本文介绍了从VBA调用DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to call a DLL function from Access using VBA. The prototype for the DLL function is

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

我在Access中声明的那个:

The one I declared in 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函数的第一条语句中放置了一个断点,但是没有被击中.

When I try to call from Access, Access crashed with an access violation. I placed a breakpoint in the first statement of the DLL function, but it was not hit.

声明不正确吗?

推荐答案

您错过了回报

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"以避免损坏.

and probably need to add extern "C" to avoid mangling.

这篇关于从VBA调用DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:50