By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

Delegates - what am I doing wrong?

P: n/a
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(ScriptCompilerCa llback*
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.
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Please...?

Or it isn't possible to pass a managed callback function to the native code
in a single mixed assembly? No other way than DllImport? I'd like to wrap
the unmanaged .lib into a .NET assembly. Please help.

-pc


"Pepa Cougar" <co****@centrum.cz> wrote in message
news:53**************************@posting.google.c om...
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(ScriptCompilerCa llback*
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.

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.