Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

#VALUE! when calling DLL function (C++) in 64-bit Excel

Status
Not open for further replies.

justhumm

Structural
May 2, 2003
111
Not sure if this is the right forum for this, but like Ol' Jack always says...what the hell?

I am very new to C-plus-plus and trying to use it to create user-defined functions for excel. I wrote a very simple test function in Cpp that just adds two arguments together (Excel cell references).

I compiled a 32-bit DLL & a seperate 64-bit DLL project using the same *.cpp and *.def files in Visual Studio 2013.

When I run the 32-bit DLL in a 32-bit Excel install, the new excel function works fine (eg: 5 + 10 = 15).

When I run the 64-bit DLL in a 64-bit Excel install, I am getting a #VALUE error in the cell.

Can anyone see something blatantly wrong that I am doing with the 64-bit DLL or the VBA declare? Thanks!

Code:
***** VBA (32-bit) *****
Declare Function ExPlus Lib _
"C:\AKH-VSWS\Ex-Plus32\Debug\Ex-Plus32.dll" _
(ByVal a As Double, _
 ByVal b As Double) As Double

Computer 1: Windows 7 (64-bit), Office 2016 (32-bit), Visual Studio 2013

Code:
***** VBA (64-bit) *****
Declare PtrSafe Function ExPlus Lib _
"C:\AKH-VSWS\Ex-Plus64\x64\Debug\Ex-Plus64.dll" _
(ByVal a As Double, _
 ByVal b As Double) As Double

Computer 2: Windows 7 (64-bit), Office 2016 (64-bit)

Code:
Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file c:\AKH-VSWS\Ex-Plus64\x64\Debug\Ex-Plus64.dll
PE signature found
File Type: DLL

FILE HEADER VALUES
            8664 machine (x64)
               7 number of sections
        5AC930F1 time date stamp Sat Apr 07 16:58:25 2018
               0 file pointer to symbol table
               0 number of symbols
              F0 size of optional header
            2022 characteristics
                   Executable
                   Application can handle large (>2GB) addresses
                   DLL

 
Replies continue below

Recommended for you

You can't use a 32-bit DLL in a 64-bit application. Same is true for a 64-bit DLL in a 32-bit application. If you want to use your DLL in 64-bit excel, you need to build a 64-bit version.
 
The problem in the OP was running a 64 bit DLL in 64 bit Excel:

When I run the 64-bit DLL in a 64-bit Excel install, I am getting a #VALUE error in the cell.

It is some time since I looked at linking directly to C++ DLLs from Excel, mainly because of the 64 bit/ 32 bit problems, but you might find something useful in the blog post below, or the links:




Doug Jenkins
Interactive Design Services
 
Thanks for the responses!

I think I figured out what my issues were...

I was compiling it in debugger mode, so it was adding a "D" onto the name of one of the dependency files. And when I moved the DLL to a computer without Visual Studio, it wouldn't run. I had to switch my compile settings to release mode.

In the *.cpp file, I was missing one of the two underscores (_) in the __stdcall statement. And Visual Studio's debugger and I weren't catching it. So the user-defined-function wasn't being exported with the DLL.

I also didn't properly register / set-up the *.def file within Visual Studio. So even if the __stdcall statement was correct, the function still wouldn't have exported correctly.

And apparently, if you don't somehow register the UDF with excel/windows, you need to run the C++/DLL function through a local VBA function. I have to read up on that (XLL's and all that fun stuff).

So, in conclusion, yeah...I was being stupid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor