S
Sebastian Grobosch
Hi All,
I have the following problem: I'm using a managed C++ Dll within a C#
project. I want to call a method of a C# class out of the Dll. I thought
about using delegates because of the managed C++ code. Could it
generally work with delegates? I tried it with this code, but no success:
managed C++ DLL:
public ref class MyClass
{
public:
delegate void CallBackFunction();
void CallTest(CallBackFunction^ Funktion);
};
C#:
// The delegate Class
public class DelegateFunctions
{
public delegate void delTest();
public delTest TestDelegate;
public DelegateFunctions()
{
}
}
....
dlgFunktion.TestDelegate = new DelegateFunctions.delTest(test);
//definition of the delegate function
....
void test()
{
MessageBox.Show("Hello World");
}
public void CallBack()
{
MyClass.CallTest(dlgFunktion.TestDelegate); // Call of the dll
function and transfer of the delegate function
}
If the method "CallBack()" is called, there should be a message box with
"Hello World", but there is only an Error CS1503 at
"MyClass.CallTest(dlgFunktion.TestDelegate)": The Argument could not be
converted from "DelegateFunctions.delTest" to "MyClass.CallBackFunction".
Any Ideas?
Sebastian
I have the following problem: I'm using a managed C++ Dll within a C#
project. I want to call a method of a C# class out of the Dll. I thought
about using delegates because of the managed C++ code. Could it
generally work with delegates? I tried it with this code, but no success:
managed C++ DLL:
public ref class MyClass
{
public:
delegate void CallBackFunction();
void CallTest(CallBackFunction^ Funktion);
};
C#:
// The delegate Class
public class DelegateFunctions
{
public delegate void delTest();
public delTest TestDelegate;
public DelegateFunctions()
{
}
}
....
dlgFunktion.TestDelegate = new DelegateFunctions.delTest(test);
//definition of the delegate function
....
void test()
{
MessageBox.Show("Hello World");
}
public void CallBack()
{
MyClass.CallTest(dlgFunktion.TestDelegate); // Call of the dll
function and transfer of the delegate function
}
If the method "CallBack()" is called, there should be a message box with
"Hello World", but there is only an Error CS1503 at
"MyClass.CallTest(dlgFunktion.TestDelegate)": The Argument could not be
converted from "DelegateFunctions.delTest" to "MyClass.CallBackFunction".
Any Ideas?
Sebastian