473,385 Members | 1,829 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,385 software developers and data experts.

C DLL + variable length parameters

Is it possible to pass variable length parameters to a C function
exported in a DLL (i.e. using varargs.h without resorting to say passing
a delimited string to be parsed in the function)?

i.e. I want something like this:

#include <varargs.h>

CCONV foo( char* fmt, va_list args ) ;

where CCONV is the calling convention (import/export)

Jul 28 '06 #1
4 1787
"Bit Byte" <fl**@flop.comwrote in message
news:Gr******************************@bt.com...
Is it possible to pass variable length parameters to a C function exported
in a DLL (i.e. using varargs.h without resorting to say passing a
delimited string to be parsed in the function)?

i.e. I want something like this:

#include <varargs.h>

CCONV foo( char* fmt, va_list args ) ;

where CCONV is the calling convention (import/export)
Yes. In fact wsprintf(), which takes a variable number of arguments, is
exported by USER32.DLL. What problem are you having?

Regards,
Will
Jul 28 '06 #2


William DePalo [MVP VC++] wrote:
"Bit Byte" <fl**@flop.comwrote in message
news:Gr******************************@bt.com...
>>Is it possible to pass variable length parameters to a C function exported
in a DLL (i.e. using varargs.h without resorting to say passing a
delimited string to be parsed in the function)?

i.e. I want something like this:

#include <varargs.h>

CCONV foo( char* fmt, va_list args ) ;

where CCONV is the calling convention (import/export)


Yes. In fact wsprintf(), which takes a variable number of arguments, is
exported by USER32.DLL. What problem are you having?

Regards,
Will

Hi Will,

Thanks for replying, actually, my prototype was wrong. I wanted
something more like this:

CCONV foo(char* fmt, ...) ;

To be exported by my DLL - is this possible ?

(from what you say though - it should be possible - since wsprintf is
exported by user32.dll. I have seen a lot of questions posted about this
and the answer seems to be a resounding no - or having to resort to
"tricks".

Ah, but I did leave out one piece of (vital?) information though - I
want to be able to call this Dll function from VB - still possible ?

Jul 28 '06 #3
"Bit Byte" <fl**@flop.comwrote in message
news:9u********************@bt.com...
Ah, but I did leave out one piece of (vital?) information though - I want
to be able to call this Dll function from VB - still possible ?
VB is another kettle of fish entirely.

You will get a better reply in the VB groups than from me because I am happy
to remain blissfully ignorant of VB. :-)

That said, I _think_ (and I could be wrong) that you would need to use
something like ATL's CComSafeArray class to pass a variable number of
widgets back and forth. How you'd consume such a thing in VB if it is indeed
possible ... well, it beats the heck out of me. :-)

Regards,
Will
Jul 28 '06 #4
Thanks for replying, actually, my prototype was wrong. I wanted something
more like this:

CCONV foo(char* fmt, ...) ;

To be exported by my DLL - is this possible ?

(from what you say though - it should be possible - since wsprintf is
exported by user32.dll. I have seen a lot of questions posted about this
and the answer seems to be a resounding no - or having to resort to
"tricks".

Ah, but I did leave out one piece of (vital?) information though - I want
to be able to call this Dll function from VB - still possible ?
This question came up some time ago, and the answer was negative.

Yes, you can export varargs functions (calling convention has to be __cdecl)
Yes you can use it in VB if you import it as a function with a specific
prototype (i.e. you fix the argument list).
No, you cannot -AFAIK- import it directly as a varargs function.

But maybe someone on the VB forums can give you an alternative solution /
workaround.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
>

Jul 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: yasaswi | last post by:
I am using field( substring( product_id, 1, 4 ), 'IR56', '1k09', '7a72', '6f22' ) > 0 in a where clause to select four different strings of same length. However I want to be able to search...
17
by: ethan | last post by:
Hi All, How to write a macro with variable length of argument? For example, if i need a macro to check return value of printf. #define PRINTF_ESC(x, ...) if(printf(x, ...) == 10) goto end; ...
5
by: Jim via DotNetMonster.com | last post by:
Hi, I need to pass the value of a variable from one function to another but I don't seem to get the value. I declare the variable outside all functions. What I'm trying to do is that when the...
6
by: mechanicfem | last post by:
In f(), I am passing a parameter of array type - /size/ indicates the array's length: void f(char arr, int size); In the c99 stds, it mentions the use of and says (I think) that it can be...
14
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and...
11
by: Fan Yang | last post by:
I'm reading Modern C++ Design, and it is saying "Variable template parameters simply don't exist." But I find VC7.1 & VC8 support this feature.Who can tell me that which is right -_-b Many thanks.
3
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window...
2
by: rameshbabupeddapalli | last post by:
Hi, I want to create my own variable length parameters function it should work like printf() function. When i write the program as given below it's working fine #include<stdio.h> ...
7
by: Drakemar | last post by:
Hello all, Thank you for taking the time to read and help me with my question. Here is a simplified program I have: int array2D = { {1, 2, 3}, {4, 5, 6} }; private void Main(){
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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...

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.