0

I got a c++ demo that has successfully called the API written in c++, now am trying to call those API from excel VBA. I've done quite a bit research but still not able to link them together.

Basically there's a API(TapQuoteAPI.dll) export function like this in demo 'TapQuote.h

TAP_DLLEXPORT const TAPICHAR *TAP_CDECL GetTapQuoteAPIVersion();

in demo c++ solution(TapQuoteAPI_Demo), i include the 'TapQuote.h' in demo.cpp,

the cout<<GetTapQuoteAPIVersion()<<endl; is successfully called, and result is print.

but when it comes to call this function in excel vba, i keep failing.

I tried to directly use the TapQuoteAPI.dll in excel like this, but not working.

Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI.dll" () As String

Then I also try to build another dll function with a deFile.def from TapQuoteAPI_Demo.dll since i successfully call it within the c++ demo.

Declare Function GetTapQuoteAPIVersion Lib "D:\Proejct\WIN32\TapQuoteAPI_demo.dll" () As String

also failed. Could anyone shed some lights for me please?

  • Is `const TAPICHAR *TAP_CDECL` compatible with a type in VBA? (Almost a rhetorical question, you'll probably need to refactor to return a BSTR). – Bathsheba Oct 04 '18 at 14:49
  • thanks for the reply. am not very sure, the doc says TAPICHAR original type is char. how to refactor to BSTR pls? does it mean i need to write a cpp wrapper? – Chan Kenneth Oct 04 '18 at 15:01
  • Before you can declare the function in VBA, you need to see what `TAP_DLLEXPORT` and `TAPICHAR *TAP_CDECL` stand for and fully expand the C++ declaration. If the `__cdecl` convention is actually involved, you will need to create either an `__stdcall` wrapper [or a type library](https://stackoverflow.com/q/5195605/11683). – GSerg Oct 04 '18 at 16:01

0 Answers0