In C you can declare a function like this
int average( int first, ... )
Where the ellipses denote a variable argument list.
If I have a function like that in a c++ DLL and I want to link a Visual Basic GUI to it, how would that function be declared in the Visual Basic program?

The Visual Basic 6 text I have talks about something called Optional Variant but it looks like it will only apply for one variable and not a list of unknown variables.

I'm pretty sure you have to know the C types, and the mimic them in VB, and probably declare the .dll as you would in the API.

For example, the findwindow api call (declared as):

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Is a simple function, that searches for an open window by either it's class name, or by the caption in the titlebar. If you look at the declaration for it, you are telling vb that you want to declare the function, and then you give it the name of the function (the name of the function here, but be the same as that in the .dll file), then the lib keyword, which identifies which library (which .dll file) the function can be found in. Then it gives an Alias, I don't remember exactly what it's for, but has something to do with not conflicting with functions already existing with the same name (or something crazy). Then you have the parameter list, that the function requires/expects. This function expects 2 parameters passed to it, in this case both strings. As a person who understands C, I'm not going to insult your intelligence by explaining what byval is.... and this function returns a long value (a windows handle to the found window, or 0 for none found). I'm imagining that is how you would make VB call the functions in your C dll, unless I completely missed the mark on this one, and you meant something else entirely (in which, accept my apologies).

This article has been dead for over six months. Start a new discussion instead.