what to do with libs and dlls

This is a discussion on what to do with libs and dlls within the C Programming forums, part of the General Programming Boards category; Hey, i am sort of noob in this. I've been programming on C under linux for a while, but now, ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    14

    what to do with libs and dlls

    Hey, i am sort of noob in this. I've been programming on C under linux for a while, but now, i'm heading for native win32 applications. I was building my code and I noticed that i don't know how to "include" libraries(.lib) nor dll files. I only know what to do with headers. Can anyone help me? I think it is simple, but i dont get it.

    Thanks

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Exampe to include library in a windows app using MS command line compiler.
    The other command line parms just tell the compiler that we're
    creating a Windows GUI app as opposed to a console app
    cl /DWIN32 myapp.c advapi32.lib /link /subsystem:windows


    Two different approaches for loading a DLL

    First approach
    DLL using the import library (mydll.lib) that was created while
    compiling the DLL. All you have to do is include the header file
    from the creation of the dll in your app and include the import
    lib when you're linking your code as illustrated below
    cl mydllapp.c mydll.lib



    Second approach

    Loading DLL on the fly.
    cl mydllapp.c

    Code:
     int main(void)
     {
     HINSTANCE hmyDLLlib=LoadLibrary("myDLL.DLL");
       if(hmyDLLlib==NULL) 
      printf("Unable to load library!\n");
     return 0;
     }

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    14
    Thank you very much. But I have this problem. I was trying to use sleep(). I searched on the internet for some help and I included windows.h, loaded the dll the way u posted (seems to work fine ) and done that command with the /DWIN32 example.c kernel32.lib.
    But compiler says unresolved external symbol _sleep. What is this? Can someone help me?

    (what is /DWIN32 anyway?)

    Thanks.
    Last edited by RevengerPT; 11-21-2005 at 06:02 AM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    The /DWIN32 is defining a macro. In this case, it's defining the WIN32 macro to tell the compiler that we're building a 32 bit app. This macro is really not too relevant today. But it was common practice to use it a few years back when 32 bit Windows OS's were starting to emerge. Thus, it was used to distinguish between building a app for a 16 bit OS such as Windows 3.1 or the newer Windows 32 bit OSs.

    Code:
    // Compile cl sleep.c 
    
    #include <windows.h>
    
    int main(void)
    {   // Sleep for 1 second (1000 milliseconds)
    	Sleep(1000);
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-17-2008, 03:20 PM
  2. If you must port to .NET 2005, read this thread.
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-22-2007, 06:51 AM
  3. C# and C++ static library integration?
    By gotclout in forum C# Programming
    Replies: 5
    Last Post: 06-07-2006, 06:10 AM
  4. dlls and libs
    By SirKnightTG in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-19-2003, 09:09 PM
  5. DLL's and Lib's
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 06-10-2002, 10:19 PM

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