Question

I have C++ managed dll compiled with /clr that has some global functions.

for example

void Managed2UnManaged(DataStructures::AAA^ elem, DataStructures::CPP::AAA* copy_elem);    

when I try to use these functions in a C++ managed console application I get the following errors

error LNK2028: unresolved token (0A00048C) "void __clrcall Managed2UnManaged(class DataStructures::AAA ^,class DataStructures::CPP::AAA *)" (?Managed2UnManaged@@$$FYMXP$AAVAAA@DataStructures@NextIn@@PAV1CPP@23@@Z)

error LNK2019: unresolved external symbol "void __clrcall Managed2UnManaged(class DataStructures::AAA ^,class DataStructures::CPP::AAA *)" (?Managed2UnManaged@@$$FYMXP$AAVAAA@DataStructures@NextIn@@PAV1CPP@23@@Z)

I added to the console application a reference to the dll but it still gives the error.

I also tried adding __declspec(dllexport) but then I get

error C3395: 'Managed2UnManaged' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention

and if I specify __stdcall I get

error C4439: 'Managed2UnManaged' : function definition with a managed type in the signature must have a __clrcall calling convention

I am using VS2012.

the h file has

class XXX {
 public:
static void Managed2UnManaged(DataStructures::RegResult^ elem,     DataStructures::CPP::RegResult* copy_elem);
};

and the cpp file

 void XXX::Managed2UnManaged(DataStructures::RegResult^ elem, DataStructures::CPP::RegResult* copy_elem)
{

}

Problem Solved. the problem was that I also needed to declare the class public ref. this caused a different problem because that the native c++ types are private. so I had to use the make_public pragma. Thanks all.

Was it helpful?

Solution

I think that the problem may be that the CLR doesn't allow global functions.

You must create a managed class and write your function as a static member function of that class, for that function to be exported.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top