Page 1 of 1

Windows API Functions

Posted: Sat Sep 06, 2003 3:52 am
by Rogue
I was recently converting a little loop speed test program from IBasic and looked for a way to get ticks. After a fair amount of searching I came accross the GetTickCount_() function. What I find troubling is that I cannot find anything in the documentation about this shortcut. Is there something that I missed? I downloaded ApiViewer 2003 which had a PureBasic syntax plugin and it shows:

Code: Select all

OpenLibrary(0,"kernel32.dll")
CallFunction(0,"GetTickCount",)
which was what I was going to use but GetTickCount_() is cleaner. Can anyone point to where it talks about this type of shortcut?

Code: Select all

x.f = 1
y.f = 1.000001 

; change to desired amount of loops 
howManyLoops = 100000000

OpenConsole()
PrintN("")
PrintN("Running Benchmark of "+Str(howManyLoops)+" loops.")

starttime = GetTickCount_() 
For i = 1 To howManyLoops
   x = x * y
Next i 
stoptime = GetTickCount_() 

totalSeconds.f = stoptime - starttime 
totalSeconds = totalSeconds / 1000 

PrintN("")
PrintN("Computer ran through "+Str(howManyLoops)+" loops in "+StrF(totalSeconds,2)+" seconds.")
PrintN(""):PrintN(""):PrintN(""):PrintN(""):PrintN(""):PrintN("Press almost any key to continue.") 
Repeat:Until Inkey()<>""
CloseConsole()

End

Posted: Sat Sep 06, 2003 4:09 am
by Karbon
Any function ending with an underscore is a WinAPI function.. Something like 600 API functions are directly available through PureBasic though I'm not sure it is documented anywhere...

Re: Windows API Functions

Posted: Sat Sep 06, 2003 7:51 am
by PB
> Can anyone point to where it talks about this type of shortcut?

It's all in the FAQ: viewtopic.php?t=4876

Specifically, look for 'Why do some commands end in an underscore' in
the FAQ, and it links off to details about using API commands. :)

Posted: Sat Sep 06, 2003 11:06 am
by GedB
API functions are built into windows.

In C/C++ these functions are made available by including Windows.h

In Visual Basic and Ibasic you have to declare the function.

In PureBasic, the functions are just available. This is because PureBasic is wonderful :)

The functions are all declared in the compilers support files.

If you take a look at Purebasic\PureLibraries\Windows you'll find Kernal32. In that file you'll see that GetTickCount is delcared.

So, the big question is, how do you find out how to use all of these functions?

The ultimate source is the Windows SDK from microsoft, as linked to by the FAQ:
http://www.mvps.org/vb/code/Win32api.zip

Personally I don't find this very useful. My personal favourite reference is AllApi.net's ApiGuide. This has lots of VB examples listed by functionality.
http://www.mentalis.org/agnet/apiguide.shtml

Converting VB API code to PB mainly involves deleting 90% of the code:)

Posted: Sat Sep 06, 2003 12:22 pm
by PB
> Converting VB API code to PB mainly involves deleting 90% of the code

It's great, isn't it? :D

Posted: Sat Sep 06, 2003 4:21 pm
by Kale
To get a description of WinAPI commands put this file:

http://www.garyw.uklinux.net/PB/WIN32.zip

into your PureBasic folder then put your cursor over a command and hit F1 :D