Reputation: 1037
I've got c++/cli class library project. I need to import c++ native clases. they are declared like this
class __declspec(dllexport) Check
{
const char* type;
protected:
int val;
public:
Check(int);
Check();
const char* Type();
void Type(const char*);
virtual int Val();
void Val(int);
~Check(){};
};
class __declspec(dllexport) Test:public Check
{
const char* type;
public:
Test(int x);
int Val();
~Test(){};
};
how to import them into c++/cli project?(I've got .dll and .lib files)
Upvotes: 1
Views: 1405
Reputation: 941217
You don't "import" native code, it doesn't have anything resembling the metadata in a managed assemblies that describes the types.
You have to do this the old-fashioned way. You must use #include in your source code to include the .h header file(s) that declare the classes. Wrap those #includes with #pragma managed(push, off) and #pragma managed pop to ensure the compiler understands these are native code declarations. Also beware that the declarations you posted are not good enough, the classes must appear with the __declspec(dllimport) attribute. You normally use a macro for that.
And you must tell the linker to link the .lib, the import library for the DLL. Project + Properties, Linker, Input, Additional dependencies setting.
You'll find more hints on writing managed class wrappers in this answer.
Upvotes: 3