473,389 Members | 1,089 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 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 1994
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.