Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a problem to use a code compiled with Microsoft Visual Studio 2022.
Basically the code generates a dll that takes an argument and returns another to an Excel cell. The code below works correctly in the 32-bit architecture of Office (generating code like Win32), but gives an error when receiving the variable "a" in the 64-bit version of Office.

double __stdcall fA(double& a) // causes an exception reading "a" - only in 64 bits mode
{
return a;
}

If I change the code to:
double __stdcall fA(double& a) // caues an exception reading "a" - only in 64 bits mode
{
return 5;
}
the number 5 is displayed correctly in corresponding Excel cell.

At the VBA module…
Declare PtrSafe Function fA Lib "C:\mydll.dll" (ByRef a As Double) As Double

Does anyone have any idea what this problem could be or the root cause of it?

C++
web




What I have tried:

Hi,

I have a problem to use a code compiled with Microsoft Visual Studio 2022.
Basically the code generates a dll that takes an argument and returns another to an Excel cell. The code below works correctly in the 32-bit architecture of Office (generating code like Win32), but gives an error when receiving the variable "a" in the 64-bit version of Office.

double __stdcall fA(double& a) // caues an exception reading "a" - only in 64 bits mode
{
return a;
}

If I change the code to:
double __stdcall fA(double& a) // caues an exception reading "a" - only in 64 bits mode
{
return 5;
}
the number 5 is displayed correctly in corresponding Excel cell.

At the VBA module…
Declare PtrSafe Function fA Lib "C:\mydll.dll" (ByRef a As Double) As Double

Does anyone have any idea what this problem could be or the root cause of it?

C++
Posted
Updated 12-Jan-23 6:26am
Comments
Richard MacCutchan 12-Jan-23 10:49am    
Are you trying to use the 32-bit dll with the 64-bit Office?
Danilo Lemos 2021 12-Jan-23 11:32am    
Yes but it doesn't work. When I compile the code in x86 mode it works only in 32 bits version.

1 solution

Quote:
Yes but it doesn't work. When I compile the code in x86 mode it works only in 32 bits version

Well, that's why it doesn't work.

You cannot combine 32 and 64-bit code in the same process. If you're using 64-bit Office, the .DLL you're using must also be compiled 64-bit. The same goes for 32-bit Office. If you're using 32-bit Office, the .DLL must be compiled 32-bit.

This goes for ALL applications in Windows, not just Office.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900