473,624 Members | 2,119 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 2015
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
4453
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 application runs flawlessly, but once I call the class from inside a c# windows application the program freezes, crashes etc... there must be a way to make this work inside a windows app as it run great as a command line app.
1
2985
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 header files. According to the documentation and the header files the function I need is declared as follows: extern "C" {
3
3455
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 have the same signature, and I never have to call more than one DLL in the same program. (The DLLs parse and validate 5 different binary formats.) Originally I was expecting to have 5 different C# programs as the constants are different for each...
2
10473
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 regsvr32) and uses Assembler to make some math in SSE. The result is given out as an Int. Using a C# console app (code below) it work fine & fast.
9
20363
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 input char* parameter for example
6
5208
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. What am I doing wrong?
9
8204
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 which call the API functions I want to use. That compiled and ran well. The C++ code is as follows: My header file void createSummarizer(char* rdir, char* lFile, char* key); void createInputOptions(const char* genre, const char* variant, const...
1
2763
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). The first function is called "StrFirst" and takes in a LPTSTR as the first parameter and a long as the second, like this: SIMPLELIB_API int StrFirst(LPTSTR str, long num); The second function is essentially the same thing, but with the order of the...
1
5790
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 code: #define USERINT_FUNC __cdecl #ifdef __cplusplus extern "C" { #endif
0
8234
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4079
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
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 we have to send another system
2
1482
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.