Help calling Win32 API's

This is a discussion on Help calling Win32 API's within the Windows Programming forums, part of the Platform Specific Boards category; how do we call a windows function in c? lets say the "Sleep" function, which is a Kernel function. am ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    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.

  2. #2
    Registered User ExDigit's Avatar
    Join Date
    Jan 2002
    Posts
    31

    Smile

    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!

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    5
    thank you so much!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 02:12 AM
  2. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  4. Those darn API's
    By Zahl in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-04-2003, 09:27 AM
  5. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21