Windows API in VBA compiler?

Hello @gdgsupport and all,
I was wondering if there’s a way to run windows API calls in the compiler (or some workaround to more easily conceal passwords in the vba compiler when connecting to something online via Windows API), such as ftp, online databases, etc?

If I try any Private Declare PtrSafe {someWinApiNameHere} … it gives an error.


Yes, it’s possible to invoke Windows API in the compiler. The main problem may come whether you have Excel 32-bit or 64-bit… But here is some guide:

function lib "libName.dll" [alias ExternalFunctionName] [callingConvention] functionName(arguments) as resultType;

For example, the following declaration:

function lib "CustomLib.dll" MyFunction(arg as integer) as integer

imports a function called MyFunction from CustomLib.dll. Default calling convention, if not specified, is stdcall. Scripter also allows to declare a different calling convention (stdcall, register, pascal, cdecl or safecall) and to use a different name for DLL function, like the following declaration:

function MessageBox lib "User32.dll" alias "MessageBoxA" stdcall (hwnd as pointer, text as string, caption as string, msgtype as integer) as integer

that imports ‘MessageBoxA’ function from User32.dll (Windows API library), named ‘MessageBox’ to be used in script.