I am trying to use a C++Builder 11.1.5 created DLL in MSVC 2022 C++ project. Both are 32bit. I can't build the DLL in MSVC as it uses some VCL objects.
My C++ Builder defines the external function thus:
extern "C" __declspec(dllexport) void __stdcall SetEnabled(bool val) {
...
}
MSVC uses a header to reference the function:
extern "C" __declspec(dllimport) void __stdcall SetEnabled(bool val) ;
I have created a .DEF
file with the same name as the DLL, containing this:
LIBRARY MYTESTDLL
EXPORTS
SetEnabled
And I have generated a .LIB
file from this .DEF
file using MS lib.exe
:
lib.exe /DEF:MYTESTDLL.def /out:MYTESTDLL.lib /MACHINE:x86
Finally, I have added MYTESTDLL.lib
to my MSVC project in the Linker->Additional Dependencies
section.
But, when I build the program, I get this error:
Error LNK2019 unresolved external symbol __imp__SetEnabled@4 referenced in function _WinMain@16
I've tried adding the ordinal (@4
) to my .DEF
file and rebuilding the .LIB
file, but I still get the same error.
In a hex editor, I can that __imp__SetEnabled
is in the .LIB
file, but clearly not in a way that MSVC likes.
Have I missed a step somewhere? Is there anything obviously wrong with what I've done?