Groups | Blog | Home
all groups > visual c libraries > december 2003 >

visual c libraries : Using MFC in a Managed C++ DLL?? Can I?


Michael Howes
12/11/2003 2:49:09 PM
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



Michael Howes
12/12/2003 10:09:12 AM
[quoted text, click to view]

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

discussion NO[at]SPAM discussion.microsoft.com
12/12/2003 7:53:49 PM
C cant use MFC, C++ can however, how did you pull that one off :D



[quoted text, click to view]

Dilton McGowan II
12/13/2003 12:40:04 AM
[quoted text, click to view]

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

AddThis Social Bookmark Button