PC Review


Reply
Thread Tools Rate Thread

DllImport for C function with var args

 
 
Leon
Guest
Posts: n/a
 
      18th Jun 2008
Hi,

I have a C exported function in a DLL that has the following proto-type:
int _cdecl MyFunction( LPCSTR fmt, ... );

Does anyone know the DllImport declaration for this so that I can call this
in C#?

Thanks.

Leon
 
Reply With Quote
 
 
 
 
David Anton
Guest
Posts: n/a
 
      18th Jun 2008
Try the 'params' keyword.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI


"Leon" wrote:

> Hi,
>
> I have a C exported function in a DLL that has the following proto-type:
> int _cdecl MyFunction( LPCSTR fmt, ... );
>
> Does anyone know the DllImport declaration for this so that I can call this
> in C#?
>
> Thanks.
>
> Leon

 
Reply With Quote
 
Leon
Guest
Posts: n/a
 
      22nd Jun 2008
I know about using param in C#. But can you read my question carefully?

How to you declare [DllImport(....)] in C# for a C function that takes var
args like:

int _cdecl DoSomething( int abc, ... );

Thanks.

Leon

"David Anton" wrote:

> Try the 'params' keyword.
> --
> http://www.tangiblesoftwaresolutions.com
> C++ to C#
> C++ to VB
> C++ to Java
> VB to Java
> Java to VB & C#
> Instant C#: VB to C#
> Instant VB: C# to VB
> Instant C++: VB, C#, or Java to C++/CLI
>
>
> "Leon" wrote:
>
> > Hi,
> >
> > I have a C exported function in a DLL that has the following proto-type:
> > int _cdecl MyFunction( LPCSTR fmt, ... );
> >
> > Does anyone know the DllImport declaration for this so that I can call this
> > in C#?
> >
> > Thanks.
> >
> > Leon

 
Reply With Quote
 
Chris Jobson
Guest
Posts: n/a
 
      22nd Jun 2008
> How to you declare [DllImport(....)] in C# for a C function that takes var
> args like:
>
> int _cdecl DoSomething( int abc, ... );


You can't do a single declaration for the function. Instead you have to do a
separate declaration for each set of arguments you want to call it with. See
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.callingconvention(VS.71).aspx
which has an example of how to call printf from C#.

Chris Jobson


 
Reply With Quote
 
Leon
Guest
Posts: n/a
 
      23rd Jun 2008
Thanks.

Your answer and reference actually confirm that my declaration has not been
at fault.

Leon

"Chris Jobson" wrote:

> > How to you declare [DllImport(....)] in C# for a C function that takes var
> > args like:
> >
> > int _cdecl DoSomething( int abc, ... );

>
> You can't do a single declaration for the function. Instead you have to do a
> separate declaration for each set of arguments you want to call it with. See
> http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.callingconvention(VS.71).aspx
> which has an example of how to call printf from C#.
>
> Chris Jobson
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct way to call function with 2 args... Phil_V Microsoft Excel Programming 1 17th Mar 2006 01:49 PM
Is there a class or method to construct url args or extract url args? Ken Varn Microsoft ASP .NET 2 22nd Jun 2005 01:26 PM
Passing args to a Function quixote Microsoft Access VBA Modules 1 19th Aug 2003 06:31 PM
Re: Passing args to a Function Tim Ferguson Microsoft Access VBA Modules 0 18th Aug 2003 06:58 PM
Re: passing multiple args or an array of args to threads William DePalo [MVP VC++ ] Microsoft VC .NET 0 10th Jul 2003 05:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:40 PM.