dieucay555
August 3rd, 2009, 10:32 PM
I trying use 1 DLL write by C++ in project C# but i hava a proplem!
In C++, when i create 1 event, using callback.For example : create event MouseMove : create 1 procedure is void CALLBACK MouseMoveProc(), and to handle events that it uses CadOnEventMouseMove(MouseMoveProc);in the form CadOnEventMouseMove void CadOnEventMouseMove (
F_MOUSEMOVE pFunc / / pointer to event procedure
);
To subscribe to the events which, in C # you do the following:
1 declare delegate to take the place of cursor to the function:
public delegate void MouseDelegate(int hDwg, int Button, int Key, int Xwin, int Ywin, double Xdwg, double Ydwg, double Zdwg);
And then, create event :
CadOnEventMouseMove(new VeCAD.MouseDelegate(MouseMoveProc));
When compiled no error but a few seconds after the application is crash, and errors arising :
"A callback was made on a garbage collected delegate of type 'VeCad_CS1!VeCAD.MouseDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called."
Please help me!
In C++, when i create 1 event, using callback.For example : create event MouseMove : create 1 procedure is void CALLBACK MouseMoveProc(), and to handle events that it uses CadOnEventMouseMove(MouseMoveProc);in the form CadOnEventMouseMove void CadOnEventMouseMove (
F_MOUSEMOVE pFunc / / pointer to event procedure
);
To subscribe to the events which, in C # you do the following:
1 declare delegate to take the place of cursor to the function:
public delegate void MouseDelegate(int hDwg, int Button, int Key, int Xwin, int Ywin, double Xdwg, double Ydwg, double Zdwg);
And then, create event :
CadOnEventMouseMove(new VeCAD.MouseDelegate(MouseMoveProc));
When compiled no error but a few seconds after the application is crash, and errors arising :
"A callback was made on a garbage collected delegate of type 'VeCad_CS1!VeCAD.MouseDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called."
Please help me!