hello,
now, i wanna port a c++ program into C# project. a DLL written by C++ and
keep it no change, and UI wirtten by C#.
my C++ UI code is as below:
// error handlers --global function callback function
// C++ dll would invoke this function if needed
void ImageConv_Callb ack_Handler(con st char *szInfo)
{
AfxMessageBox(s zInfo);
}
CXXXDlg::OnInit Dialog(...)
{
....
// Set Callback Function
SetImageConvCal lbackFunc(Image Conv_Callback_H andler);
....
}
{ // work flow
.....
}
and it works fine.
i wrote C# code for the same function, so that i need 2 write a callback
function in C#. my C# code is as below:
namespace ImageConvTest
{
partial class Form1 : Form
{
.....
public delegate void delegateCH(stri ng szInfo);
private void ImageConv_Callb ack_Handler(str ing szInfo)
{
MessageBox.Show (szInfo);
}
// error functions
[DllImport("Imag eConv.dll", EntryPoint = "SetImageConvCa llbackFunc")]
public static extern void
SetImageConvCal lbackFunc(deleg ateCHpFuncCallb ackProc);// in this case, is
delegateCHcorre ct? is it equal to "void *"???
private void Form1_Load(obje ct sender, EventArgs e)
{
InitImageConvLi brary();
//
delegateCH delegate_Callba ck_Handler = new
delegateCH(Imag eConv_Callback_ Handler);
SetImageConvCal lbackFunc(deleg ate_Callback_Ha ndler);
}
here, strange things happened to the C# project.
compiled it and got no errors. run it with no errors too. once i trigger the
function which is in C++ DLL, runtime exception occurs :-(
and if comments //SetImageConvCal lbackFunc(deleg ate_Callback_Ha ndler);
the program works fine.
is there any method to solve this problem? thank u very much.
--
With my kind regards,
Wen