0

I would like to call a DLL function from Visual Basic.

In C, the DLL function looks like

typedef struct {
   int values[8];
   int etc;
} S;

int dllfunction(const S *s);

In Visual Basic, I have successfully defined the function as follows:

Friend Class MyDll
    Public Structure S
        Public Value1, Value2, Value3, Value4, Value5, Value6, Value7, Value8 As Integer
        Public Etc As Integer
    End Structure

    Friend Declare Auto Function dllfunction Lib "mydll.dll" (ByRef S As S) As Integer
End Class

Calling the function is then possible with

Dim S as Dll.S
...   (Initialize S member variables)

Dll.dllfunction(S)

I would like, instead of explicitly defining eight variables for int values[8], to use some sort of array than match the C array layout and that can be used (or easily copied from/into) a Visual Basic array. Is there any language construct that allows this?

Note that

Public Structure S
    Public Values as Integer(4)
    Public Etc As Integer
End Structure

is not allowed by the language.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Étienne
  • 407
  • 4
  • 15
  • Declare it with pinvoke. Then it's all good. Also, that function looks like it is cdecl. Again you'll need pinvoke for that. You are using legacy declare syntax and from that do your problems stem. – David Heffernan Mar 18 '21 at 21:08
  • I have added the VB syntax to the linked answer. – Étienne Mar 20 '21 at 07:57

0 Answers0