Search code examples
cdllborland-c++

Link DLL in Borland C++ compiler


I use freecommandlinetools compiler bcc32. I need to use third party dll in my program. I'd prefer not to call LoadLibrary and GetProcAddress, but rather to link the dll in my program to call the dll functions directly.

#include "somelibrary.h"

int main() {
  somefunction(); // defined in somelibrary.dll
}

I see unresolved externals in attempt to compile. How to convince the linker to link with the somelibrary.dll?


Solution

  • You must create a .lib in order to link the dll directly. Supposing your dll is user32.dll :

    implib -a -c -f user32.lib user32.dll
    

    Will create user32.lib with all the symbols of user32.dll. Then link your project with user32.lib instead of user32.dll.

    You can use the impdef.exe command to see the symbols exported by the dll. If these symbols already start with an underscore '_', you can omit the -a in the implib command.