How can I to pass an array to a DLL function?

  • Thread starter Carlos Villaseñor M.
  • Start date
C

Carlos Villaseñor M.

Hi everybody!

I finally have success implementing my first DLL function, I have exported a
C++ function with a DLL using the "Declare" statement in Basic, but now I
have a doubt, how can I to pass an array in the DLL function parameters
list, I need to pass y return the same array, but changed, to my Basic
application.

Below I show my code in Basic:

Private Declare Function CreateDll3 Lib "DLL3.dll" () As Long
Private Declare Sub DestroyDll3 Lib "DLL3.dll" (ByVal objptr As Long)
Private Declare Function GetCpuSpeedDll3 Lib "DLL3.dll" (ByVal objptr As
Long) As Integer

Private Declare Sub valor_prueba Lib "DLL3.dll" (ByVal objptr As Long, ByRef
val()) <--------- this is te function that need to pass an array

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Sub Form_Initialize()

InitCommonControls
ChDir App.Path

End Sub

Private Sub Command1_Click()

Dim nSpeed As Integer
Dim s As String
Dim s2 As String
Dim objptr As Long
Dim valor(0 To 3) As Integer


valor(0) = 3
valor(1) = 3
valor(2) = 3

Screen.MousePointer = vbHourglass
objptr = CreateDll3()
nSpeed = GetCpuSpeedDll3(objptr)
valor_prueba(objptr, valor()) <--------Here I call the DLL function, I
don't know if this is right....


DestroyDll3 (objptr)
Screen.MousePointer = 0

s = nSpeed
Form1.Text1.Text = "GetCpuSpeedDll3(objptr) returned " + s
Form1.Text2.Text = "El valor calculado es " + s2

End Sub


I appreciate some help!

Thank you
Carlos Villaseñor
 
M

Michel Posseth [MCP]

Hello carlos


Private Declare Sub valor_prueba Lib "DLL3.dll" (ByVal objptr As Long, ByRef
val()) <--------- there is no declaration type so , you should pass a
array of objects in VB.Net ( in VB6 you would have passed a variant
array )


regards

Michel Posseth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top