Managed C++ Mixed Assembly

  • Thread starter Thread starter Olivier Matrot
  • Start date Start date
O

Olivier Matrot

Hello,

I have a VC++ Project that outputs an unmanaged DLL.

I would like to convert this project to a managed C++ Project.
The goal is to mix unmanaged and managed code. Un unmanaged exported
function will need to run managed code. Is it possible ?
TIA.
 
Hello, Olivier!

Yes, it is possible.
To compile with managed code use /clr compiler parameter.

And here's code sample
( http://www.winterdom.com/mcppfaq/archives/000370.html )

OM> I have a VC++ Project that outputs an unmanaged DLL.

OM> I would like to convert this project to a managed C++ Project.
OM> The goal is to mix unmanaged and managed code. Un unmanaged exported
OM> function will need to run managed code. Is it possible ?
OM> TIA.



--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Ok, this is not necessary with VS2005...
I have now a mixed DLL. But when I load it with LoadLibrary from unmanaged
code I have the following Error:
193 : %1 is not a valid Win32 application.
Ouch !

Olivier Matrot said:
Thanks for that.
Should I follow the following ? http://support.microsoft.com/?id=814472
I may be wrong but the sample you provider is not what I'm looking for.
 
Hello, Olivier!

Hmm, strange. Do you have DllMain function in your dll?
Is it called?

You wrote on Fri, 24 Nov 2006 18:46:53 +0100:

OM> Ok, this is not necessary with VS2005...
OM> I have now a mixed DLL. But when I load it with LoadLibrary from
OM> unmanaged
OM> code I have the following Error:
OM> 193 : %1 is not a valid Win32 application.
OM> Ouch !

OM> "Olivier Matrot said:
Thanks for that.
Should I follow the following ?
http://support.microsoft.com/?id=814472
I may be wrong but the sample you provider is not what I'm looking
for.

 
This a a visual studio 2003 upgraded MFC DLL.
I've only added a managed C++ class to the project...

Vadym Stetsyak said:
Hello, Olivier!

Hmm, strange. Do you have DllMain function in your dll?
Is it called?

You wrote on Fri, 24 Nov 2006 18:46:53 +0100:

OM> Ok, this is not necessary with VS2005...
OM> I have now a mixed DLL. But when I load it with LoadLibrary from
OM> unmanaged
OM> code I have the following Error:
OM> 193 : %1 is not a valid Win32 application.
OM> Ouch !

OM> "Olivier Matrot said:
Thanks for that.
Should I follow the following ?
http://support.microsoft.com/?id=814472
I may be wrong but the sample you provider is not what I'm looking
for.
Hello, Olivier!
Yes, it is possible.
To compile with managed code use /clr compiler parameter.
And here's code sample
( http://www.winterdom.com/mcppfaq/archives/000370.html )
OM> I have a VC++ Project that outputs an unmanaged DLL.
OM> I would like to convert this project to a managed C++ Project.
OM> The goal is to mix unmanaged and managed code. Un unmanaged
exported
OM> function will need to run managed code. Is it possible ?
OM> TIA.

 
Hi Olivier,
This a a visual studio 2003 upgraded MFC DLL.
I've only added a managed C++ class to the project...

Based on the error message: 193 : %1 is not a valid Win32 application.

The problem seems to be your mixed DLL is not a valid Win32 image. Is it
possible that the DLL is built by any 64-bit version's library?

If you just upgrade that MFC DLL to VS2005, is there any problem to load it?

By the way, the KB article you mention does not target on your case, it
discuss the scenario that the original DLL is a pure .NET assembly.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
There is no problem to load the DLL, if there is no CLR module module in the
project.
As soon as I add a Managed C++ Class, the DLL does not load anymore.

"Gary Chang[MSFT]" said:
Hi Olivier,
This a a visual studio 2003 upgraded MFC DLL.
I've only added a managed C++ class to the project...

Based on the error message: 193 : %1 is not a valid Win32 application.

The problem seems to be your mixed DLL is not a valid Win32 image. Is it
possible that the DLL is built by any 64-bit version's library?

If you just upgrade that MFC DLL to VS2005, is there any problem to load
it?

By the way, the KB article you mention does not target on your case, it
discuss the scenario that the original DLL is a pure .NET assembly.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
My fault.
I started from scratch with this project. Now the DLL is successfully
loaded.
My problem now is to call a static managed function from unmanaged code (an
unmanaged exported C style function).

Olivier Matrot said:
There is no problem to load the DLL, if there is no CLR module module in
the project.
As soon as I add a Managed C++ Class, the DLL does not load anymore.

"Gary Chang[MSFT]" said:
Hi Olivier,
This a a visual studio 2003 upgraded MFC DLL.
I've only added a managed C++ class to the project...

Based on the error message: 193 : %1 is not a valid Win32 application.

The problem seems to be your mixed DLL is not a valid Win32 image. Is it
possible that the DLL is built by any 64-bit version's library?

If you just upgrade that MFC DLL to VS2005, is there any problem to load
it?

By the way, the KB article you mention does not target on your case, it
discuss the scenario that the original DLL is a pure .NET assembly.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
Nothing special to do for calling managed code from unmanaged code.
Thanks for that.

Olivier Matrot said:
My fault.
I started from scratch with this project. Now the DLL is successfully
loaded.
My problem now is to call a static managed function from unmanaged code
(an unmanaged exported C style function).

Olivier Matrot said:
There is no problem to load the DLL, if there is no CLR module module in
the project.
As soon as I add a Managed C++ Class, the DLL does not load anymore.

"Gary Chang[MSFT]" said:
Hi Olivier,

This a a visual studio 2003 upgraded MFC DLL.
I've only added a managed C++ class to the project...

Based on the error message: 193 : %1 is not a valid Win32 application.

The problem seems to be your mixed DLL is not a valid Win32 image. Is it
possible that the DLL is built by any 64-bit version's library?

If you just upgrade that MFC DLL to VS2005, is there any problem to load
it?

By the way, the KB article you mention does not target on your case, it
discuss the scenario that the original DLL is a pure .NET assembly.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
Back
Top