Click to See Complete Forum and Search --> : Using VC6 lib in Borland C++ Builder 6
lechoo
September 20th, 2005, 05:44 AM
Hi everyone,
I have following problem: I need to access maxnet.dll using BCB6. There's also lib for this dll. So what I do is convert it (lib file) using coss2omf. Then I add this new lib to project but linker throws "unresolved external" error on function I want to call.
Then I tried method described here: http://www.digitalmars.com/ctg/coff2omf.html
Still nothing. So I tried creating lib from dll using borland's implib. And still no luck.
Now I'm quite out of ideas. What else can I do?
regards
Paul McKenzie
September 20th, 2005, 05:53 AM
Hi everyone,
I have following problem: I need to access maxnet.dll using BCB6. There's also lib for this dll. So what I do is convert it (lib file) using coss2omf.Wrong.
Use the Borland program IMPLIB.EXE to create a Borland compatible import library for maxnet.dll. That is exactly what that program is there for -- to generate Borland import library files from existing DLL's.
Regards,
Paul McKenzie
Paul McKenzie
September 20th, 2005, 05:57 AM
Just to complete my answer,
You don't even need an import library. If you use LoadLibrary() and GetProcAddress(), you need no import library. An import library is only needed for ease of use for the C or C++ programmer and linker.
In no means is it necessary, as the way to universally use a DLL is to call LoadLibrary() and GetProcAddress() to get the pointer to the DLL's exported functions. As a matter of fact, it may be easier to do LoadLibrary() and GetProcAddress() if you only want to call a few functions from the DLL, and you find out you're wasting a lot of time trying to get import libraries to work properly.
Regards,
Paul McKenzie
Skoons
September 20th, 2005, 04:36 PM
Try to use same dll files. Or download new COFF2OMf utility. It`s strange that you have such problems, I never met them but have used this utility very often (I have converted DX9 SDK from VC to Borland C++)
Paul McKenzie
September 20th, 2005, 06:50 PM
Or download new COFF2OMf utility. No need for that. If you have a DLL and just want to use it, regardless of what programming language created the DLL, either create an import library using IMPLIB.EXE from the DLL and add it to your Borland project, or at runtime call LoadLibrary() and GetProcAddress().
Regards,
Paul McKenzie
Paul McKenzie
September 20th, 2005, 06:54 PM
So I tried creating lib from dll using borland's implib. And still no luck.What do you mean by "no luck"? Every DLL that I've used has had no problems when IMPLIB.EXE is used to create the import library.
You must be doing something wrong, giving the wrong command-line parameters, or something else.
Regards,
Paul McKenzie
lechoo
September 21st, 2005, 06:08 AM
What do you mean by "no luck"? Every DLL that I've used has had no problems when IMPLIB.EXE is used to create the import library.
Thanks for Your help. By no luck I mean I'm still getting unresolved external error.
You must be doing something wrong, giving the wrong command-line parameters, or something else.
Possible. I'll try again from begining.
regards
Paul McKenzie
September 21st, 2005, 06:22 AM
You could be getting an unresolved external error that has nothing to do with the import library you created. Import libraries work correctly, so it is something you are doing wrong.
1) Exactly what are the errors? I would like to see the error messages.
2) Please check using Dependency Walker or some other tool *exactly* what the exported function names are from the DLL. Maybe you are getting the names wrong, thereby calling functions that just do not exist.
3) Where is the header file that defines the DLL functions? You are using one, right? If so, are the functions "extern "C"? If you don't know what this is, then I can see why you're having a problem. If the functions in the DLL are "straight" function names, i.e. no name-mangling, then your functions must be declared as "extern "C".
It would do you better if you just post (or attach) the header file that declares the DLL functions and I will see if it is correct, given what the DLL has exported. You will have to give me the list of exported names, since I believe that maxnet.dll can't be distributed to anybody (since I believe it is an AutoDesk DLL).
But again, you can bypass all of this and just use LoadLibrary() and GetProcAddress(). However, there is no reason why you shouldn't be able to get this to work with import libraries.
Regards,
Paul McKenzie
lechoo
September 22nd, 2005, 02:41 AM
1) Exactly what are the errors? I would like to see the error messages.
There's only one
[Linker Error] Unresolved external 'CreateManager()' referenced from C:\TEMP\BACKBURNERCOMM\UNIT1.OBJ
This is function I'm calling (obtained with dumpbin maxnet.dll /exports)
46 2D 00001020 ?CreateManager@@YAPAVMaxNetManager@@XZ
And here's part of maxnet.h
#ifdef WIN32
#ifndef MAXNETEXPORT
#define MAXNETEXPORT __declspec( dllimport )
#endif
#else
#define MAXNETEXPORT
#endif
//some structures......
//-----------------------------------------------------------------------------
//-- Interface
MAXNETEXPORT MaxNetManager* CreateManager ( );
MAXNETEXPORT void DestroyManager (MaxNetManager* mgr);
//-- Initializes a "Job" structure
MAXNETEXPORT bool jobReadMAXProperties (char* max_filename, Job* job, CJobText& jobText);
//-- Reads Render Data from a *.max file and fills in a Job structure
MAXNETEXPORT void jobSetJobDefaults (Job* job);
//-- Utilities
MAXNETEXPORT void NumberedFilename (TCHAR* infile, TCHAR* outfile, int number);
MAXNETEXPORT bool IsMacNull (BYTE *addr);
MAXNETEXPORT bool GetMacAddress (BYTE* addr);
//more functions......
This is how I call CreateManager
MaxNetManager* manager = CreateManager();
This is how I use implib
implib -c maxnet maxnet.dll
regards
Adam
Paul McKenzie
September 29th, 2005, 04:21 PM
CreateManager@@YAPAVMaxNetManager@@XZ
That is the function you're calling, but guess what? You never called it. You called "CreateManager", not "CreateManager@@YAPAVMaxNetManager@@XZ". Yes, that *is* the function name.
The problem is that the library uses a mangled C++ name. The library was meant solely for VC 6 usage. If it were meant for general usage, the name would not be mangled (for example, do a dumpbin on one of the Windows system DLL's. You will see that the exported name is not mangled, making the DLL usable for all languages and compilers).
Borland C++ uses different name-mangling algorithm, so when you compile your program, "CreateManager" for Borland C++ will be "CreateManager@u7onsfodsn" or something different.
Therefore, you better get a true Borland version of the library, since the one you're using assumes that you're using Visual C++, or get a version of the library that exports its function names as 'C', non-mangled names.
Regards,
Paul McKenzie
lechoo
September 30th, 2005, 12:36 AM
Thanks for Your help. Right now I'm using LoadLibrary() and GetProcAddress() which works nicely.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.