C DLL + variable length parameters

  • Thread starter Thread starter Bit Byte
  • Start date Start date
B

Bit Byte

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)
 
Bit Byte said:
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
 
William said:
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 ?
 
Bit Byte said:
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
 
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
(e-mail address removed)
Remove only "_nos_pam"
 
Back
Top