Re: convert an MFC application to MFC DLL




"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


.



Relevant Pages

  • Re: VBA and VSTO
    ... If you compile in VB6 with Global MultiUse than all you have to do is set a reference in Excel to your dll via Tools, References and you can access your functions in the dll directly. ... You will have to register the dll as well with Windows with Regsvr32, but that can be done quite simply in VBA. ...
    (microsoft.public.excel.programming)
  • Re: HOW CAN I OPEN A COM PROJECT COMPILED IN VS2005, IN VS2003?
    ... I keep getting the .exe output when I compile in the VC7. ... the General Configuration Type to be .dll in the Project Property. ... Microsoft MVP, MCSD ... instead create my own folders for file grouping... ...
    (microsoft.public.win32.programmer.ole)
  • GlobalMultiUse component breaks its compatibility !!!
    ... I have a component (ActiveX dll) with only one class in it. ... compiled, even though the binary compatibility is set, a new UUID is ... Public Property Let MyStringProp(ByVal vNewValue As String) ... Compile the project. ...
    (microsoft.public.vb.com)
  • LNK2020 using managed/unmanaged classes combination and workaround question
    ... mark 'DLL' and 'Export Symbols'). ... this is a managed class added to the DLL. ... To the Windows Forms project, ... make sure you compile everything with /clr. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Program does not invoke methods of ActiveX-DLL
    ... >> and defining a compatibility-dll has the effect that I cannot compile the ... >> declared in that dll. ... > reference DLLB if DLLB doesn't contain a reference to DLLA... ...
    (microsoft.public.vb.com)