I am writing a C # library that will be used by a C ++ application. I use C ++ / CLI as an interaction mechanic.
I need to pass a callback function from C ++ to C # (using C ++ / CLI as an intermediate level). The C # library should call a C ++ function with a null-terminated string with wide characters; i.e. the prototype of the callback function is
Func (LPCWSTR pszString);
There are other parameters, but they are not essential for this discussion.
I searched the net and found Marshal.GetDelegateForFunctionPointer. The method I can use. The problem is that it converts System.String from C # to char * and not the wchar_t * I'm looking for.
Also, what is the best method to get this sample code, including the C ++ / CLI part, if possible. C ++ / CLI dll depends on C # dll. The method must be called synchronously.
source
share