Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. dll access violation with Excel 32 / 64 bits

dll access violation with Excel 32 / 64 bits

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiohelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Danilo Lemos 2021
    wrote on last edited by
    #1

    Hi, I built a function library (dll) in MS-Visual Studio 2022 using C/C++, to be accessed directly from Excel cells via VBA code. When I call the dll in the 32-bit version of Microsoft 365 Excel, no error occurs. But when I compile the dll for x64 and run it from the 64-bit version, an access violation occurs in the function arguments. Summarizing the project in a single function:

    ---------------------------------------------------------------
    .cpp file:

    extern "C"
    {
    __declspec(dllexport) double __stdcall fA(INT64&);
    }

    double __stdcall fA(double& a) // causes an exception in 64 bits mode
    {
    return a;
    }

    VBA da planilha Excel:

    Declare PtrSafe Function fA _
    Lib "C:\dll64\dll64.dll" (ByRef a As Double) As Double

    -------------------------------------------------------------

    V 1 Reply Last reply
    0
    • D Danilo Lemos 2021

      Hi, I built a function library (dll) in MS-Visual Studio 2022 using C/C++, to be accessed directly from Excel cells via VBA code. When I call the dll in the 32-bit version of Microsoft 365 Excel, no error occurs. But when I compile the dll for x64 and run it from the 64-bit version, an access violation occurs in the function arguments. Summarizing the project in a single function:

      ---------------------------------------------------------------
      .cpp file:

      extern "C"
      {
      __declspec(dllexport) double __stdcall fA(INT64&);
      }

      double __stdcall fA(double& a) // causes an exception in 64 bits mode
      {
      return a;
      }

      VBA da planilha Excel:

      Declare PtrSafe Function fA _
      Lib "C:\dll64\dll64.dll" (ByRef a As Double) As Double

      -------------------------------------------------------------

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Why did you declared it as

      double __stdcall fA(INT64&);

      not as

      double __stdcall fA(double&);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups