I have the following callback signature and the delegate I am using for
the function pointer:
//C++ Callback Signature:
void(*pErrorHandler)(acTErrorMsgType ErrorMsgType, acTErrorCode
ErrorCode, acTBoardHandle BoardHandle, acTChannelHandle ChannelHandle,
const char *Format, ...);
//C# delegate for callback:
public delegate void ErrorHandlerDelegate(
ErrorMsgType errorMsgType,
ErrorCode errorCode,
int boardHandle,
int channelHandle,
string errorString);
Is there a way to marshall the C++ '...' variable parameter list from
C#, perhaps using a Param Array (..., params object[] args)?
Mattias Sj?gren - 15 Jan 2005 01:26 GMT
Jason,
>Is there a way to marshall the C++ '...' variable parameter list from
>C#, perhaps using a Param Array (..., params object[] args)?
The short answer is that no, you can't do this in pure C#. You can in
IL assembler or C++.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jason Cartwright - 17 Jan 2005 15:05 GMT
Unfortunately that is what I suspected. Is it predictable what will
happen when the C# delegate is "called" from unmanaged code if optional
parameters are supplied? I'm ok with ignoring the optional params as
long as the call itself doesn't fail completely.
Mattias Sj?gren - 18 Jan 2005 23:30 GMT
Jason,
>Unfortunately that is what I suspected. Is it predictable what will
>happen when the C# delegate is "called" from unmanaged code if optional
>parameters are supplied?
To get vararg support at all in C++ means you must use the cdecl
calling convention. But delegate callbacks expect a stdcall calling
convention by default. So you'll likely corrupt the stack.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.