简体   繁体   中英

Error accessing 64bit DLL function

I have created a 64bit DLL file using Microsoft Visual Studio 2015. Visual C --> Win32 Project.

The code for squareMain.c is as follows :

 long _stdcall square(long a)
 {
  return a*a;
 }

The code for Defile.def is as follows :

    LIBRARY "square"
    EXPORTS
    squareforExl=square

I have build the DLL using configuration manager settings set platform and active solution platform to x64 for 64bit DLL.

I have to access this DLL functions through Excel vba7. The function in VBA is as follows :

Private Declare PtrSafe Function squareforExl Lib "C:\math.dll" (ByVal x As Long) As Long

Sub square()
    Dim b As Long
    b = 5
    Dim c As Long
    Debug.Print b
    c = squareforExl(b)
    Debug.Print "Square : " & c
 End Sub

While trying to access DLL function squareforExl() as in the code above, it shows the following error msgBox:

Run time Error '53':  File not Found :"C:\math.dll"

I have tried placing file in different location directories, even in systems folder.

I have successfully compiled and executed 32bit DLL on in a 32 bit version of Office. My question is how can I access the DLL functions for a 64 bit dll in a 64 bit version of Office ?

Please Check your Office installation whether it is 64bit installation or 32bit installation. Meaning that, if VBA editor is in VBA7, it doesn't mean office is 64bit. It seems, you have 32bit office installation (ie later 2007 version, so that VBA7) on 64bit OS. Please create DLL in 32bit and use Ptrsafe in VBA (as it is VBA7), the error will be nullified. For 64bit Office Installation on 64bit OS, Calling 64bit DLL with Ptrsafe, will not have any issue. I'd both usages ie(1. 64bit office on 64bit os. 2. 32bit office with VBA7 on 64bit OS) and working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM