I am attempting to call a C++ DLL from Excel-VBA.
I know the DLL function is being executed as I inserted fputs() logging calls to track execution and the stamps are showing up in my log file. The problem is, whenever the DLL function returns, I get Error 49.
Here is the declaration in VBA:
Private Declare Function InitMCR Lib "MCRBoilerplate.dll" Alias "?initMCR@@YGXXZ" ()
and here is the declaration in C++
__declspec(dllexport) void __stdcall initMCR() { ... }
Why am I getting this Error 49 behavior, even though the DLL calls appear to be working?
In VBA, functions that return void
need to be declared as Sub
instead of Function
So the declaration in VBA should be:
Private Declare Sub InitMCR Lib "MCRBoilerplate.dll" Alias "?initMCR@@YGXXZ" ()
See MSDN page on VBA Declare statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With