Using MFC in a Managed C++ DLL?? Can I?

M

Michael Howes

I have some old C code that uses MFC and some C Run Time Library.
I need to be able to call this from C#

I thought i'd be able to create a Managed C++ DLL, tell the project it was
using MFC, include the .c file and be on my way.

Can I use MFC in a Managed C++ DLL?

If I build a Visual C++ Class Library (.Net) and tell it to use MFC in a
Shared DLL I immediately get the following warning
nochkclr.obj : warning LNK4099: PDB 'libc.pdb' was not found with
'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or
at 'C:\BlueIguana\SymbolPDTSolution\Debug\libc.pdb'; linking object as if no
debug info

This is before I've typed any code.

linking with old run time library things because of the use of things like
strupr in the C code?

I was hoping I'd build a simple C++ class (2 methods), that would call into
this C code and that these methods would be available to my C# code

here is what I need to do
I have three files.....a LARGE .C file and a good sized .CPP/.h file. I
don't have time to port these 1000s of lines of code.
These files are actually being called from an C++/MFC application (which I
can build and run) but I don't need ANY of the UI that is calling this C
code
It's sort of strange how this project is set up, but in this MFC app, there
is a CPP file with two lines in it, and include of stdafx.h and a include of
the above mentioned .C file.

I need to call this C code form C#. The C code uses both MFC and run time
library calls.
Can I do this with a Managed C++ DLL?

thanks
mike
 
M

Michael Howes

I have some old C code that uses MFC and some C Run Time Library.
I need to be able to call this from C#

I thought i'd be able to create a Managed C++ DLL, tell the project it was
using MFC, include the .c file and be on my way.

Can I use MFC in a Managed C++ DLL?

If I build a Visual C++ Class Library (.Net) and tell it to use MFC in a
Shared DLL I immediately get the following warning
nochkclr.obj : warning LNK4099: PDB 'libc.pdb' was not found with
'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\nochkclr.obj' or
at 'C:\BlueIguana\SymbolPDTSolution\Debug\libc.pdb'; linking object as if no
debug info

I forgot to mention one other set of warnings I get...
I get a ton of warnings (well 17) on most of the mfc and atl libs

msvcrtd.lib(secchk.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

atlsd.lib(Externs.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

I tried to dig through the MSDN articles on this and really had a hard time
making sense of it.

Am I missing some build settings to be able to link MFC into a Managed C++
DLL??

thanks

mike
 
D

Dilton McGowan II

Michael Howes said:
2003\Vc7\lib\nochkclr.obj' if

I forgot to mention one other set of warnings I get...
I get a ton of warnings (well 17) on most of the mfc and atl libs

msvcrtd.lib(secchk.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

atlsd.lib(Externs.obj) : warning LNK4210: .CRT section exists; there may be
unhandled static initializers or terminators

I tried to dig through the MSDN articles on this and really had a hard time
making sense of it.

Am I missing some build settings to be able to link MFC into a Managed C++
DLL??

thanks

mike

Hello Michael,

The help gives a step-by-step resolve to convert the project to Mixed mode
which should solve the static runtime nature of the issues.

An alternative technique that I've employed successfully in the past is to
make an abstraction layer Managed C++ DLL. This achieves a clean interface
to .NET users of the DLL and from that DLL you can conveniently load and use
standard C/C++ DLLs which should include MFC, though mine was C++ with no
MFC.

Dilton
 

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