wrap native C++ DLL used Boost libs, into .NET

Hello! I need to use a DLL used Boost, in .NET projects. I wrapped this lib, but I cannot use the wrapping, because System.BadImageFormatException (is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)) raises at once, if I executing an application using the wrap. Wrap scheme: Native DLL --- .NET Class Library --- .NET Project. I'm wrapping every class in native DLL into .NET class. I using some principles from the "Expert C++/CLI: .NET for Visual C++ Programmers" by Marcus Heege. When I wrote a small test project, I discovered that if I only include anyone Boost header into native DLL, it set the System.BadImageFormatException permanently. Without Boost wrapping works perfectly. I use: Boost 1.35.0 Visual Stidio 2005 SP1, 2008 - same results in all cases. Windows XP SP2 x86. I found same problems in Internet - impossible to wrap native DLLs, used Boost. All this problems were unsolved. Such as: http://objectmix.com/dotnet/121318-not-valid-win32-application-exception-hre... -- Best regards, Ilya Chumakov mailto:aidforsoft@mail.ru

On Fri, 05 Sep 2008 08:47:08 +0200,
[...]I found same problems in Internet - impossible to wrap native DLLs, used Boost. All this problems were unsolved. Such as: http://objectmix.com/dotnet/121318-not-valid-win32-application-exception-hre...
as it turns out you are referring to a thread which I had started. Looking
at that thread I think I solved the problem by moving #include

Hi Boris.
[...]I found same problems in Internet - impossible to wrap native DLLs, used Boost. All this problems were unsolved. Such as: http://objectmix.com/dotnet/121318-not-valid-win32-application-exception-hre...
as it turns out you are referring to a thread which I had started. Looking at that thread I think I solved the problem by moving #include
from a header file to a .cpp file (so the C++/CLI project which includes the header files of my native C++ project doesn't include this Boost header anymore). At least I can and do ship a .NET library built on top of a C++ DLL which uses Boost 1.34.1. I'm not sure if your problem is similar to mine but I could fix mine.
Thanks. In my case, all Boost headers has located inside .cpp files only. So the C++/CLI DLL doesn't include Boost headers, but I cann't solve the problem of System.BadImageFormatException. -- Best regards, Ilya Chumakov mailto:aidforsoft@mail.ru

On Mon, Sep 8, 2008 at 12:13 AM,
Hi Boris.
[...]I found same problems in Internet - impossible to wrap native DLLs, used Boost. All this problems were unsolved. Such as: http://objectmix.com/dotnet/121318-not-valid-win32-application-exception-hre...
as it turns out you are referring to a thread which I had started. Looking at that thread I think I solved the problem by moving #include
from a header file to a .cpp file (so the C++/CLI project which includes the header files of my native C++ project doesn't include this Boost header anymore). At least I can and do ship a .NET library built on top of a C++ DLL which uses Boost 1.34.1. I'm not sure if your problem is similar to mine but I could fix mine. Thanks. In my case, all Boost headers has located inside .cpp files only. So the C++/CLI DLL doesn't include Boost headers, but I cann't solve the problem of System.BadImageFormatException.
This sounds like the error you get when trying to use a native 32-bit DLL in a 64-bit (or vice-versa) .NET process. -- Cory Nelson

This sounds like the error you get when trying to use a native 32-bit DLL in a 64-bit (or vice-versa) .NET process.
Thanks, I have thought about this. I use WinXP x86 and /MACHINE:X86 in my Visual Studio projects. In addtition, this assumption fails to explain the fact that working of the DLL depend on the using of the Boost headers. -- Best regards, Ilya Chumakov mailto:aidforsoft@mail.ru

boost-users-bounces@lists.boost.org, le 10 septembre 2008 02:01:
This sounds like the error you get when trying to use a native 32-bit DLL in a 64-bit (or vice-versa) .NET process.
Thanks, I have thought about this. I use WinXP x86 and /MACHINE:X86 in my Visual Studio projects. In addtition, this assumption fails to explain the fact that working of the DLL depend on the using of the Boost headers.
I vaguely remember about problems wrapping native DLLs when the wrapped DLL has dependencies on other DLLs. Boost libraries that are not header-only (like, IIRC, Boost.Thread) use the autolinking pragma "#pragma comment(lib, xxxx)" in their headers to automatically have the linker link their DLLs to client programs #include-ing their headers. (I missed the beginning of this discussion, so sorry if I'm off-topic or if I repeat already rejected hypotheses.) Éric Malenfant --------------------------------------------- The power of accurate observation is commonly called cynicism by those who have not got it. - George Bernard Shaw

2008/9/10
This sounds like the error you get when trying to use a native 32-bit DLL in a 64-bit (or vice-versa) .NET process.
Thanks, I have thought about this. I use WinXP x86 and /MACHINE:X86 in my Visual Studio projects. In addtition, this assumption fails to explain the fact that working of the DLL depend on the using of the Boost headers.
-- Best regards, Ilya Chumakov mailto:aidforsoft@mail.ru
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I'm using following solution: __dllimport on function, i want to use into .NET application. Than declare static method of class in .NET with atribute "dllimport(dllname,methodname)" (exact syntax lookup in documentation (such as msdn)). I have some troubles with marshaling of string from .net application to C++. .NET has very strange behaviour with marshaling strings - as i undestood, NET converts string to ASCII-string, if string doesn't have any symbol with ASCII-code greater than 127, and to unicode strings in other case. There are two solutions: To write COM, COM+, or DCOM component, and use interopt techniques on .NET. In this case .NET generates interopt's object and .NET class for COM component opaque. This means, your task looks like that: Write dll / COM, than using it as described bellow. Sorry for my english.

aidforsoft@mail.ru wrote:
Hello!
I need to use a DLL used Boost, in .NET projects. I wrapped this lib, but I cannot use the wrapping, because System.BadImageFormatException (is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)) raises at once, if I executing an application using the wrap.
Wrap scheme: Native DLL --- .NET Class Library --- .NET Project. I'm wrapping every class in native DLL into .NET class. I using some principles from the "Expert C++/CLI: .NET for Visual C++ Programmers" by Marcus Heege.
When I wrote a small test project, I discovered that if I only include anyone Boost header into native DLL, it set the System.BadImageFormatException permanently. Without Boost wrapping works perfectly.
I use: Boost 1.35.0 Visual Stidio 2005 SP1, 2008 - same results in all cases. Windows XP SP2 x86.
I found same problems in Internet - impossible to wrap native DLLs, used Boost. All this problems were unsolved. Such as: http://objectmix.com/dotnet/121318-not-valid-win32-application-exception-hre...
Just a thought: this may be related to a known issue with Visual Studio 2005 SP1: http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/73cb0f98-d15... https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedba... There are two suggested workarounds: https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?Feedback... David

Just a thought: this may be related to a known issue with Visual Studio 2005 SP1: http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/73cb0f98-d15... https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedba...
There are two suggested workarounds: https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?Feedback...
It's working! Workaround #define BOOST_THREAD_USE_DLL is working! My test project with using Boost is working! I will test a big DLL later. BIG THANKS, David! -- Best regards, Ilya Chumakov
participants (7)
-
aidforsoft@mail.ru
-
Boris
-
Cory Nelson
-
David Walthall
-
Eric MALENFANT
-
Ilya Chumakov
-
Олег Царев