Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

Possible to Marshal param array to unmanged code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Cartwright - 14 Jan 2005 21:02 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.