-
November 29th, 2012, 01:17 PM
#1
launching current version of IE to view an HTML file, from a VCC program
I tried to do this with _spawnl(), but first of all I'm not sure how to properly ask for the path to iexplore.exe, as I'm sure it will change every time MS gets a whim to move it. I know there's a GetWindowsDirectory() call, but that's not where IE resides (its in "C:\Program Files\Internet Explorer\iexplore.exe" in XP, Lord know where on win 7 or 8).
Also, even temporarily hard coding the path to make it launch with spawnl(), I can't seem to get my html document to display. I know the path to that is right (since I put it there ).
char * pFile = "someFile.htm";
char * pCmd = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
int res = _spawnl(_P_NOWAIT, pCmd,pCmd, pFile, NULL); // also tried without specifying pCmd 2x
if (res == -1) MessageBox("Sorry... can\'t Open File.");
So my second question would be, how to you PROPERLY pass the file to view as an argument.
thanks for any help!
-
November 29th, 2012, 02:09 PM
#2
Re: launching current version of IE to view an HTML file, from a VCC program
Well, how many times are you going to launch the same question to this Forum?
If you are just a spammer or you're just trolling then you"ll be banned here forever.
If instead you need some real help then please, read Announcement: Before you post....
Victor Nijegorodov
-
November 29th, 2012, 03:48 PM
#3
Re: launching current version of IE to view an HTML file, from a VCC program
Hey victor, from the content of my actual question it ought to be obvious that I'm not spamming. It was a coding question, not an attempt to sell hot Russian brides.
More to the point, as user of this forum I'm sure you're experienced enough to know that computers can play tricks on all of us. For some reason my browser kept stalling today when I tried to make the post, and I was just trying to get it through once. When I realized that it had been posted multiple times, I did my best to delete the repeats. But for whatever reason, the forum only allows you to edit posts (and you have to give a reason), but does not seem to allow deletes.
I apologize for the inconvenience you've been caused. But please don't judge so quickly. We all hate spam.
-
November 29th, 2012, 05:12 PM
#4
Re: launching current version of IE to view an HTML file, from a VCC program
Wel, OK!
Only moderators can delete the Original Post.
And I admit that Forum worked very slowly in the past four hours.
But it does not mean you would post the same question again and again unless you had verified that you previous post had failed.
Victor Nijegorodov
-
November 30th, 2012, 01:40 AM
#5
Re: launching current version of IE to view an HTML file, from a VCC program
Originally Posted by VictorN
Wel, OK!
Only moderators can delete the Original Post.
[...]
Done.
-
November 30th, 2012, 01:54 AM
#6
Re: launching current version of IE to view an HTML file, from a VCC program
Code:
#include <windows.h>
#include <process.h>
#include <direct.h>
int main()
{
char * pFile = __argv[1];
char fullPath[MAX_PATH] = {0};
char* pos = strchr(pFile, ':');
if (NULL == pos)
{
_getcwd(fullPath, sizeof(fullPath));
strncat(fullPath, "\\", sizeof(fullPath));
strncat(fullPath, pFile, sizeof(fullPath));
pFile = fullPath;
}
char* pCmd = "%PROGRAMFILES%\\Internet Explorer\\iexplore.exe";
char iePath[MAX_PATH] = {0};
ExpandEnvironmentStrings(pCmd, iePath, sizeof(iePath)); // or try to use getenv :)
int res = _spawnl(_P_NOWAIT, iePath, pFile, pFile, NULL);
if (res == -1)
MessageBox(NULL, "Sorry... can\'t Open File.", "Oops!", MB_OK);
return 0;
}
Best regards,
Igor
-
November 30th, 2012, 10:37 AM
#7
Re: launching current version of IE to view an HTML file, from a VCC program
Thanks Igor!
The only problem with that was when I'm working in Vstudio, that becomes the path returned with getcwd(). This (below) seemed to work too, so I guess this confirms I can count on iexplore being in that same place always. But now you've go me thinking about the spawn parameters, because I couldn't get it to work passing the file/path twice, and it seemed to like my passing _T("file:\\") for the first arg, followed by the actual path string buffer. But hoestly, thatwas just a guess that worked, and just because something works on my system doesn't always make it "right".
char pFile[MAX_PATH];
TCHAR pCmd[MAX_PATH];
TCHAR * pEnv = _tgetenv(_T("ProgramFiles"));
_tcscpy(pCmd, pEnv);
_tcscat(pCmd, _T("\\Internet Explorer\\iexplore.exe"));
// help path is ALWAYS one dir up from my executable
strcpy(pFile, AfxGetApp()->m_pszHelpFilePath);
for ( i = strlen(pFile) - 1; i; i--) if (pFile[i] == '\\') break; // strip it off.
pFile[i++] = '\\'; // make sure theres a delimiter (paranoid)
strcpy(&pFile[i], "myHtmlFile.htm");
int res = _spawnl(_P_NOWAIT, pCmd, _T("file:\\"), _T(pFile), NULL);
if (res == -1) MessageBox("Sorry... can not Open User Guide.");
-
December 1st, 2012, 03:18 AM
#8
Re: launching current version of IE to view an HTML file, from a VCC program
My code works just fine in both Windows XP and 7. I'm not sure how "file:\\" actually acts there down in the abyss of _spawnl, but it really works in my case too. You can find it yourself in your debugger why IE path does not work when the absurd path really does the trick. I noticed that your original code resulted in passing pCmd to IE as address string, that's why I used pFile instead.
As for getcwd. Of course I didn't run it in VS, but if you do, you need to know that in that case current directory is your project directory. There the file must be placed to work with getcwd.
Best regards,
Igor
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|