I have 64 bit windows 10 with MS Office 64 bit. I am trying to get the VBA for Powerpoint to load and execute a function in a self-written 64 bit windows DLL. To prevent export name mangling I have used extern C:
extern "C" {
__declspec(dllexport) long jaadd(long a, long b)
{
return a + b;
}
}
This simple function can be called by a C++ module with no problems:
hinstDLL = LoadLibrary(L"D:\\Visual Studio 2017\\Projects\\PopUpDLL\\x64\\Debug\\PopUpDLL.dll");
if (hinstDLL != NULL)
{
jaadd = (AddFunc)GetProcAddress(hinstDLL, "jaadd");
if (jaadd != NULL) {
result = jaadd(13, 40);
}
fFreeDLL = FreeLibrary(hinstDLL);
}
The problem arises when trying to call the DLL from VBA in Powerpoint. GetProcAddress always returns zero and so does FreeLibrary
Private Declare PtrSafe Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As LongLong
Private Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare PtrSafe Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private hLib As Long
Sub LLib()
hLib = LoadLibrary("D:\\Visual Studio 2017\\Projects\\PopUpDLL\\x64\\Debug\\PopUpDLL.dll")
MsgBox hLib
Dim pprocaddress As Long
pprocaddress = GetProcAddress(hLib, "jaadd") ***** always returns 0
MsgBox pprocaddress
xx = FreeLibrary(hLib) ***** always returns 0
MsgBox xx
End Sub
Any help gratefully received.