Click here to Skip to main content
14,983,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
first there was only c code, i added a c++ file and class and used that c code function within my c++ class.
Now i am creating cli wrapper class for my mixed c/c++ code:

my 'c' code:
header file : "Code.h"
#pragma once
extern "C"
 int perfomtask(int argc,char** argv);

class testclass
    public :
        void begintask(int argc, char **argv);

code file "code.c"
#include "Code.h"
int perfomtask(int argc, char **argv){...}

my cplusplus code file:

#include "code.h"

void testclass::begintask(int argc, char **argv)

now i have tested the working of the above with this main class
int main(int argc, char **argv)
    testclass obj1;
    return 0;


now that's about my c/c++ mixed code
now here's my cli wrapper code
header file=
using namespace System;

namespace wrapclass
    public ref class wrapclass
    public :
        void mynativeclass(int argc,char**argv);
        int argc;
        char** argv;
        testclass *ptestclass;

code file=
    ptestclass = new testclass();

    delete ptestclass;
void wrapclass::wrapclass::mynativeclass(int argc,char** argv)


now i am getting
error :
error LNK2028: unresolved token (0A00032E) "extern "C" int __cdecl perfomtask(int,char * *)referenced in function "public: void __thiscall testclass::begintask(int,char * *)" could someone help me out on this one any explanation would be appreciated.
Richard MacCutchan 7-May-15 8:20am
Have you built the C code with the C++ code?
RajneeshSaysHello 7-May-15 8:25am
yes it is building fine
RajneeshSaysHello 7-May-15 8:27am
the only problem is where to declare performtask() function so that it is visible to both cli linker and c++ linker after complie.
Richard MacCutchan 7-May-15 8:53am
I'm not sure as I don't do mixed mode. I can only assume that pure C code does not build properly under /CLI

1 solution

Check that in the linker option for common language runtime is not set to pure.
If it is set to '/clr:pure' the linker will produce MSIL code without any native executable code.
It should be set to '/clr'to allow for Mixed (Native and Managed) Assemblies.
See here[^] and here[^].
RajneeshSaysHello 13-May-15 1:47am
i put the .obj file reference in the linker additional dependencies option now the liker is able to find the function without any error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900