User forums > General (but related to Code::Blocks)

CB dll project -> used in an M$ Visual project : troubles

(1/3) > >>

killerbot:
Hello all,
I am in big trouble. I have created a dll project with CB. This created a main.c, I changed that into a main.cpp, since I will need some classes also. The exported function thoug are extern C, so no name mangling. I wrote a litlle test project (console app from CB), which uses the dll (loaded thourh LoadLibrary, and then GetProcAddress) --> all woks well.
But when a project from M$ Developer Studio (mfc app and regular code, that regular uses the dll), thinsk go wrong. The exported functions seem to work well. One of those exported functions is a factory function which return a pointer to an class object created on the heap in the dll. When invoking member methods on that pointer, things go wrong. Crash !! I tried several methods (some with arguments, others without, I had one with no arguments -> error box is complaining about priviliged instruction).

What surprises me is that antoher mingw project can use the dll, while an M$ project can't.

Help help help help .....
Lieven

anarxia:
You can't mix n' match C++ code compiled with different compilers, period. Name mangling is the least of your problems.
Use C if you want to support multiple compilers with the same DLL.

killerbot:
is it really that bad ??
If I get a third party dll for example, I don't know how it was build, nor if it's c or c++. So no guarantee on usability.
 :shock: :shock: :shock: Is it really that bad ?

AkiraDev:

--- Quote from: killerbot on February 09, 2006, 05:20:51 pm ---is it really that bad ??
If I get a third party dll for example, I don't know how it was build, nor if it's c or c++. So no guarantee on usability.
 :shock: :shock: :shock: Is it really that bad ?

--- End quote ---

While it's true that DLL's are really not compatible, you can still find a way to link MinGW DLLs to Microsoft compiled binaries. Have a look at MinGW.org, there are tools (like reimp) that allow you to this, and they explain how to do it.

Michael:

--- Quote from: AkiraDev on February 09, 2006, 05:26:10 pm ---While it's true that DLL's are really not compatible, you can still find a way to link MinGW DLLs to Microsoft compiled binaries. Have a look at MinGW.org, there are tools (like reimp) that allow you to this, and they explain how to do it.

--- End quote ---

Well, things are not so simple. DLL are not so compiler compatible, but there is also the problem of the imported library. Let me cite from libxml2 readme:


--- Quote ---If you configure libxml2 to include iconv support, you will obviously need to obtain the iconv library and include files. To get them, just follow the links at http://www.gnu.org/software/libiconv/ - there are pre-compiled Win32 versions available, but note that these where built with MSVC. Hence the supplied import library is in COFF format rather than OMF format. You can convert this library by using Borland's COFF2OMF utility, or use IMPLIB to build a new import library from the DLL. Alternatively, it is possible to obtain the iconv source, and build the DLL using the Borland compiler.

--- End quote ---

In my specific case, I could compile libxml2, but not link it, because of libiconv. As I had the libs and the dll from compiled for windows (MSVC), I have tried as suggested above. Before with COFF2OMF, then with IMPLIB and finally with reimp. Well, nothing to do. May be I am doing something wrong, that's possible, but after 4 hours of trying and testing.... :roll:
 
May be the dll alone will work, but as I have to develop, I need an import library that would work with MinGW... :(

Michael

Navigation

[0] Message Index

[#] Next page

Go to full version