the example I am playing with is more for me in gaining knowledge in working with windows API's
You're probably better off getting hold of a compiler (say, the freely available MinGW port of gcc) and using it and Inline::C to access the Windows API's. It's fairly trivial with Inline::C. The following script outputs 0:
use warnings;
use strict;
use Inline C => <<'EOC';
#include <sql.h>
int foo() {
SQLHENV henv = SQL_NULL_HENV;
return SQLAllocHandle(1, 0, &henv);
}
EOC
print foo();
Admittedly that doesn't do anything useful, but at least it returns a sane value and is nowhere near as obtuse as Win32::API.
I must confess that I've spent quite some time trying to get the Win32::API version to return a sane value ... and have failed miserably. Usually, when I can get the Inline::C rendition working, I can then get the Win32::API rendition to work correctly ... sadly, not tonight :-) I assume it's because I haven't found the correct way to deal with the 3rd argument, but I really don't know. Update: Nope ... looks like apl and Corion have picked up the scent, however. Update 2:Yep ... I just checked and the SQLRETURN type is a short ... and apparently Win32::API simply fills the other 2 bytes with garbage.
Cheers, Rob | [reply] [d/l] |
Thank you all for sharing your wisdom, I have gained knowledge :^)
I believe syphilis is correct in Win32::API does not deal well with short data types.
So I took the suggestion and played around with InLine and now have another option for calling APIs:
use warnings;
use strict;
print "InLineC.pl Started:\n\n Now to Execute some C code:\n\n";
print " fnTest Returned: ".fnTest()."\n";
print "\n Back from the C Code\n\nInLineC.pl Finished.\n";
use Inline C => <<'END_C';
#include <sql.h>
int fnTest() {
SQLHENV env;
SQLRETURN ret;
ret = SQLAllocHandle(1, 0, &env);
return ret;
}
END_C
| [reply] [d/l] |