I am trying to call some Win32API external functions in kernel32.dll from within SQL Anywhere 12.0.1 database server. Everything works well on 32-bit Windows (XP and 7), but nothing works on 64-bit Windows (7 and 8).
When I declare a function WITHOUT the LANGUAGE clause on 32-bit Windows, the function executes normally. When I do the same on 64-bit Windows I get the following error message:
When I declare a function WITH the LANGUAGE clause (C___ESQL32 or C_ESQL64) the error message disappears, the function seems to execute, but "does nothing". I can't get any return value or OUT arguments, everything is NULL. Executing functions in the external context (with the LANGUAGE clause) doesn't work at all, even on 32-bit Windows.
I have installed the latest EBF, tried with database engine and server, disabled antivirus and firewall - nothing helps. I have tried several Win32API functions: GetVersion, GetCurrentDirectoryA, GetVolumeInformationA, MessageBoxA, ... but here is the simplest example with a function that has no arguments:
create function SFGetVersion ( ) returns integer external name 'GetVersion@kernel32.dll' language C_ESQL32 (or C_ESQL64 for 64-bit Win); select SFGetVersion();
Where do I make mistake? Could anyone manage to get this function execute successfully in any context on 32-bit and 64-bit Windows? Is it possible at all to call Win32API functions from within SQL Anywhere server (I suppose it is - it works on 32-bit Win)?
Any help would be welcome. Thanks!
asked 20 Feb '13, 14:47
When calling an external function on Win64 you must use the "new" External Function API (new is relative since it has existed since v7). The "old" API is still allowed when using the 32bit server but its use is discouraged (it has not been updated since the new API was created).
In your particular case, the external DLL is missing the extfn_use_new_api() function and therefore the server thinks (correctly) that you are using the old API and it is not supported on 64bit platforms.
http://sqlanywhere.blogspot.ca/2008/11/refactoring-foxhound-series.html Refactoring Foxhound: The Series
http://sqlanywhere.blogspot.ca/2009/02/get-mac-addresses-via-sql.html Get MAC Addresses Via SQL
http://sqlanywhere.blogspot.ca/2011/02/loading-32-bit-versus-64-bit-dlls.html Loading 32-bit Versus 64-bit DLLs
http://sqlanywhere.blogspot.ca/2011/02/loading-32-bit-versus-64-bit-dlls_16.html Loading 32-bit Versus 64-bit DLLs [revisited]
http://sqlanywhere.blogspot.ca/2012/12/calling-getopenfilename-from-sql.html Calling GetOpenFileName() From SQL
answered 20 Feb '13, 16:18