0

I try to import functions from a NetWeaver.dll in c++.

One of the declarations is:

DECL_EXP RFC_CONNECTION_HANDLE SAP_API RfcOpenConnection(RFC_CONNECTION_PARAMETER const * connectionParams, unsigned paramCount, RFC_ERROR_INFO* errorInfo);

My first attempt was:

DECL_EXP RFC_CONNECTION_HANDLE SAP_API (*RfcOpenConnectionImp) (RFC_CONNECTION_PARAMETER const*, unsigned, RFC_ERROR_INFO *) = (DECL_EXP RFC_CONNECTION_HANDLE SAP_API(*) (RFC_CONNECTION_PARAMETER const*, unsigned, RFC_ERROR_INFO*)) GetProcAddress(hinstLib, "RfcOpenConnection");

but following error occured:

"Auf eine Aufrufkonvention darf kein geschachtelter Deklarator folgen." Means something like: "After a calling convention a nested declarator is not allowed."

So I tried some variations until the compiler was satisfied with:

RFC_CONNECTION_HANDLE (*RfcOpenConnectionImp) (RFC_CONNECTION_PARAMETER const*, unsigned, RFC_ERROR_INFO *) = (RFC_CONNECTION_HANDLE (*) (RFC_CONNECTION_PARAMETER const*, unsigned, RFC_ERROR_INFO*)) GetProcAddress(hinstLib, "RfcOpenConnection");

so it compilled an throwed a error during runtime:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Well, not really surprising...

But how do I import this kind of function the correctly?

Thanks for help!

Tagamoga
  • 332
  • 4
  • 18
  • `RFC_CONNECTION_HANDLE (SAP_API *RfcOpenConnectionImp)(...)` might work. https://stackoverflow.com/questions/4830355/function-pointer-and-calling-convention – Retired Ninja Sep 01 '21 at 02:32
  • 1
    It works! Thank you very much! Do you like to post a answer, so I can rate it. – Tagamoga Sep 01 '21 at 03:01
  • Does this answer your question? [Function pointer and calling convention](https://stackoverflow.com/questions/4830355/function-pointer-and-calling-convention) – Retired Ninja Sep 01 '21 at 03:04

0 Answers0