-
Help calling Win32 API's
how do we call a windows function in c?
lets say the "Sleep" function, which is a Kernel function. am i right in thinking this function is in kernel32.dll?
anyway, in VB this is very easy. we put the name and/or path to the dll containing our function and as long as we call the function by its proper name and pass it proper arguments, all is well. i have no clue how to do this in c. do i need the "#import" tag?
it would be very appreciated if someone could provide a very small example.
-
Well, all you really need to do is include <windows.h>. You say that you're using the "Sleep" function? According to my Win32 API reference (you should download one - it's great.. visit http://www.winprog.org/resources.html):
"The Sleep function suspends the execution of the current thread for a specified interval.
VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);
Parameters
dwMilliseconds
Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay.
Return Values
This function does not return a value. "
Looking at this reference, we see that the Sleep command requires a double word. However, we can just pass a number straight to it.. Putting this to the test:
#include <windows.h>
int main()
{
Sleep(500);
return 0;
}
As you probably guessed, this waits 500 milliseconds and ends.
Hope this helps! :)
-