×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

***** 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

***** 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 --> Dump

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 

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

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.

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

The problem in the OP was running a 64 bit DLL in 64 bit Excel:

Quote:

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:

https://newtonexcelbach.com/2013/03/28/installing-...

Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/

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

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

White Paper - The Criticality of the E/E Architecture
Modern vehicles are highly sophisticated systems incorporating electrical, electronic, software and mechanical components. Mechanical systems are giving way to advanced software and electronic devices, driving automakers to innovate and differentiate their vehicles via the electric and electronic (E/E) architecture. As the pace of change accelerates, automotive companies need to evolve their development processes to deliver and maximize the value of these architectures. Download Now
White Paper - Model Based Engineering for Wire Harness Manufacturing
Modern cars, trucks, and other vehicles feature an ever-increasing number of sophisticated electrical and electronic features, placing a larger burden on the wiring harness that enables these new features. As complexity rises, current harness manufacturing methods are struggling to keep pace due to manual data exchanges and the inability to capture tribal knowledge. A model-based wire harness manufacturing engineering flow automates data exchange and captures tribal knowledge through design rules to help harness manufacturers improve harness quality and boost efficiency. Download Now
White Paper - Modeling and Optimizing Wire Harness Costs for Variation Complexity
This paper will focus on the quantification of the complexity related costs in harness variations in order to model them, allowing automated algorithms to optimize for these costs. A number of real world examples will be provided as well. Since no two businesses are alike, it is the aim of this paper to provide the foundational knowledge and methodology so the reader can assess their own business to model how variation complexity costs affect their business. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close