Re: convert an MFC application to MFC DLL
- From: "Giovanni Dicanio" <giovanniDOTdicanio@xxxxxxxxxxxxxxxxx>
- Date: Fri, 29 May 2009 11:37:47 +0200
"Tom Gonuts" <funkygonuts@xxxxxxxxx> ha scritto nel messaggio news:ecc08760-e11c-487c-9e88-
I wanted to compile the old C codes in C++/CLI. However, lnk 2020
errors popped up all over places. Mostly these errors complained about
the extern variables. I had tried a numerous ways followed MSDN and
other sources without success. It is quite possible that I am still
not doing things right. I suspect that some settings with visual
studio are need to be done but I can't be sure since I am a newcomer.
If I changed the old C-codes a little bit (change definitions and
declaration), it compiled but as I stated before I am not allowed to
changed the old C-codes.
I tried building a simple C++/CLI test project using VS2008, and I inserted a pure C source file (with .c extension, called 'PureCCode.c'), defining global variables, etc.
When I tried to build the project, I got the following error on VS2008:
Command line error D8045 : cannot compile C file '.\PureCCode.c' with the /clr option
And MSDN documentation is explicit about that:
http://msdn.microsoft.com/en-us/library/abb82cy0(VS.85).aspx
<cite>
Only C++ source code files can be passed to a compilation that uses /clr.
</cite>
You may have the option to compile the original C code as C++, but I'm not sure this is a good choice.
I mean: there are some differences between C++ and C, and you may have some errors or bugs.
If you really can't change your original C code, to convert it to C++ code, I would suggest to expose your original C code as a *pure C interface* DLL.
You may want to add some functions to be exported by this DLL, to get/set your existing global variables. In this way, you don't need to change your original C code (because you are building a native Win32 DLL that exports a C interface, and you can compile pure C code to build a pure Win32 DLL). You just need to add and export getter/setter functions to access your global variables from outside the DLL.
Once you have this pure-C interface DLL, you can wrap it using C++/CLI. You can develop one or more C++/CLI classes that expose methods that call the pure-C interface DLL. And you can call this C++/CLI bridging layer directly from C# (or other .NET languages, like VB.NET, or F#...).
HTH,
Giovanni
.
- Follow-Ups:
- Re: convert an MFC application to MFC DLL
- From: Giovanni Dicanio
- Re: convert an MFC application to MFC DLL
- References:
- convert an MFC application to MFC DLL
- From: Tom Gonuts
- Re: convert an MFC application to MFC DLL
- From: Joseph M . Newcomer
- Re: convert an MFC application to MFC DLL
- From: Tom Gonuts
- Re: convert an MFC application to MFC DLL
- From: Ajay
- Re: convert an MFC application to MFC DLL
- From: Tom Gonuts
- convert an MFC application to MFC DLL
- Prev by Date: Re: Calling CreateDispatch to create Word Instance
- Next by Date: Re: convert an MFC application to MFC DLL
- Previous by thread: Re: convert an MFC application to MFC DLL
- Next by thread: Re: convert an MFC application to MFC DLL
- Index(es):
Relevant Pages
|