setting a switch with a dll

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

setting a switch with a dll

Post by kpassaur » Mon Mar 05, 2007 2:27 pm

I have a dll I would like to use. The author of it made it work with MS. Then we spoke about creating it with a switch that would change how the data was returned so that it would be more useful. Once created, it no longer worked with MS.

I told the author this, great guy - Adrain from Utility Warrior, and he debuged it again and said it had to be an error with MS.

The origional dll is used to create PDF's from Tiff Images

The new dll extracts text from a tiff image that was created with Microsoft's Document imaging and places it in a text file. When there was no switch, it would create one large text file. With the switch the user had a choice of a file with the same name as the tiff with a counter added for each page or the option of inserting user specified text at the end of each page. The dll will also embedd the text into a pdf making it text searchable. That portion still works.

This is the email from the developer:

Hi Keith,

I've made the changes which can be download from http://www.utilitywarrior.com/Image2PDF ... 86beta.zip

I've now added a string parameter to I2PDF_SaveTIFFOCRText() - the string can either be:

1. Empty, ie "", in which case the saving of the text is the same as it was before

2. Contain some additional inter-page text (up to 256 characters), eg "\n********** PAGE BREAK **********\n\n" where \n forces a new line to be output

3. Be "FilePerPage" in which case the text is output so that each page gets it's own text file, eg output-1.txt, output-2.txt, output-3.txt etc

I'll make a start on Bates numbering next week - although I envisage this taking a couple of weeks to complete - I'll keep you posted.

Have a good weekend.
Adrian



The script is as follows:

Let>newpdf=c:\temp\test.pdf
DeleteFile>c:\temp\test.pdf
DeleteFile>c:\temp\test.txt
Let>tiftoprocess=c:\temp\test.TIF

Let>Library=c:\temp\Image2PDF StdCall.dll
LibLoad>Library,crepdf
LibFunc>crepdf,I2PDF_License,result,**********************
LibFunc>crepdf,I2PDF_AddImage,result,%tiftoprocess%
LibFunc>crepdf,I2PDF_SetProducer,result,eDocFile
//LibFunc>crepdf,I2PDF_SetOutline,result,2,3
LibFunc>crepdf,I2PDF_SetPermissions,result,15
LibFunc>crepdf,I2PDF_SetDPI,result,0

LibFunc>crepdf,I2PDF_IncludeTIFFOCRText,result,
LibFunc>crepdf,I2PDF_SaveTIFFOCRText,result,
Let>errbuf=
Let>errbuf_SIZE=255
LibFunc>crepdf,I2PDF_MakePDF,result2,%newpdf%,0,errbuf,255
LibFree>crepdf

It worked on the older version that was created, the line
LibFunc>crepdf,I2PDF_SaveTIFFOCRText,result,
is what is causing the difficulty.

Any ideas on creating a work around?

I could use the older verison, however, what would happen in the future is that when a new dll comes out, I would not be able to combine the new feataures with the old. So it would be nice if I could make this work.

There are some samle images here

http://www.edocfile.com/downloads/sampl ... %20abe.zip

If someone wants to give it a go, maybe its just me, would not be the first time I am missing something simple.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 06, 2007 7:46 am

Do this:

Let>s=
Let>s_LENGTH=0
LibFunc>crepdf,I2PDF_SaveTIFFOCRText,result,s

Works for me.

If you send a value:

Let>s=Page Break\n
Let>s_LENGTH=12
LibFunc>crepdf,I2PDF_SaveTIFFOCRText,result,s
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

String length being passed to DLL

Post by kpassaur » Tue Mar 06, 2007 8:46 am

First, Thank you it works great.

I know you are busy, but if you get a chance could you explain why it now works. I never noticed the varialbe_LENGTH= before.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Mar 06, 2007 9:11 am

variable_LENGTH is explained in the help file.

You have to understand that there is no such thing as passing a string to a DLL. You actually pass a PCHAR, which means Pointer to CHAR. This is a pointer to a memory location storing the actual string. The PCHAR is effectively the beginning of the memory location. So it is often important to tell the DLL what the size of this buffer is, so that it doesn't try to read too much memory. The memory beyond the end of the string might not belong to you.

And in this case your DLL looks at that pchar value and looks at the size of it. If it is zero length it does one thing. If it is larger than zero length it does another. So in this case you need to set the length. So we create a variable and set it to nothing and make sure the DLL knows it is of length zero bytes.

Most of the time when sending a string that does not get modified and when that string's size is obvious, you don't need to do this. With an empty string and where the DLL checks for zero bytes it would be safest to tell it is zero bytes!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts