问题
I have some sample code from MSDN that I am trying to adapt for use but the VBA compiler rejects the contents of the angled 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 the compile error 'expected line number or label or statement or end of statement' and do not find the help menu provided to be any use. I have tried square brackets [ ] in case this is a problem of VBA version to no avail. Could someone point out my error in using the COM interop services.
回答1:
The code is VB.NET. This is not VBA.
In VBA you would write,
Declare Function Test Lib "../../insert_dll_name_here.dll" (file() As String) As Long
However, VBA does not directly support the cdecl convention, but you can make it work with a type library. You may also have troubles with the file() As String array - make sure to handle it properly on the C++ side.
As a side note, this has nothing to do with COM. This is calling a function from an external library.
来源:https://stackoverflow.com/questions/16648447/vba-com-interop-troubles