473,500 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2001
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4431
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
1
2965
by: Peter Gloor | last post by:
Hello NG, I have a mirror.dll written in C I would like to access from a C# console application. However, I dont't know how to to it. The dll is fairly well documented and I have access to the...
3
3441
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
2
10463
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
9
20343
by: Gnic | last post by:
Hi, I have a (Complied) C Library that needs to be called using c# code, some of the function require char* parameter(in and out) Here is the problem, There is a function that expect an...
6
5175
by: not_a_commie | last post by:
I changed the stdout in my C# app using Console.SetOut. It works fine for all my Console.Out.Write calls and with log4net. However, I don't see any output from native dlls that write to stdout....
9
8192
by: jjones7947 | last post by:
Am doing a JNI wrap on a C++ API, am using VC7 and Eclipse. In preparation, I created a C++ executable which mimicked the flow of the JNI, i.e. a driver file which called methods in file with methods...
1
2740
by: JohnCox | last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode). ...
1
5775
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.