I have a third party library; I have created a compatible .lib using implib, and I have used the library successfully in countless BCB6 console applications.

I want to use this library in a VCL application but linking fails; undefined _functions (ie with leading underscore). Now when I build the Console app, provided I #include <windows.h>, everything is perfect. I discovered that if I leave out windows.h then I get the same problem as the VCL attempt. If I try to include windows.h in the VCL app as a work-around, it doesn't fix the problem.

I have looked at windows.h but it is very convoluted, I wonder if anyone can tell me what it is that it does in the Console app to fix the problem, an why it doesn't do it in the VCL app ?

*IF* I remember correctly from my coding days in C++Builder 6, function name with leading underscores were reserved for the Builder VCL system files. Using them in your functions was verboten as they could cause conflicts. You may have rename your functions.

2ffat wrote:*IF* I remember correctly from my coding days in C++Builder 6, function name with leading underscores were reserved for the Builder VCL system files. Using them in your functions was verboten as they could cause conflicts. You may have rename your functions.

You are thinking of system functions in the Delphi RTL. In a DLL, an exported function name is prefixed with an underscore if the function uses either the __stdcall calling convention, or the __cdecl calling convention without C language linkage, and if the DLL was not compiled with a .def file to export different names than the compiler's default naming conventions.

How EXACTLY are those functions defined in ipworks.h? The only possibility that comes to mind is if the functions in question are declaring their calling convention using a precompiler macro in such a way that it is dependent on something that windows.h defines, causing the code to compile using one calling convention (like __stdcall) when windows.h is included, and a different calling convention (like __cdecl) when omitted.

denville wrote:VCL app:

VCL apps always include windows.h, whether you include it in your own code or not.

If you really want to know what's going on, I suggest you invoke the IDE's preprocessor (Project Manager > right-click a .cpp file > choose "Preprocess". Or run CPP32.EXE directly) on your code so you can see exactly how preprocessor macros are being expanded, and you can see exactly what the compiler sees. I'm sure you will then notice some differences.

I can see now that the calling convention is modified depending on whether WIN32 is defined. Defining it myself in the project has the magic effect. Mind you, I couldn't see where WIN32 got defined by default in the console apps that worked.