64bit Excel problem with DLL functions

Hi

I'm having  trouble with user-defined functions contained in a DLL. The functions don't work in 64bit Excel when called directly from a worksheet although they work fine when the DLL is compiled as 32-bit and called from 32-bit Excel. In 64-bit Excel they return strange values and usually crash Excel. I created a test DLL with a few simple functions with different data types as parameters that simply return the parameter passed to them converted to a double. The same problem exists whether the passed parameter is a double-precision float, 4-byte long, or 8-byte longlong.

The functions do work in 64-bit Excel when called from an intermediate Visual Basic function using code similar to the following and calling longlong1 from a worksheet:

     Private Declare PtrSafe Function LongLongtest Lib "64bitDLL" (ByVal result As LongLong) As Double

     Function longlong1(result As LongLong) As Double
          longlong1 = LongLongtest(result)
     End Function

I don't know if the problem is with Excel or the DLL. However, the DLL functions work fine when called from a console test program as well as from the Visual Basic interface in Excel. I've compiled the DLL in both C and C++ versions with Visual Studio Community, Embarcadero C++Builder XE8, and MinGW compilers and have the same problems with all of them. Does anyone have a suggestion re how to make the functions work when called directly from a worksheet?

Kaintuck1936

May 9th, 2015 6:37pm

Hi Kaintuck1936,
This is the forum to discuss questions and feedback for Microsoft Excel. And based on your description, you said it works fine from a console and you only provide the version of excel but not sure what the function to do with. We couldnt confirm if your issue more about developing of excel or more about C++. You also not sure if this problem with Excel or DLL. So I suggest you to post you issue to Excel for Developer forum and C++ forum at the same time, and please a bit more precise explain your issue.

This is the link of Excel for Developer forum:

https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc

This is the link of C++:

https://social.msdn.microsoft.com/Forums/en-US/home?forum=vcgeneral&filter=alltypes&sort=lastpostdesc

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

Regards,

George Zhao
TechNet Community Support

Free Windows Admin Tool Kit Click here and download it now
May 11th, 2015 3:23am

George,

Thanks for the reply. I should have stated in the original post that I'm using Office 2010 professional 64-bit Excel.

Today I verified that the problem is definitely an Excel problem, not the DLL or the C code. I tested the DLL in 64-bit MATLAB and it works perfectly, as it also does in a console program and when called from Visual Basic within Excel. However, when I call the DLL functions directly from an Excel worksheet I get garbage answers and Excel usually crashes. I wrote some test functions that displayed a message box showing what the functions were seeing as the input parameters. If the input was a long with a value "15", the message box showed "15" when called from VB or the console program, but showed some huge number when called directly from a worksheet. Same problem for other data types, e.g., single, double, short int, longptr.

The problem is almost as if the worksheet is using an incorrect protocol to call the DLL, but I don't see how that's possible since 64-bit Windows only has one protocol. I'd like to know if anyone has been successful in calling a function in a non-Windows DLL that has input values passed to it directly from an Excel worksheet.

May 12th, 2015 12:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics