Well...I assume you meant that you do know the extension and want to find the corresponding application? Then, in this case 'ShellExecute()'/'ShellExecuteEx()' would be the simplest solution to open that file.
If you don't know the extension, then there is actually no assocation available...due to the missing extension.
So, I am sorry, but I still might not understand your actual problem...what are you trying to accomplish?
"Software is like sex, it's better when it's free." - Linus Torvalds
I apologize for not being clear. Posting with clarity is harder than it seems.
I have a filename provided by a user.
All I know for sure is that the file exists.
I want to open it with whatever application is associated with
this file and wait until that application is closed before proceeding.
If ShellExecute/Ex (or whatever I end up using) cannot find an
association, I tell the user that I can't open the file and carry on.
If I am able to open the file, I want to wait until that application
(whatever it is) is closed before continuing with my processing.
So, I've learned how ShellExecute/Ex can execute the associated
application for me, but I do not understand how to wait for
whatever application that was actually executed to finish
because I don't know how to get a (guaranteed) viable process
handle from ShellExecute/Ex.
And I don't know how to make use of CreateProcess in this
situation to get that viable handle.
Is there another API I can use, to the registry or somewhere, to
tell me, up front, what the file association is so I can use
You say "ShellExecute/Ex" but there are critical differences between ShellExecute and ShellExecuteEx in this context. ShellExecuteEx will accomplish what you need as much as is reasonably possible. In the SHELLEXECUTEINFO structure that ShellExecuteEx uses is hProcess, which can be used to wait for the process. There is a problem in situations where a single application is used for multiple filees, such as Internet Explorer, Word and Excel. I think there is a KB article describing the problem but I forget if there is a solution provided.
Originally posted by joleary
I have tried to familiarize myself with the basic concepts of DDE,
but I'm afraid I don't understand what you mean about
CreateProcess possibly being problematic when DDE is used.
Yes it probaly is difficult to find information about that unless you look at the registrations (associations?) for various file types. You will see that many file types use DDE to open them.
I am also having problems with createprocess and WaitForSingleObject.
The process launches documents (xls,doc,mpp,ppt) and then uses WaitForSingleObject, users can change the document and then save those changes.
The program works fine, unless documents of the same type are open (i.e. if am launching a word document and I have other word docs open WaitForSingleProcess returns 0 even though the document is still open)
I have used WaitForInputIdle but the process is initiated fine.
Do you have multiple instances of the app running as well?