|
From: Chris W. <ch...@qw...> - 2006-12-04 22:26:50
|
Hi all, I'm sorry if this has been covered in previous posts. I'm afraid I'm still a bit lost with the issues relating to linking MinGW code with Windows DLLs. I'm trying to use the Microsoft Volume Shadow Copy Service (VSS) from MinGW, for a GPL application, without needing my users to download the VSS API (license encumbered and not GPL compatible). Therefore, I would like to add support for this service to MinGW and to my application, which already compiles with MinGW and MSVC, and retain the ability to compile with both. Most of the VSS API is COM, and is covered by MSDN, so I think I can write a freely distributable set of headers for that part using only MSDN as a source. I've never done this before, so I could use some pointers to writing COM headers for MinGW. However, my first problem is that one function from this DLL needs to be called to get the first COM interface. That function, CreateVssBackupComponents [http://msdn2.microsoft.com/en-gb/library/aa381517.aspx] appears to have been compiled by Microsoft using MSVC C++ name mangling, even though it is not an object method, just a function, and nor is it overloaded. Objdump on the VSSAPI.DLL included in Windows XP shows: /tmp/vssapi.dll: file format efi-app-ia32 /tmp/vssapi.dll architecture: i386, flags 0x0000010b: HAS_RELOC, EXEC_P, HAS_DEBUG, D_PAGED [...] Ordinal/Name Pointer] Table [...] [ 11] ?CreateVssBackupComponents@@YGJPAPAVIVssBackupComponents@@@Z It looks like it will be very tricky to link directly to this function from MinGW. I tried to use the following definition: HRESULT __stdcall CreateVssBackupComponents(IVssBackupComponents** ppBackup) __attribute__ ((alias ("CreateVssBackupComponents@@YGJPAPAVIVssBackupComponents@@@Z"))); However, it misses the initial question mark (?), since g++ complains about invalid junk in the assembler if I include it, and g++ still complains about a missing symbol at link time, having added a prefix underscore to the symbol name, even if I use the -fno-leading-underscore option to g++. I know that name mangling is only one issue related to calling C++ methods from one compiler in another, but this is not a method, just a function compiled by Microsoft without extern "C", so I assume that the other problems don't apply here? I'm pretty much at a loss how to call this function from MinGW. The only way I can think of is to write a small wrapper library that I compile with MSVC, that re-exports this function using extern "C" under a different name, and link my MinGW code with this wrapper library. However, this is really ugly because it means I have to call the function with a different name when using MinGW, and use #define magic to achieve compilation with both MinGW and MSVC. Can anyone see another option? I have read the MinGWiki pages: * http://www.mingw.org/MinGWiki/index.php/MSVC-MinGW-DLL * http://www.mingw.org/MinGWiki/index.php/MixObjects However, I'm still lost, since the examples seem tuned towards building DLLs with MinGW that can be linked to MSVC applications, and what I want to do is the reverse. I tried to use dlltool to re-export the symbols from the DLL in an import library, but 'dlltool --export-all-symbols' on the DLL tells me that no symbols were found, and creates an import library with no useful symbols. I haven't tried pexports yet, and I don't know if it can help. Can anyone offer me any advice? Thanks in advance for your help. Cheers, Chris. -- _ ___ __ _ / __/ / ,__(_)_ | Chris Wilson <0000 at qwirx.com> - Cambs UK | / (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer | \ _/_/_/_//_/___/ | We are GNU-free your mind-and your software | |