M
mot133t
I will quickly try to write a code that shows my intention. I will pass
unnecessary code.
typedef void(FP*)(LONG _param1, LONG _param2, BYTE* _pData);
class CNative
{
public: FP m_CallBack;
private: void JobDone()
{
for(iter i = m_Jobs.begin();i!=m_Jobs.end();++i)
{
// WORKS TWICE THAN CRASH
if(m_CallBack!=NULL) (*m_CallBack)(i->param1,i->param2, NULL);
}
}
};
ref class Managed
{
private: delegate void Handler(LONG _param1, LONG _param2, BYTE*
_pData);
private: CNative* m_Unmanaged;
private: Handler^ m_Handler;
private: /*USELESS static*/ void /*USELESS __stdcall */ Celebrate
(LONG _param1, LONG _param2, BYTE* _pData) {
// Invoke a nice event
}
public: void DoIt() {
m_Handler = gcnew Handler(this,&Managed::Celebrate);
// USELESS: pin_ptr<Handler^> pin(&m_Handler);
m_Unmanaged->m_CallBack =
Marshall::GetFunctionPointerForDelegate(m_Handler).ToPointer();
m_Unmanaged->DoYourJob();
}
};
I do get the right values from (*m_CallBack) twice. But then I beleive
stack is corrupted during function call, and BOOM
Can someone please tell me that this can not be done? I even don't know
how does it work twice.
And if you can tell the reason why is really appreciated. You can try
to explain me why do I try to do this
unnecessary code.
typedef void(FP*)(LONG _param1, LONG _param2, BYTE* _pData);
class CNative
{
public: FP m_CallBack;
private: void JobDone()
{
for(iter i = m_Jobs.begin();i!=m_Jobs.end();++i)
{
// WORKS TWICE THAN CRASH
if(m_CallBack!=NULL) (*m_CallBack)(i->param1,i->param2, NULL);
}
}
};
ref class Managed
{
private: delegate void Handler(LONG _param1, LONG _param2, BYTE*
_pData);
private: CNative* m_Unmanaged;
private: Handler^ m_Handler;
private: /*USELESS static*/ void /*USELESS __stdcall */ Celebrate
(LONG _param1, LONG _param2, BYTE* _pData) {
// Invoke a nice event
}
public: void DoIt() {
m_Handler = gcnew Handler(this,&Managed::Celebrate);
// USELESS: pin_ptr<Handler^> pin(&m_Handler);
m_Unmanaged->m_CallBack =
Marshall::GetFunctionPointerForDelegate(m_Handler).ToPointer();
m_Unmanaged->DoYourJob();
}
};
I do get the right values from (*m_CallBack) twice. But then I beleive
stack is corrupted during function call, and BOOM
Can someone please tell me that this can not be done? I even don't know
how does it work twice.
And if you can tell the reason why is really appreciated. You can try
to explain me why do I try to do this