CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 1999
    Location
    Tampa, FL
    Posts
    114

    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!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

  3. #3
    Join Date
    Apr 1999
    Location
    Tampa, FL
    Posts
    114

    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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: launching current version of IE to view an HTML file, from a VCC program

    Quote Originally Posted by VictorN View Post
    Wel, OK!
    Only moderators can delete the Original Post.
    [...]
    Done.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  7. #7
    Join Date
    Apr 1999
    Location
    Tampa, FL
    Posts
    114

    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.");


  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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
  •  





Click Here to Expand Forum to Full Width

Featured