variable args question

  • Thread starter Thread starter Bit byte
  • Start date Start date
B

Bit byte

I have a C function that takes variable args, i.e. is of the form :

foo( const char*, const int, ... ) ;

I want to expose this function so that I can call it from VB(6).

My questions are:
1). Is it possible to export a function with variable args in a DLL?
2). How would such a functon be called from VB ? (Ok, this may not be
the correct group for a question on VB but, it is related to what I'm
doing ... )
 
I have a C function that takes variable args, i.e. is of the form :
foo( const char*, const int, ... ) ;

I want to expose this function so that I can call it from VB(6).

My questions are:
1). Is it possible to export a function with variable args in a DLL?
I have never done so, but since the printf routines in the dynamic runtime
are also exported from a dll this should be possible.
2). How would such a functon be called from VB ? (Ok, this may not be the
correct group for a question on VB but, it is related to what I'm doing
... )

I think this is what you are looking for:
http://msdn2.microsoft.com/en-US/library/sect4ck6(VS.80).aspx
A quick google indicated that this also works for vb6 (though it would be
safer to check in the vb6 documentation)

Note that I have never used VB, so I cannot tell you how you have to tell it
how to marshall your variables, but that should be standard stuff I guess.
microsoft.public.dotnet.languages.vb would be a good place to ask that
question probably.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
Bit said:
I have a C function that takes variable args, i.e. is of the form :

foo( const char*, const int, ... ) ;

I want to expose this function so that I can call it from VB(6).

My questions are:
1). Is it possible to export a function with variable args in a DLL?

Sure - just export it.
2). How would such a functon be called from VB ? (Ok, this may not be
the correct group for a question on VB but, it is related to what I'm
doing ... )

I don't believe that it's possible to call a varargs function from VB6 - at
least not while preserving the variable argument list feature (which, AFIAK,
VB doesn't have).

If you always need to pass the same number and type of arguments, you could
simply declare the VB function to have a fixed argument list it, I believe,
it should "work", but that's definitely going down the path of hackery
rather than solid design..

-cd
 
Back
Top