Results 1 to 5 of 5

Thread: DLL question

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    DLL question

    When I make a DLL, I include the .h file with all the function prototypes and stuff, and link with the .lib file. How can I use the DLL without having to link with the .lib file?

  2. #2
    jim mcnamara
    Guest
    A .lib file is a library of routines that the linker picks & chooses from. It drags them, whole, into your dll. If you link statically.

    Otherwise, the .lib file 'knows' whether the routine is external (like in kernel32.dll) or lives only in the .lib file. If it is external, the 'kernel32' dll reference is used. Not the actual code. If it's internal, the code gets copied into your .dll file. Whole.

    Either way, your code will run. The only time you have the dll reference problem is if YOU, in your dll code, reference another external dll that is not found on other PC's. The external reference will be put into your code by the linker. But at runtime, the dll will fail. Or: if the .lib file references an wacko external dll, then you have the same problem. Most of the time this is not an issue. 99% of the time, I'd say.

    SO: the only problem you will likely encounter is that you have to drag along the other, external dll you decided to use.

    However.

    For COM, all bets are off. We now enter IID's, CLSID's, and a new world of hurt with ActiveX dll's. Suffice it to say, it doesn't work the same.

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    What? I was talking about getting the handle to the function, pointer to it, etc.

  4. #4
    jim mcnamara
    Guest
    I'm sorry - you used the word link - which I took to mean a link edit -- what you do when you create a runtime module or dll from object code.

    There is no handle or pointer to a dll entry-point, per se. It gets defined when you create your program and run it. This is assuming I didn't get the wrong meaning, again. Your code maintains a reference (kind of a pointer or handle ).

    You can use function pointers to refer to a dll entry point, or any other function's entry point.

    You define a function pointer like this:
    Code:
    int (* p)();  
    
    (*p)() = myfunction;
    ......
    int myfunction(void){
    
    }
    p now points to the function entry point for myfunction.

    Eventually, I may accidentally provide what you want....

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Uh, I think this still isn't it.
    You mean, if you want to use the DLL in your app, you include the header and link to the lib. And you want to know how to go without using the lib. Did I get this right?
    You need the API functions LoadLibrary, FreeLibrary and GetProcAddress.
    This may be not exact, I don't have a referance at hand:
    HMODULE LoadLibrary(LPCTSTR szFileName);
    loads a dll, name is provided in szFileName, returns handle

    void* GetProcAddress(HMODULE hLib, LPCTSTR szFunctionName);
    gets the address of the function szFunctionName in the dll hLib.

    void FreeLibrary(HMODULE hLib);
    Free resources used by the library.

    All of this is very complicated and messy. If you have an import library, use it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width