Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute, open with dialog, and win2k 1

Status
Not open for further replies.

crjones42

Programmer
Mar 2, 2001
4
US
Hi--
How do I call the "open with" dialog in 2000????
I've been using the following code to open a text file with unusual extension for viewing or call the "open with" dialog if user has not registered a favorite viewer/editor:
Code:
if(int(ShellExecute(m_hWnd,"open",g_awhost_copy,NULL,
                    NULL,SW_SHOWNORMAL))==SE_ERR_NOASSOC)
   ShellExecute(m_hWnd,"openas",g_awhost_copy,NULL,
                NULL,SW_SHOWNORMAL);
"openas" isn't documented by MS but it did work until QA upgraded to windows 2000, and now nothing happens if the type isn't registered. I've also tried the version where "open" is used with filename replaced by:

rundll32.exe shell32.dll,OpenAs_RunDLL <<FILENAME>>

which I got from several other sources including a thread here, and again nothing happens. The first example returns SE_ERR_NOASSOC and the second returns ERROR_FILE_NOT_FOUND even though rundll32 and shell32 directories are in PATH and FILENAME (full path btw) exists...
Any idea?
 
hi,
please try
<b>
WinExec(&quot;rundll32.exe shell32.dll,OpenAs_RunDLL filepath_filename&quot;,SW_SHOWDEFAULT);
</b>

good luck!
 
Noluck with WinExec, concatenated my filepath and name onto rundll32.exe shell32.dll,OpenAs_RunDLL as a CString, returns ERROR_BAD_FORMAT. I've written my own version with standard open dialog which lets user select .exe directly, it's just nicer and more consistent to use the open with...
 
hi,
Wow! Why¡¢Where did you use &quot;CString&quot;?
The following code really works on my Window2000 Server.


char buf[200];
strcpy(buf,&quot;rundll32.exe shell32.dll,OpenAs_RunDLL &quot;);
strcat(buf,&quot;c:\\winzip.gol&quot;);
WinExec(buf,SW_SHOWDEFAULT);


Hope so do the trick in your case.
 
Ok, great that works!!!! But I don't know why... To quote the MSDN library, &quot;You can freely substitute CString objects for const char* and LPCTSTR function arguments.&quot; My filename was already a CString, so I set a temp CString equal to the RunDLL command (cut-and-pasted from above so I'd get it right including the space), did tempstring+=filename, then passed the whole thing to WinExec and as far as I can see it was the same string I just passed as char!?!?!?!
*****THANK YOU*********
 
status--Works with CString, evidently I did something wrong the first time. Used dumpbin and curiously there is no &quot;open&quot; function that I see in shell32.dll, so I'm using the original ShellExecute version and then calling WinExec if error ==SE_NO_ASSOC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top