Solved

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

Posted on 1998-09-14
4
172 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

737 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