Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6881591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:07:38+00:00 2026-05-27T05:07:38+00:00

I need to call a DLL in 64-bit Excel for use in VBA. i.)

  • 0

I need to call a DLL in 64-bit Excel for use in VBA.
i.) I’ve been told I can’t use a 32-bit dll in a 64-bit program, is this true?
ii.) Does anyone know of an example they know to be working demonstrating loading a dll into VBA.

At the moment they’re not even loading. I can call the DLL’s fine from within C++.

The example code is as follows and compiles fine in 64 bit mode. I’ve tried registering the function. The VBA error is “compile error: expected lib”

Failing calling function in VBA

Public Declare PtrSafe Function getNumber_Lib "C:\Users\james.allsop\Documents\Visual Studio 2010\Projects\DynamicLibrary\x64\Debug\MathFuncsDll.dll" () As Integer

The following all compiles and runs.

MathFuncsDll.h

// MathFuncsDll.h
// Returns a + b
__declspec(dllexport) double Add(double a, double b);
// Returns a - b
__declspec(dllexport) double Subtract(double a, double b);
// Returns a * b
__declspec(dllexport) double Multiply(double a, double b);
// Returns a / b
// Throws DivideByZeroException if b is 0
__declspec(dllexport) double Divide(double a, double b);
__declspec(dllexport) double getNumber();

MathFuncsDll.cpp

#include "MathFuncsDll.h"
double Add(double a, double b)
{
  return a + b;
}

double Subtract(double a, double b)
{
  return a - b;
}

double Multiply(double a, double b)
{
  return a * b;
}

double Divide(double a, double b)
{
  if (b == 0)
  {
    return -1.0;
  }
  return a / b;
}

double getNumber()
{
    return 1000;
}

MyExecRefsDll.cpp

// MyExecRefsDll.cpp : Defines the entry point for the console application.
//
// MyExecRefsDll.cpp
// compile with: /EHsc /link MathFuncsDll.lib

#include <iostream>
// Returns a + b
__declspec(dllimport) double Add(double a, double b);

// Returns a - b
__declspec(dllimport) double Subtract(double a, double b);

// Returns a * b
__declspec(dllimport) double Multiply(double a, double b);

// Returns a / b
// Throws DivideByZeroException if b is 0
__declspec(dllimport) double Divide(double a, double b);
__declspec(dllimport) double getNumber();

int main()
{
    double a = 7.4;
    int b = 99;
    std::cout << "a + b = " << Add(a, b) << "\n";
    std::cout << "a - b = " << Subtract(a, b) << "\n";
    std::cout << "a * b = " << Multiply(a, b) << "\n";
    std::cout << "a / b = " << Divide(a, b) << "\n";
    return 0;
}

Any help would be greatly appreciated!
James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:07:39+00:00Added an answer on May 27, 2026 at 5:07 am

    Your declaration in VBA contains an error. It should be:

    Public Declare PtrSafe Function getNumber Lib "C:\Users\james.allsop\Documents\Visual Studio 2010\Projects\DynamicLibrary\x64\Debug\MathFuncsDll.dll" () As Integer
    

    instead of:

    Public Declare PtrSafe Function getNumber_Lib "C:\Users\james.allsop\Documents\Visual Studio 2010\Projects\DynamicLibrary\x64\Debug\MathFuncsDll.dll" () As Integer
    

    Note the removed underscore.

    And yes, you cannot call 32-bit DLLs from 64-bit applications and vice versa. That’s a general restriction for all applications, not just for VBA or Excel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call some methods in Wininet.dll from a Java program. I can
Question: I need to call a C# dll from a C++ executable. I use
I have a third party DLL i need to call from my C# program.
I need to call some jQuery .load() function from flash. i Use this: import
I need to call this method, but I can't find it in any namespace.
I can't seem to find this on msdn been searching for a bit (described
I need to call an external dll from c#. This is the header definition:
I need to call a function in an unmanaged .dll written in C lang
In my C# code, I need to call a function from a C++ Dll
I writing a PHP script program under Linux. In the script, I need call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.