Open IE, go to URL, close

This is a discussion on Open IE, go to URL, close within the C++ Programming forums, part of the General Programming Boards category; Ok, so I need to write a very simple app and I thought I'd give it a go in C++. ...

  1. #1
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429

    Open IE, go to URL, close

    Ok, so I need to write a very simple app and I thought I'd give it a go in C++. One of our old applications is being phased out and I'd like to write a small app that does nothing but open IE and send them to a specific URL and then close it.

    And I'll just place this C++ app in the same place as the EXE that launches the old app.

    So my C++ skills are damn near nonexistent and my C knowledge has severly eroded, so can someone give me a jumpstart on how to open IE?

    I could do this in about 2 seconds in VB, but I'm trying to branch out. I looked through the FAQ real quick but didn't see anything that would help me.
    EntropySink. You know you have to click it.

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    this should help you out. I advise Shellexecute()
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    OK, I copied the Shellexecute() version and I get this error:

    fatal error C1010: unexpected end of file while looking for precompiled header directive
    Code:
    # include <windows.h>  //You need shell32.lib for this one 
    
    int main(void)
    {
      char szPath[] = "C:\\WINDOWS\\system32\\Calc.exe";
    
      HINSTANCE hRet = ShellExecute(
            HWND_DESKTOP, //Parent window
            "open",       //Operation to perform
            szPath,       //Path to program
            NULL,         //Parameters
            NULL,         //Default directory
            SW_SHOW);     //How to open
    
      /*
      The function returns a HINSTANCE (not really useful in this case)
      So therefore, to test its result, we cast it to a LONG.
      Any value over 32 represents success!
      */
    
      if((LONG)hRet <= 32)
      {
        MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
        return 1;
      }
    
      return 0;
    }
    EntropySink. You know you have to click it.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    Turn off precompiled headers (in the project properties) or add #include "stdafx.h" to the top of your cpp file.

    When you create your project make sure to find the Empty Project option in the new project wizard if you don't need precompiled headers.

  5. #5
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Ok, now I'm getting an error that it can't open "stdafx.h"
    EntropySink. You know you have to click it.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    I was assuming that if precompiled headers are turned on, it would have created stdafx.h for you. I'd suggest turning them off if you only want to make a small app (in Project Settings or Project Properties somewhere). They are for speeding up compilation when you have lots of source files that all include the same stuff. Make sure to remove the #include "stdafx.h" if you turn off precompiled headers.

    If you do keep them on, just create an empty stdafx.h and add it to your project. You'll probably also have to add stadfx.cpp that is empty except for including stdafx.h.

  7. #7
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Alright... now I get this error when I try to link it. It compiles fine:
    unresolved external symbol _WinMain@16
    I feel like an idiot that I can't even get this working. I'm so babied by VB.
    EntropySink. You know you have to click it.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Sounds like you created a Win32 Console project instead of a Win32 project

    Edit: Scratch that, I think I said it backwards...You probably created a Win32 project instead of a Win32 Console project (since the linker is looking for a WinMain function and you have a main function)
    Last edited by JaWiB; 04-07-2006 at 01:42 PM.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Nope, Win32 project, not console.
    EntropySink. You know you have to click it.

  10. #10
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Yeah I updated my post, sorry
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  11. #11
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    WTF I didn't know about HWND_DESKTOP and I've wanted to get the handle of the desktop a couple of times out of curiosity.
    Meh.

    EDIT: Scratch that, I just noticed it's defined as (HWND) 0. Silly me.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-27-2009, 12:46 PM
  2. Open Source and Security
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 06-17-2008, 01:23 AM
  3. Open Software License 3.0 Explained
    By laserlight in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-08-2008, 07:10 PM
  4. Problems with open and save boxes
    By pinkcheese in forum Windows Programming
    Replies: 3
    Last Post: 05-21-2002, 06:03 PM
  5. how do u open a folder?
    By nicola_diaz in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2001, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21