Spotnick2
September 10th, 1999, 11:25 AM
I'm doing a little software that change the default printer to pdf writer, PRINTS and then change back to the normal default printer.
It does work, but I'm using ShellExecute to print, the problem is, the time the ShellExecute is launched, the default printer is set back to the original and it prints to the original...
Is there a known way to run a shellexecute modal? I can't put a timer, depending on the document, it could be long or not.. idea would be to scan the directory where I'm writing the PDF file, but that is not a very good way to process.
Any ideas?
Thanks.
---
Nicolas LeBlanc
Software Engineer
Ordiplan Inc.
trier
September 10th, 1999, 01:10 PM
The following function might be of assistance to you (?). I use it to control processes running stored procedures in SQL Server. For example, sp B might have a dependency on sp A..so I wait until sp A is completely done running before calling sp B. I don't know if this is going to help...
<vbcode>
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
'=========================================================================
' ExecCmd - runs command line processes (*.exe's and stored procedures).
'=========================================================================
Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'------------------------------------------
' [1] Initialize the STARTUPINFO structure:
'------------------------------------------
start.cb = Len(start)
'------------------------------------------
' [2] Start the shelled application:
'------------------------------------------
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'------------------------------------------
' [3] Wait for the shelled application to finish:
'------------------------------------------
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
</vbcode>
Lothar Haensler
September 13th, 1999, 02:00 AM
you can use parts of the code published by "trier" by using the ShellExecuteEx function. It fills a structure. One of the elements is the hProcess of the started process.
Use that for waiting via WaitForSingleObject.
Hi techies,
Do Anybody know how can I access pdfwriter libraries programmatically so that I can convert anyfile(excel, doc,...) to PDF. Iam working in VC++ MFC.
Your Idea is appreciated.
Thanx
venu.