从VBA调用DLL

时间:2009-10-12 18:47:31

标签: c++ ms-access vba dll

我需要使用VBA从Access调用DLL函数。 DLL函数的原型是

int __stdcall myFunction(const char* data,
        int rows, int cols, int sl, int fullsize, 
        double aspect_ratio,
        double y,
        void** ppResult);

我在Access中声明的那个:

Private Declare Function DllImport_myFunction _
        Lib "myFunctionDLL.dll" _
        Alias "myFunction" _
            (ByVal data As String, _
             ByVal rows As Long, _
             ByVal cols As Long, _
             ByVal sl As Long, _
             ByVal fullsize As Long, _
             ByVal aspectRatio As Double, _
             ByVal y As Double, _
             ByRef handle As Long)

当我尝试从Access调用时,Access因访问冲突而崩溃。我在DLL函数的第一个语句中放置了一个断点,但它没有被命中。

声明是否不正确?

1 个答案:

答案 0 :(得分:1)

您错过了返回

Private Declare Function DllImport_myFunction Lib "myFunctionDLL.dll" Alias "myFunction" _
(ByVal data As String, _
 ByVal rows As Long, _
 ByVal cols As Long, _
 ByVal sl As Long, _
 ByVal fullsize As Long, _
 ByVal aspectRatio As Double, _
 ByVal y As Double, _
 ByRef handle As Long
) As Long

并且可能需要添加extern“C”以避免重复。