Microsoft 365 VBA to call IBM MQ Client

Stephen Newell 1 Reputation point
2022-01-21T15:39:20.667+00:00

We have some old Excel 2010 VBA that makes calls to IBM MQ, via an external reference to MQAX200.DLL. We have now migrated to Microsoft 365 and this method no longer works. I need to make these Excels work under Microsoft 365. I have read that I should now use .NET MQ classes to integrate VBA with IBM MQ. However, I have been unable to make that work. I then thought that I could write a C++ DLL to integrate with MQ and have the Excel VBA call the C++ DLL. I have done this before with Excel 2010. However, I have been unable to get Microsoft 365 VBA to call any DLL. My latest error is runtime error 453 (can't find dll entry point...)

My VBA looks like this...

Private Declare PtrSafe Function TestDll1 Lib "C:\Users\steph\source\repos\TestDll1\x64\Debug\TestDll1.dll" () As LongLong
Private Declare PtrSafe Function TestDll2 Lib "C:\Users\steph\source\repos\TestDll1\x64\Debug\TestDll1.dll" () As Boolean

Sub Call_zMq_Click()
#If VBA7 Then
MsgBox "Code is running in the new VBA7 editor"
#If Win64 Then
MsgBox ("Windows 64")
#Else
MsgBox ("Windows 32")
#End If
#Else
MsgBox "VBA version 6 or earlier"
#End If

Dim zResult1 As LongLong
Dim zResult2 As Boolean
Dim zParm1 As LongLong
Dim zParm2 As LongLong

zParm1 = 1
zParm2 = 2
zResult1 = 0
zResult2 = False

zResult1 = TestDll1()
zResult2 = TestDll2()

End Sub

and I have built a 64-bit Windows C++ DLL with MSVS 2019, with this code...

// dllmain.cpp : Defines the entry point for the DLL application.

include "pch.h"

//--Public Functions--
__declspec(dllexport) long long __stdcall TestDll1();
__declspec(dllexport) BOOL __stdcall TestDll2();

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

long long __stdcall TestDll1()
{
long long returnValue = 456; // Our return value
return returnValue;
}

BOOL __stdcall TestDll2()
{
return TRUE;
}

pch.h simply looks like this...

ifndef PCH_H

define PCH_H

// add headers that you want to pre-compile here

include "framework.h"

endif //PCH_H

When executing the VBA, it shows Msgbox results of...
Code is running in the new VBA7 editor
Windows 64

and then hits runtime error 453.

I have tried adding a reference to my TestDll1 in my Excel VBA, but I get an error saying that it can't add a reference to the specified file.

Can anyone please advise? Ultimately, my aim is to integrate Microsoft 365 VBA with IBM MQ. If someone can give me example of that, it would be much appreciated. Or, if someone can give me example of Microsoft 365 VBA calling a 64-bit C++ DLL, that would help too because I could build the MQ integration in the C++ DLL. Or, do I need to use C# (I don't know C#, so am reluctant to take that approach)? Any help much appreciated.

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-01-21T15:56:25.557+00:00

    Try these definitions:

    extern "C"
    {
       __declspec( dllexport ) long long __stdcall TestDll1( );
       __declspec( dllexport ) BOOL __stdcall TestDll2( );
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.