in reply to Re^4: WIN32::API and void*
in thread WIN32::API and void*
You probably leaked a table. Do doing the Call() means you run the C function and the defined check is meaningless since the result will be 0 (probably NULL pointer/failure for the C function) or a pointer (12345 format), never undefined. Check defined only on $CreateTable API obj. I posted code from a test suite of Win32::API, you need to change it a little bit more.$pass = $pass && defined($CreateTable->Call()) == 1;
Correct, try printing $aTable to the screen, I prefer Data::Dumper.$aTable = $CreateTable->Call(); print("Table Created");
$aTable should be a decimal number, 123456 style. "HANDLER" isn't a C or Win32 API type. Its "HANDLE". If you tried HANDLER you should be getting warnings printed to console, but I'm not sure if 0.68 will report unknown types or not.use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper($aTable);
About the whole packing and unpacking of the handlers before passing them out, I'm not sure whether I should pack $aTable or not. I understand that because it's the value returned by an API function, $aTable should already be stored with the appropiate format (unless there is any transformation behind the scenes before perl stores its value)."appropiate format", no its not. Thats why 0.68 sucks.
I have packed the string with the file path since in the header files it's advised that the string containing the filename has to be null terminated (I've checked http://perldoc.perl.org/functions/pack.html and sounds like a pack('Z', string) to me).Useless, all scalar strings in perl are automatically null terminated at all times secretly so they can be passed to OS/library C function that want null terminated (even if you feed binary garbage to the C function, the C function will hit a null in your binary garbage, or hit the secret null, either way, it will never buffer overflow. This is a ansi/ascii null, not a UTF16 null, if your doing UTF16 in perl, you need to write "\x00\x00" yourself. The secret null character never appears in the perl language, so if you put the scalar to disk, or through a network, then you need to add the null yourself with pack or
.= "\x00";
Something isn't right since I get a "Segmentation fault (core dumped)" error. Which means I'm not passigng the correct arg for LPHANDLER raw_result. I've tried to "$aTable=pack('J',$aTable);" before passing it to myTableLoadfromFile, but I still get the same error. Any idea what I'm missing?The pack J is what your missing. After you pack $aTable, do a print Dumper on it, it should be 4 or character, some of the characters might be in "\123" octal escape sequence since they are unprintable binary. You can also try
you can also scrap the C prototype interface of Win32 API and use the letter interface.$packedaTable = pack('J', $aTable); die "bad code" if unpack('J', $packedaTable) != $aTable;
becomesmy $LoadTableFromFile = new Win32::API("myDll.dll","int myTableLoadFro +mFile(char* filename, LPHANDLE raw_result)");
Final question, are you on 32 bits or 64 bit windows and what is the calling convention of your C functions? I think you have cdecl functions, since a no parameter stdcall and a no parameter cdecl are interchangable and identical under the hood, so whats might be why create doesn't crash, but myTableLoadFromFile does.my $LoadTableFromFile = new Win32::API("myDll.dll", "myTableLoadFromFi +le", 'PP', 'I');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: WIN32::API and void*
by sgv_81 (Novice) on Jul 25, 2012 at 18:52 UTC | |
by bulk88 (Priest) on Jul 25, 2012 at 20:52 UTC | |
by sgv_81 (Novice) on Jul 26, 2012 at 08:31 UTC | |
by bulk88 (Priest) on Jul 26, 2012 at 16:55 UTC | |
by sgv_81 (Novice) on Jul 26, 2012 at 17:34 UTC | |
|