Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

systemqq & winexec

Intel_C_Intel
Employee
607 Views
I need to open an Excel template from withing a quickwinprogram. I do this by supplying the file name only and letting the file association do it's job. If I use WinExec, it always warns of possible viruses and waits for a user response.
If I use systemqq, it goes to DOS briefly and then works fine without any warning. However,when the excel template is in a subdirectory of c:program files, systemqq doesn't likes the space in the name and it fails. In this case I can get it to work if I use changedir first, but then I've got more housekeeping to do, and I still have the brief flash to DOS. In the final release the template will typically reside in c:program filesmicrosiris, but installation choicescould put it elsewhere
Is the a cleaner way to make this work?
TIA,
Neal Van Eck
0 Kudos
7 Replies
Steven_L_Intel1
Employee
607 Views
ShellExecute is what you want.
0 Kudos
Intel_C_Intel
Employee
607 Views
Thanks! That works smoothly. However, I can't find a way to keep the focus on the Excel window so the spreadhseet can be filled. ShellExec returns immediately and my application asks for the file saved by excel, thereby putting the just opened (empty) in the background. Is there someway to force it to either wait or to stay in the foregorund?
0 Kudos
Jugoslav_Dujic
Valued Contributor II
607 Views

See ShellExecuteEx; after you call it, you can use WaitForSingleObject on SEI.hProcess (see docs). Note, however, that your application will appear to be non-responding while waiting for Excel to terminate.

Jugoslav

0 Kudos
Intel_C_Intel
Employee
607 Views

Thanks, but I'm struggling with this. I can't seem to use this without defining shellinfoexec, and when I do, it complains it doesn't match the dummy argument. I'm probably not undertanding the structure definition properly anyway, not being a C programmer. No includesor use statments seem to help.

Any further clues would be greatly appreciated.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
607 Views

Quick sketch:

USE DFWIN
type (T_SHELLEXECUTEINFO):: SEI !CVF api translations have T_ prefix

SEI%cbSize = SIZEOF(SEI)
SEI%fMask = SEE_MASK_NOCLOSEPROCESS
SEI%lpVerb = NULL ! = open
SEI%lpFile = LOC("whatever.xls")C !LP*STR's in TYPEs require LOC

IF (ShellExecuteEx(SEI) .EQ.0) THEN
iErr = GetLastError()
ELSE
i = WaitForSingleObject(SEI%hProcess, INFINITE)
i = CloseHandle(SEI%hProcess)
END IF

HTH

Jugoslav

0 Kudos
Intel_C_Intel
Employee
607 Views
Works beutifully! Thanks a million
Neal
0 Kudos
Intel_C_Intel
Employee
607 Views
Although the method works fine, it's a little slow to load excel, and takes about 5 or more seconds to return after closing excel, compared to runqq which snaps it in and out without delay. Is this typical behavior for shellexecex or do I have some other problem? Perhaps it waits for buffers to flush, etc?
0 Kudos
Reply