I am having a problem working with DLL functions in vba Excel 64-bit(Win8). When I force function declarations to be loaded from absolute DLL path, like below, there is no problem and my code runs well.
Private Declare PtrSafe Function get_Ith Lib "MYPATH\CVode.dll" (ByVal lpv As LongPtr, ByVal i As LongPtr) As Double
However, I don't want the absolute path. So, I put dll file next to the excel file (in the same folder) and declare function like the following:
Private Declare PtrSafe Function get_Ith Lib "CVode.dll" (ByVal lpv As LongPtr, ByVal i As LongPtr) As Double
Then I include following statements in Workbook_Open of the excel sheet.
Private Sub Workbook_Open()
ChDrive ThisWorkbook.Path
ChDir ThisWorkbook.Path
End Sub
I have been using this method for this dll (but newer version) as well as other projects without any problem.
But right now the vba returns some irrelevant values from dll functions and my program would blow out.
BTW, the dll has been written in c++ and I have the source code. In the source code there is .def file exporting all functions to external programs.
I would appreciate it if you help me out