Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling ghostscript dll from vfp 7
Message
From
08/05/2002 16:52:27
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Calling ghostscript dll from vfp 7
Miscellaneous
Thread ID:
00654238
Message ID:
00654238
Views:
370
I need to call a free pdf creator, Ghostscript (www.ghostscript.com) dll
from VFP 7 to create pdf files.
This dll function require a array of pointers to strings as parameters.
I have the VB sample code above.
How to convert this to VFP 7 ?
Public Function CallGS(ByRef astrGSArgs() As String) As Boolean
    Dim intReturn As Long
    Dim intGSInstanceHandle As Long
    Dim aAnsiArgs() As String
    Dim aPtrArgs() As Long
    Dim intCounter As Long
    Dim intElementCount As Long
    Dim iTemp As Long
    Dim callerHandle As Long
    Dim ptrArgs As Long

* Load Ghostscript and get the instance handle
Private Declare Function gsapi_new_instance Lib "gsdll32.dll" (ByRef lngGSInstance As Long, ByVal lngCallerHandle As Long) As Long
    intReturn = gsapi_new_instance(intGSInstanceHandle, callerHandle)

If (intReturn >= 0) Then
* Convert the Unicode strings to null terminated ANSI byte arrays
* then get pointers to the byte arrays.
        intElementCount = UBound(astrGSArgs)
        ReDim aAnsiArgs(intElementCount)
        ReDim aPtrArgs(intElementCount)
       
        For intCounter = 0 To intElementCount
            aAnsiArgs(intCounter) = StrConv(astrGSArgs(intCounter), vbFromUnicode)
            aPtrArgs(intCounter) = StrPtr(aAnsiArgs(intCounter))
        Next
        ptrArgs = VarPtr(aPtrArgs(0))

Private Declare Function gsapi_init_with_args Lib "gsdll32.dll" (ByVal lngGSInstance As Long, ByVal lngArgumentCount As Long, ByVal lngArguments As Long) As Long
      
        intReturn = gsapi_init_with_args(intGSInstanceHandle, intElementCount + 1, ptrArgs)

* Stop the Ghostscript interpreter
Private Declare Function gsapi_exit Lib "gsdll32.dll" (ByVal lngGSInstance As Long) As Long

        gsapi_exit (intGSInstanceHandle)
    End If
* release the Ghostscript instance handle
    gsapi_delete_instance (intGSInstanceHandle)
End Function

Private Function TestGS() As Boolean
Dim astrArgs(3) As String
astrArgs(0) = "gs" 'The First Parameter is Ignored
astrArgs(1) = "-dBATCH"
astrArgs(2) = "-c"
astrArgs(3) = "(Hello world) print"
TestGS = CallGS(astrArgs)
End Function


Sub Main()
Call TestGS
End Sub
Andrus
Next
Reply
Map
View

Click here to load this message in the networking platform