P
Pepa Cougar
Hello, I'm writing a managed C++ wrapper for a legacy C++ code. I'm
wrapping a script-compiler class, which uses a callback to report
script errors back to the client.
The callback prototype is defined as:
typedef void (__stdcall *COMPILE_ERROR_CALLBACK)(int Line, char* Text,
void* Data);
The script compiler provides a method for setting a callback with the
following prototype:
void SetCompileErrorCallback(COMPILE_ERROR_CALLBACK Callback, void
*Data);
That was the unmanaged side. I have a managed C++ class wrapping the
native class, which defines a delegate:
__delegate void ScriptCompilerCallback(int Line, String* Text, IntPtr
Data);
I want to wrap the native SetCallback method like this:
bool ManagedClass::SetCompilerCallback(ScriptCompilerCallback*
Callback, IntPtr Data)
{
Native()->m_ScriptEngine->SetCompileErrorCallback(Callback,
Data.ToPointer());
return true;
}
But I'm getting the following compile error:
error C2664: 'NativeClass::SetCompileErrorCallback' : cannot convert
parameter 1 from 'Namespace::ManagedClass::ScriptCompilerCallback __gc
*' to 'COMPILE_ERROR_CALLBACK'
There is no context in which this conversion is possible
What am I doing wrong? What is the right way of passing a managed
delegate to the unmanaged code?
I tried to remove the third parameter from the callback (void* vs
IntPtr) also changing char* to const char* but I'm still getting the
same error.
I would be grateful for any advice. Thank you.
wrapping a script-compiler class, which uses a callback to report
script errors back to the client.
The callback prototype is defined as:
typedef void (__stdcall *COMPILE_ERROR_CALLBACK)(int Line, char* Text,
void* Data);
The script compiler provides a method for setting a callback with the
following prototype:
void SetCompileErrorCallback(COMPILE_ERROR_CALLBACK Callback, void
*Data);
That was the unmanaged side. I have a managed C++ class wrapping the
native class, which defines a delegate:
__delegate void ScriptCompilerCallback(int Line, String* Text, IntPtr
Data);
I want to wrap the native SetCallback method like this:
bool ManagedClass::SetCompilerCallback(ScriptCompilerCallback*
Callback, IntPtr Data)
{
Native()->m_ScriptEngine->SetCompileErrorCallback(Callback,
Data.ToPointer());
return true;
}
But I'm getting the following compile error:
error C2664: 'NativeClass::SetCompileErrorCallback' : cannot convert
parameter 1 from 'Namespace::ManagedClass::ScriptCompilerCallback __gc
*' to 'COMPILE_ERROR_CALLBACK'
There is no context in which this conversion is possible
What am I doing wrong? What is the right way of passing a managed
delegate to the unmanaged code?
I tried to remove the third parameter from the callback (void* vs
IntPtr) also changing char* to const char* but I'm still getting the
same error.
I would be grateful for any advice. Thank you.