Hi einaros,
Thanks for your fast reply,
Please correct and guide me if I am wrong as things start to get confusing (too many questionmark in my head),
From what I understand that is using PInvoke (Platform Invoke) right.
But I found an URL how to create wrapper is something like the below
http://www.ondotnet.com/pub/a/dotnet/2004/03/29/mcpp_part3.html page=1
What is the different between them, PInvoke way and create a wrapper way to get call by C# application.
Thanks,
Regards,
Jimmy
Hi einaros,
Thanks for your help, now I seem to have must clearer view.
Anyway, I went to bought a book title call Pro Visual C++/CLI and the .NET 2.0 Platform by Apress for self-learning.
Any more recommended books if I want to learn more in depth.
Regards,
Jimmy.
Lets a vendor gives you a Class1.dll, Class1.h, Class1.lib
#ifdef
CLASS1_EXPORTS#define
CLASS1_API __declspec(dllexport)#else
#define CLASS1_API __declspec(dllimport)
#endif
// This class is exported from the Class1.dll
class
CLASS1_API CClass1 {public
:CClass1(
void); void M1();};
// This is the constructor of a class that has been exported.
// see Class1.h for the class definition
CClass1::CClass1()
{
return;}
void
CClass1::M1(){
printf(__FUNCTION__ "\n");
}
You need to create a C++ Class Library project - ClassLib1.
This class lib containes Class1:
#pragma
once#include
"..\class1\class1.h"using
namespace System;namespace
ClassLib1 { public ref class Class1{
private:CClass1& m_cl1;
public:Class1()
: m_cl1(*
new CClass1){
}
~Class1()
{
delete &m_cl1;}
void M1(){
m_cl1.M1();
}
};
}
add a refference to you Class1.lib using
ClassLib1 properties -> Configuration properties->Linker->Input
Additional Dependences: $(NoInherit); "[LibPath]Class1.lib"
Or using
#pragma comment(lib, "[LibPath]Class1.lib")
Compile! Should be compiled!
Then create C# project.
Add a reference to you ClassLib1.
static void Main(string[] args)
{
ClassLib1.
Class1 cl = new ClassLib1.Class1();cl.M1();
}
Make sure that Class1.dll, ClassLib1.dll lies beside your C# .exe program! By default ClassLib1.dll copied to output folder but not its dependences! It meand that you need manually copy Class1.dll.
If everything is right then you will obtain this output:
CClass1::M1
Press any key to continue . . .
ClassLib1.Class1 cl = new ClassLib1.Class1();
Can you post your code
Catch this exception and post output that returns by Exception.ToString