0

I have an old Visual Studio C++ 6.0 DLL that I am trying to get call in a managed C++/CLI Code.

Here are the project settings that I used:

  1. Add the additional header directory for the unmanaged code
  2. Add the additional library directory for the unmanaged code
  3. Specify the lib file name of the unmanaged code
  4. Set the CLR option to /clr
  5. Removed the precompile header
  6. I am using VS2012 so I tried to lower the tooling to VS2008 \ I had just added the main header of the unmanaged code in the managed C++/CLI code.

The problem is it keeps on getting C2143 error in the struct definition.

The code is as follows

// logs struct
typedef struct FilesLog {
    FILE    *fpSender ;                   // <- Error in this line
    FILE    *fpReceiver ;                 // <- Error in this line
    int SendCount , ReceiveCount ;
} FilesLog_t ;

It gets C2143 on FILE lines also in another FILE line inside a class definition. (which means the error is not just on structs)

I have tried mixing and matching the project settings but it still does not work. Any ideas?

Here is the whole token error as suggested in the comment. Based on my understanding this means it does not recognize FILE that is why it is saying it needs a semicolon before *.

 error C2143: syntax error : missing ';' before '*'
Nap
  • 8,096
  • 13
  • 74
  • 117
  • 1
    Add `#include ` – Hans Passant Aug 28 '14 at 07:54
  • @HansPassant I already tried that but still the same error. – Nap Aug 28 '14 at 12:20
  • Well, you didn't try it right. I can't see it from here. Move it up so it is before any #includes that require FILE to be defined. Use Project + Properties, C/C++, Advanced, Show Includes = Yes to diagnose include order problems. – Hans Passant Aug 28 '14 at 12:22
  • @HansPassant Actually I have tried adding stdio.h before I posted this question. The struct is in a VC++6 library that works properly when added by a non managed MFC app. – Nap Aug 28 '14 at 13:07
  • Show the entire error message, not just the error number. What token was it expecting? – Ben Voigt Aug 28 '14 at 13:10
  • @BenVoigt Added the whole message – Nap Aug 28 '14 at 14:05

1 Answers1

1

Quite apart from the compiler errors you are getting, what you are attempting will never work.

FILE* is associated with internal data structures of the C++ runtime. The DLL will only accept FILE* values from its own Visual C++ 6.0 runtime, think of that as a FILEVC6MD*. If you use fopen in the C++/CLI DLL, you get a FILE* from the Visual C++ version it is compiled with, which you should think of as FILEVC9MD* (when compiling with Visual Studio 2008 tooling). It is a completely different data type. They aren't compatible in the slightest.

Generally having FILE* in the public API of a DLL is a very bad idea. Using your existing Visual C++ 6.0 DLL can only be done if it compiled with /MD to use a shared DLL for the runtime library, and then only by a caller using the same runtime library, which means either Visual C++ 6.0, or mingw. That rules out C++/CLI.

Your only hope for consuming this DLL from .NET is to write a wrapper compiled in Visual C++ 6.0 that exposes a saner public interface. That wrapper DLL can be called from p/invoke or C++/CLI.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • in your suggestion. Would that mean that when I include the wrapper header to the C++/CLI that It will include also include the FILE structure again because the include header of the wrapper included the header of the DLL? Anyway, I do not have an old PC (using Win7 MSVC6 is not working) to do this. I will get back to this answer of the result. – Nap Aug 28 '14 at 14:23
  • @Nap: The wrapper header will NOT include the header of the old DLL. Only wrapper implementation file will know about the old DLL and the old DLL's header. – Ben Voigt Aug 28 '14 at 14:28
  • Wait a second, I tried to rebuild the MSVC6 DLL in VS2008 and tried accessing it in a C++/CLI, however the same error persist. Did the path i took made sense? since i rebuild it in MSVC2008 should the FILE alredy be FILEVC9MD? Also when I go to the definition of FILE, i did not see the FILEVC9MD or FILEVC&MD only that it is either built in stdio or wchar or mbstring. – Nap Aug 29 '14 at 00:58