views:

382

answers:

2

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);

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)

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.

Is the declaration incorrect?

A: 

I changed it to

ByVal handle As Long

However itt still crashed.

Inside the function, the *ppResult is assigned to a pointer value that points to an object created. Just like the one in COM API

HRESULT QueryInterface(uuid, void**)
Sherwood Hu
A: 

You are missing the return

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

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

fnieto