471,321 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

DllImport for C function with var args

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
Jun 27 '08 #1
4 1894
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
Jun 27 '08 #2
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
Jun 27 '08 #3
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/libr...on(VS.71).aspx
which has an example of how to call printf from C#.

Chris Jobson
Jun 27 '08 #4
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/libr...on(VS.71).aspx
which has an example of how to call printf from C#.

Chris Jobson
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Jim | last post: by
3 posts views Thread by Mark Jerde | last post: by
2 posts views Thread by Brian Anderson | last post: by
9 posts views Thread by Gnic | last post: by
6 posts views Thread by not_a_commie | last post: by
9 posts views Thread by jjones7947 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.