Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2006

Tip: Looking for answers? Try searching our database.

C DLL + variable length parameters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bit Byte - 28 Jul 2006 13:06 GMT
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)
William DePalo [MVP VC++] - 28 Jul 2006 16:10 GMT
> 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
[quoted text clipped - 7 lines]
>
> 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
Bit Byte - 28 Jul 2006 17:54 GMT
>>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
[quoted text clipped - 13 lines]
> 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 ?
William DePalo [MVP VC++] - 28 Jul 2006 19:31 GMT
> 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
Bruno van Dooren [MVP VC++] - 29 Jul 2006 12:43 GMT
> Thanks for replying, actually, my prototype was wrong. I wanted something
> more like this:
[quoted text clipped - 10 lines]
> 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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.