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

#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

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!


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


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

            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
                   Application can handle large (>2GB) addresses

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:


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

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

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


White Paper - PLM and ERP: Their Respective Roles in Modern Manufacturing
Leading manufacturers are aligning their people, processes, and tools from initial product ideation through to field service. They do so by providing access to product and enterprise data in the context of each person’s domain expertise. However, it can be complicated and costly to unite engineering with the factory and supply chain. 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