473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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


Jul 21 '05 #1
3 3995
> 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
Jul 21 '05 #2
C cant use MFC, C++ can however, how did you pull that one off :D

"Michael Howes" <mh****@xblueiguana.com> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #3
"Michael Howes" <mh****@xblueiguana.com> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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


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
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
5
by: dvtaylor | last post by:
We write everything in plain old C. We have a potential customer that wants to provide us a DLL written in C#. How can we call it's functions?
3
by: Ben Terry | last post by:
I have imported a legacy C++ project into a VisualStudio.NET 2003 solution. I have some new C# projects in the solution as well. I am using the managed extensions in my C++ project so that I can...
11
by: minishilpi | last post by:
I have a question - I have this code below to send an email and I have referenced the Microsoft CDO Library 2000. It doesn't throw any exception in the console window. It goes throughout the code...
2
by: bemytthm | last post by:
I just want to ask abt communicate with AD using ASP.net. I would want to ask you all to help me correct a problem like this: This is a code i use to change password on AD public bool...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.