Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GhostScript gsdll32.Dll
Message
 
To
19/10/2015 10:26:38
Marcus Hüneke
Heidelberger Druckmaschinen
Wiesloch, Germany
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01626155
Message ID:
01626404
Views:
100
You'd be much better of creating a Win32 wrapper DLL for this code, than trying to do this all using API calls. Arrays are a bitch to get right.

I wrote a post a long time ago with the C++ code to do this:

http://weblog.west-wind.com/posts/2005/Mar/16/A-simple-GhostScript-PS-to-PDF-C-DLL-wrapper

This is also part of wwIPStuff.dll - in case you use any West Wind tools.

+++ Rick ---

>Hello,
>
>Here the whole question with sourcecode (Works until gsapi_init_with_args is called)
>
>My issue is to convert a pdf-File (one or more pages) into single TIF-Files. So a PDF File with 3 Pages leads to 3 TIF Files.
>I have found Ghostscript on the web and with the EXE (gswin32c) and some Parameters it works.
>The disadvantage of this method is that I don't get any Feedback if the procedure came to an end (PDF File with 100 Pages)
>
>So now I try to use the gsdll32.Dll of Ghostscript. But everytime I try to pass the char * [] to the function I get an error.
>
>Does anyone know how to pass the Parameter Array to the "gsapi_init_with_args " - FUNCTION.
>
>
>Any help is appreciated - Thanks in advance
>
>
>Marcus
>
>
>This is so far what I have:
>
>***********************************************************************************************************
>
>
>Clear All
>
>Set Default To c:\foxpro9\ppdauto
>
>*ghostscript must be called in this row
>
>*!*	1.gsapi_new_instance
>*!*	2.gsapi_init_with_args
>*!*	3.gsapi_exit
>*!*	4.gsapi_delete_instance
>
>Declare Long gsapi_new_instance In gsdll32.Dll Long @, Long
>Declare Long gsapi_delete_instance In gsdll32.Dll Long
>Declare Long gsapi_init_with_args In gsdll32.Dll Long, Long, Long
>Declare Long gsapi_exit In gsdll32.Dll Long
>
>
>Store 0 To lnGsinstancehandle, lnCallerhandle, lnElementcount, lnCounter, lnReturn, lnGsinstancehandle, params, lhMemory
>
>lnReturn = gsapi_new_instance(@lnGsinstancehandle,@lnCallerhandle)
>
>If lnReturn  = 0  && Succsess
>	tcFileout =  "-tiffg4-%03d.tif"
>	tcFilein = "new.pdf"
>
>
>	Dimension laArgs[6]
>	laArgs[1] = "dummy"
>	laArgs[2] = "-dBATCH"
>	laArgs[3] = "-r"+"600X600"
>	laArgs[4] = "-sDEVICE=tiffg4"
>	laArgs[5] = "-sOutputFile="+tcFileout
>	laArgs[6] = tcFilein
>
>
>
>	lnPtr = VFP2BinArray(@laArgs,@params,@lhMemory)
>    
>    
>    
>    lnReturn = gsapi_init_with_args(lnGsinstancehandle,lnPtr,params)
>    
>    
>    
>    SET STEP on
>    
>    
>    
>  *  WAIT WINDOW lnPtr
>     
>    
>
>	
>
>
>*  WAIT WINDOW lnreturn
>	gsapi_exit(lnGsinstancehandle)
>	gsapi_delete_instance(lnGsinstancehandle)
>
>    LocalFree(lhMemory)
>
>
>
>Endif
>
>
>
>
>
>Wait Window lnReturn
>
>
>Function VFP2BinArray(taData, tqBinArray, thMem)
>*****************************************************
>** Converts a VFP array of strings into an array of string pointers for
>** for passing to API functions
>**
>** Parameter:
>**  taData - The array of VFP strings, passed by reference
>**  tqBinArray - (out)The array of pointers, in VarBinary format to pass
>**         to the API function, passed by reference
>**  thMem - (out)The memory buffer to hold the string values, passed by
>**         reference. This memory must be freed manually using the
>**         LocalFree API function.
>**
>** Returns: Numeric - the number of strings placed into the binary array
>*****************************************************
>
>Local lhBuffer, lhPos
>Local lqBinArray, lnArrayCnt
>Local lnDataLen
>Declare Long LocalAlloc In WIN32API Long uFlags, Long uBytes
>Declare Long LocalFree In WIN32API Long Hmem
>
>lnArrayCnt = 0
>lqBinArray = 0h
>
>Try
>** Get the total length for the character data
>	lnDataLen = 0
>	For lnLoop = 1 To Alen(taData)
>** Add 1 byte to each string length for the NULL terminator
>		lnDataLen = lnDataLen + Len(taData[lnLoop])+1
>	Endfor
>
>** Allocate memory buffer
>	lhBuffer = LocalAlloc(0x0040,lnDataLen)
>
>** Stuff character data into buffer
>	lhPos = lhBuffer
>	For lnLoop = 1 To Alen(taData)
>** Stuff string into buffered memory
>		Sys(2600, lhPos, Len(taData[lnLoop])+1, taData[lnLoop]+Chr(0))
>** Add position to binary array
>		lqBinArray = lqBinArray + BinToC(lhPos,"4rs")
>** Increase our position pointer
>		lhPos = lhPos + Len(taData[lnLoop])+1
>** Increase Array count
>		lnArrayCnt = lnArrayCnt + 1
>	Endfor
>Catch To loExc
>	Throw
>Finally
>	If lnArrayCnt > 0
>		tqBinArray = lqBinArray
>		thMem = lhBuffer
>	Else
>		If lhBuffer <> 0
>			LocalFree(lhBuffer)
>		Endif
>	Endif
>Endtry
>
>Return lnArrayCnt
>
>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Reply
Map
View

Click here to load this message in the networking platform