473,327 Members | 2,081 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,327 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 3992
> 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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.