unmanaged callback (for dll interaction)
-
Hi, My problem is to create a delegate for the following callback definition (c++ syntax): typedef void (__stdcall *UnmanagedCallback)(std::wstring& WStringObject, const wchar_t* StringData, unsigned __int32 StringLength); I tried something like this:
public delegate void UnmanagedCallbackDelegate(ref string stringObject, string stringData, UInt32 stringLength);
or:public delegate void UnmanagedCallbackDelegate(ref string stringObject, [MarshalAs(UnmanagedType.LPWStr)]string stringData, UInt32 stringLength);
The callback fired from the dll is a _stdcall. Someone has a clue what I do wrong? Thanks in advance... Uwe. -
Hi, My problem is to create a delegate for the following callback definition (c++ syntax): typedef void (__stdcall *UnmanagedCallback)(std::wstring& WStringObject, const wchar_t* StringData, unsigned __int32 StringLength); I tried something like this:
public delegate void UnmanagedCallbackDelegate(ref string stringObject, string stringData, UInt32 stringLength);
or:public delegate void UnmanagedCallbackDelegate(ref string stringObject, [MarshalAs(UnmanagedType.LPWStr)]string stringData, UInt32 stringLength);
The callback fired from the dll is a _stdcall. Someone has a clue what I do wrong? Thanks in advance... Uwe.You can use the DllImportAttribute[^] to specify the CallingConvention[^], but I don't think .Net will marshal STL strings to a String. You would probably have to specify those parameters as an IntPtr, then convert the code from this[^] article to C# (it's shown in the "Converting String to std::string" section).
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com