?
Solved

How to call a F(x, y, ... ) function

Posted on 1998-09-14
4
Medium Priority
?
174 Views
Last Modified: 2010-04-30
I'd like to make calls to a function that takes a variable length-list of arguments.

If the function F(x, y, ...) is contained in Mylib.dll, how could I declare it in a VB app ? And how to call it ?

Does anybody know how to do it ?
0
Comment
Question by:edsont
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 150 total points
ID: 1434804
VB doesn't recognize variable parameter counts.

You would declare it with it's full compliment of parameters and then pass 0 (or null) to those parameters that don't require values:
Private Declare Function Foo Lib "MyLib.dll"(P1 As Long, P2 As Long) As Long
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1434805
If you think about how function calls work it's clear that they can't have different numbers of params. Functions pass params on the stack. (that's why you CALL a function) If you had a different number of params passed how you would know when the params ran out?

One "end run" on this is to pass an *array* to the function. The first element in the array can define the number of additional elements in the array and you can therefore have a single param function that effectively has a varaible number of params. But the call itself, has a constant number.

0
 

Author Comment

by:edsont
ID: 1434806
clifABB,

Let me know if I understood your answer:

Suppose I have the following C function:

long WINAPI Foo( p1, p2, ... );

If the maximum number of parameters Foo can take is 5, I'd declare Foo in following way:

Declare Function Foo Lib "Mylib.dll" (p1,p2,p3,p4,p5) As Long

And if an app will use Foo with only 3 parameters, it would call:

  ret = Foo( p1, p2, p3, 0, 0 )

Is it correct ?

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434807
Yep.
I'm wondering how the C function could export a variable number of parameters and be understood by VB.
There is a possibility that VB couldn't deal with the function at all.  But, if it does the way I explained (and you understand) is it.

There is also a possibility that, if the functions are overloaded, that is to say there are two or more with the same name, you could declare each one using the alias and the functions ordinal number:
Private Declare Function Foo1 Lib "MyLib.dll" Alias "#1"(P1 As String) As Long
Private Declare Function Foo2 Lib "MyLib.dll" Alias "#2"(P1 As Long, P2 As Long) As Long
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question