VBA COM Interoperability Issues

I have a sample code from MSDN that I am trying to adapt for use, but the VBA compiler rejects the contents of the angle brackets < > . I have the following code in a module:

 Imports System Imports System.Runtime.InteropServices <DllImport("../../insert_dll_name_here.dll", CallingConvention:=CallingConvention.Cdecl)> _ Public Function Test(file() As String) As Integer End Function 

I am trying to use this code to call a simple function from a C ++ dll that expects an array of strings, but I get a compilation error "expected line number or label or operator or end of instruction" and cannot find the menu help intended to be used. I tried the square brackets [ ] in case this is a VBA version issue to no avail. Can anyone point out my mistake in using COM interoperability services.

+1
c ++ vba com
source share
1 answer

The code is VB.NET. This is not VBA.

In VBA you have to write

 Declare Function Test Lib "../../insert_dll_name_here.dll" (file() As String) As Long 

However, VBA does not directly support the cdecl , but you can make it work with a type library . You may also have problems with the file() As String array - be sure to handle it correctly on the C ++ side.

As a note, this has nothing to do with COM. This is a function call from an external library.

+1
source share

All Articles