0

I have a project that was originally written in C. It's pretty large so I don't want to re-write it by hand if I can avoid it. The end goal is to embed it in a C# application. I've made and used CLR libraries before, but I'm having trouble with the below.

// CommandParse.h, used in a Win32 DLL
extern "C" {
    typedef struct _PARAMS {
        PCHAR OutputDir;
        //... other members
    } PARAMS, *PPARAMS;

    // defines in CommandParse.c
    __declspec(dllexport) VOID CmdParseParameters(PPARAMS, int, char ** const);  
}

I'm using VS2013 for these projects. And the above example is the stereotypical design pattern used in every other component.

// CommandParseWrapper.h, CLR library
namespace WrappedCode {
    public ref class CommandParams {
        PPARAMS params;
    public:
        CommandParams() {
            params = new PARAMS;
        }

        void parse(int argc, char ** const argv) {
            CmdParseParameters(params, argc, argv);
        }
    }
}

What I've done in the CLR project is added the Win32DLL project as a reference and added the source code to the "Additional Includes" setting in VS2013. However I've presented with the following errors.

error LNK2019: unresolved external symbol "extern "C" void __cdecl CmdParseParameters(struct _PARAMS *, int, char** const)"...

error LNK2028: unresolved token (0A00002E) "extern "C" void __cdecl CmdParseParameters(struct _PARAMS *, int, char** const)"...

Causing the compilation to fail. Any suggestions?

Note: I'm not against editing the original code.

leppie
  • 115,091
  • 17
  • 196
  • 297
Aage Torleif
  • 1,907
  • 1
  • 20
  • 37
  • It is a linker error, not a compilation failure. Something went wrong with "added the Win32DLL project as a reference". – Hans Passant Feb 18 '16 at 21:47
  • I can see the symbols in the export table of the DLL. And in the Solution Reference for the Win32DLL the path to the DLL is valid under the Reference Properties -> Full Path property. – Aage Torleif Feb 18 '16 at 21:53
  • I fold the answer to my question here [combining c and c how does ifdef cplusplus work](http://stackoverflow.com/questions/3789340/combining-c-and-c-how-does-ifdef-cplusplus-work) – Aage Torleif Mar 01 '16 at 13:43

0 Answers0