cyocum has asked for the wisdom of the Perl Monks concerning the following question:

I humbly ask the Monks for their sage advice.

Well, I have a project that requires me to: parse a PDF file, add some content inside the file, then out put the file for viewing on a browser that has Adobe Acrobat reader installed. I searched the net. I found the great pdflib library but found out that it would cost me $1000 to get a licence for their PDI library that would allow me to parse the PDF then manipluate it. So, I searched some more. I found Panda PDF project that seemed to fit the bill. I downloaded the source then compiled into a Windows DLL since that is the system that I am using. I was going to use ActivePerl's Win32::API to call into the dll to access the functions and allow me to complete this project.

At first, it seemed to work. I needed to call a function that takes two char *. I read the manual for Win32::API. I found out that you need to pack the variables to pass into the function if they are pointers. Here is some sample code to show you what I mean:

use Win32::API; $panda_init = Win32::API->new("c:\\temp\\panda", "panda_init", [], V); $panda_init->Call(); $panda_open = Win32::API->new("c:\\temp\\panda", "panda_open", [P, P], P); $filename = pack("p", "dd.pdf"); $mode = pack("p", "w"); $panda_open->Call($filename, $mode);

When I did this it returned "Unknown file mode handed to panda." Now I looked in the docs and the source. The only supported file mode right now is "w". Although, it always returns this error no matter what character I pack.

Does anyone have experience with Win32::API enough to give me some clues? It is probably my pack but I cannot be sure. I am about to go hack the code to see what the function thinks it is receiving but I wanted to know if anyone has encountered this before I start.

Many many thanks in advance!

Replies are listed 'Best First'.
(tye)Re: Pack and Win32::API
by tye (Sage) on Mar 17, 2002 at 23:16 UTC

    For pointers to simple '\0'-terminated strings, use an argument type of "P" and just pass the string in directly.

    If you wanted pointers to anything else, then you'd have to use pack and an argument type of "N".

            - tye (but my friends call me "Tye")

      Tried it. No joy.

Re: Pack and Win32::API
by cyocum (Curate) on Mar 27, 2002 at 13:04 UTC

    Well, for those of you watching at home. I have tried to figure out what Panda is getting on the other side of the code divide. So I added printf statements to print out the stuff I was sending in. Come to find out, if I pass a packed scalar with the "P" template, printf freaks out and causes an access violation trying to print out what I sent in. If I try to send in straight strings, it also causes an access violation. I have tried many other cominations of pack templates. Some just return (null) when printed out. Others cause access violations. I believe that I am completely missing some point here but I do not know what it is. *sigh* My search for an answer continues