Managed C++ Mixed Assembly

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.
 
V

Vadym Stetsyak

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
 
O

Olivier Matrot

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.
 
V

Vadym Stetsyak

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.

 
O

Olivier MATROT

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.

 
G

Gary Chang[MSFT]

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.
 
O

Olivier Matrot

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.
 
O

Olivier Matrot

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.
 
O

Olivier Matrot

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top