c++ dll in C#
-
hi friends i have a c++ dll which contains function and class. c++ dll code
class __declspec(dllexport) MyClass
{
public:
MyClass(void);
~MyClass(void);
void GetName()
{
.......
}
};_declspec(dllexport) void MyFun()
{}
My c# code follows
public partial class Form1 : Form
{
[DllImport("CPPDLL.dll", EntryPoint="MyFun")]
static extern void MyFun();\[DllImport("CPPDLL.dll", EntryPoint="MyClass")\] static class MyClass; public Form1() { InitializeComponent(); } }
but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance
-kk.tvm-
-
hi friends i have a c++ dll which contains function and class. c++ dll code
class __declspec(dllexport) MyClass
{
public:
MyClass(void);
~MyClass(void);
void GetName()
{
.......
}
};_declspec(dllexport) void MyFun()
{}
My c# code follows
public partial class Form1 : Form
{
[DllImport("CPPDLL.dll", EntryPoint="MyFun")]
static extern void MyFun();\[DllImport("CPPDLL.dll", EntryPoint="MyClass")\] static class MyClass; public Form1() { InitializeComponent(); } }
but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance
-kk.tvm-
DllImport doesn't work with classes. You can't import a class - if you need the class structure, it's up to you to redefine it as a struct at the C# side.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
hi friends i have a c++ dll which contains function and class. c++ dll code
class __declspec(dllexport) MyClass
{
public:
MyClass(void);
~MyClass(void);
void GetName()
{
.......
}
};_declspec(dllexport) void MyFun()
{}
My c# code follows
public partial class Form1 : Form
{
[DllImport("CPPDLL.dll", EntryPoint="MyFun")]
static extern void MyFun();\[DllImport("CPPDLL.dll", EntryPoint="MyClass")\] static class MyClass; public Form1() { InitializeComponent(); } }
but DllImport for class(MyClass) shows syntax error. how can i solve this problem thanks in advance
-kk.tvm-
-
DllImport doesn't work with classes. You can't import a class - if you need the class structure, it's up to you to redefine it as a struct at the C# side.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
It means you need to code up the C# equivalent.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.