dll access violation with Excel 32 / 64 bits
-
Hi, I built a function library (dll) in MS-Visual Studio 2022 using C/C++, to be accessed directly from Excel cells via VBA code. When I call the dll in the 32-bit version of Microsoft 365 Excel, no error occurs. But when I compile the dll for x64 and run it from the 64-bit version, an access violation occurs in the function arguments. Summarizing the project in a single function:
---------------------------------------------------------------
.cpp file:extern "C"
{
__declspec(dllexport) double __stdcall fA(INT64&);
}double __stdcall fA(double& a) // causes an exception in 64 bits mode
{
return a;
}VBA da planilha Excel:
Declare PtrSafe Function fA _
Lib "C:\dll64\dll64.dll" (ByRef a As Double) As Double-------------------------------------------------------------
-
Hi, I built a function library (dll) in MS-Visual Studio 2022 using C/C++, to be accessed directly from Excel cells via VBA code. When I call the dll in the 32-bit version of Microsoft 365 Excel, no error occurs. But when I compile the dll for x64 and run it from the 64-bit version, an access violation occurs in the function arguments. Summarizing the project in a single function:
---------------------------------------------------------------
.cpp file:extern "C"
{
__declspec(dllexport) double __stdcall fA(INT64&);
}double __stdcall fA(double& a) // causes an exception in 64 bits mode
{
return a;
}VBA da planilha Excel:
Declare PtrSafe Function fA _
Lib "C:\dll64\dll64.dll" (ByRef a As Double) As Double-------------------------------------------------------------
Why did you declared it as
double __stdcall fA(INT64&);
not as
double __stdcall fA(double&);