Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using dll with vba or vb

Status
Not open for further replies.

afarnes

IS-IT--Management
Mar 29, 2001
11
0
0
GB
I've been passed a dll file called AA_R.dll with the following instructions in a pdf about the dll. Basically by passing the dll the INPUT information below it will calculate and return the OUTPUT information below. Can anyone help me with a code example on how i could get this to work with VB or VBA, thanks?

Declaration of the calculation-procedure (Pascal)

type A_INPUT = array[1..4] of double;
A_OUTPUT = array[0..5] of double;

procedure A_CALC(
var a1 : integer;
var a2 : integer;
var B_INPUT : A_INPUT;
var a3 : integer;
var a4 : integer;
var B_OUTPUT : A_OUTPUT
); stdcall;

- the type double consists of 8 byte.
- the type integer consists of 2 byte.

Parameters of the procedure and their values

INPUT

PARAMETER VALUE UNIT
a1 without value
a2 without value
a3 without value
a4 without value

(You will need a1, a2, a3, a4 e.g., when you call the procedure.)

B_INPUT[1] pressure mbar
B_INPUT[2] air volume m³/h
B_INPUT[3] temperature °C
B_INPUT[4] humidity %

OUTPUT

PARAMETER VALUE UNIT
B_OUTPUT[0] Error Message
B_OUTPUT[1]-B_OUTPUT[4] B_INPUT[1]-B_INPUT[4]
B_OUTPUT[5] Total €

I've tried the following in Access VBA but i'm not really sure if i'm going down the right tracks:

Option Compare Database
Private Declare Function test Lib "C:\AA_R.dll" Alias "A_CALC" (ByVal a1 As Integer, ByVal a2 As Integer, ByVal B_INPUT As Double, ByVal a3 As Integer, ByVal a4 As Integer, ByVal B_OUTPUT As Double) As Long

Private Sub Command0_Click()
Dim testarray(4) As Double
Dim testarray2(6) As Double
testarray(0) = 1013
testarray(1) = 200
testarray(2) = -5
testarray(3) = 90
Call test(0, 0, testarray, 0, 0, testarray2)
Msgbox testarray2(0)
End Sub
 
VB gets a bit obscure when you pass arrays as parameters to procedures. I'm assuming that what you have here doesn't work, since you're attempting to pass an array to a parameter that you have defined as a double. That won't work. Can you explain exactly what your DLL is expecting for both your B_INPUT and B_OUTPUT parameters?
 
The only information i was given on the dll was as above. I'm assuming, for the input (B_INPUT), i need to pass an 8 byte array containing 4 lots of information; (1) a figure for pressure, (2) a figure for air volume, (3) a figure for temperature, (4) a figure for humidity.

From passing this information i should get an output (B_OUTPUT) 8 byte array that contains 6 lots of information; (1) An Error Message (if any); (2) to (5) The input information that i've passed to it; (6) The Total cost in € that the DLL has calculated.
 
It's not quite that simple. Check this page: Based on what I read there (that the api function typically expects the address of the first element of the array), I would suggest that you pass the first element of the array by reference. So put testarray(0) rather than testarray in your function call, and see if it works. No guarantees though! [neutral]

Good luck,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top