DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help opening default browser with basic coding

  1. #1
    Join Date
    May 2010
    Posts
    2

    Help opening default browser with basic coding

    Hello... im looking on making a basic exe to load 4 options, two of the options are to load to webpages in the default browser and i am having problems.

    first off, ive never C++ coded in my life
    and ive never properly coded before in my life

    i have Microsoft Visual C++ 2010 and i have compiled my basic menu successfully.

    now i want it to open up the default browser, so i am using this code snipet

    Code:
    #include <windows.h>
    #include <shellapi.h>
    #include <tchar.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
       ShellExecute(NULL, _T("open"), _T("http://dreamincode.net"),
                    NULL, NULL, SW_SHOWNORMAL);
    
       return 0;
    }
    ive placed it into my code and it looks like this:


    Code:
    #include<iostream>
    #include <windows.h>
    #include <shellapi.h>
    #include <tchar.h>
    
    using namespace std;
    
    int main()
    {
    	cout << "		   L14M333's & GuysUnderMeSuck's Patch Helper" << endl;
    	cout << "		   ==========================================" << endl;
    	cout << "			      www.se7ensins.com" << endl;
    	cout << "			      =================" << endl;
    	cout << "			     	    V1.5" << endl;
    	cout << "				    ====" << endl;
    	cout << "Coded by L14M333" << endl << endl << endl << endl;
    	cout << "Please ensure you have all the files from the .zip in the same folder" << endl <<endl <<endl;
    	cout << "Please enter <1> to load our post in your default internet browser" << endl;
    	cout << "Please enter <2> to check that you have the latest version of our patch" << endl;
    	cout << "Please enter <3> for the latest change list" << endl;
    	cout << "Please enter <4> for anything else" << endl << endl << endl;
    	int i;
        cout << "Please enter an option: ";
        cin >> i;
        cout << "You entered option " << i << endl;
    	if ( i == 1 )
    	{
    		cout << "Now loading post..." << endl <<endl;
    		int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
       ShellExecute(NULL, _T("open"), _T("http://dreamincode.net"),
                    NULL, NULL, SW_SHOWNORMAL);
    
       return 0;
    }
    	}
    	else if ( i == 2 ) 
    	{
    
    	}
    
    	system("pause");
    
    	return 0;
    }
    now when i run it i get these errors:

    error C2601: 'WinMain' : local function definitions are illegal
    c:\documents and settings\liam\desktop\patchhelper\patch helper\patch helper\main.cpp(27): this line contains a '{' which has not yet been matched

    so reading up i found out in these forums i think i need handles or something

    (sorry i havent got any knowledge in programing i just want to make this little project)

    can someone please help me out here



    Thanks in advanced




    Liam

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    winmain is MAIN in windows programming. I never cared for this junk, but thats how visual studio works when making a gui application and while you can hack and chop on it to force it to use the standard main() instead, its really not worth the time.

    So, put it back like it was where you had winmain as your main procedure, or fix it so that main is main (remove the function winmain that is now inside the new, normal main, thats the source of the first error).

    Basically you have

    int main()
    {
    int winmain() //local function not possible.
    {

    }
    }

    Note that in visual studio, and in most compilers, errors after the first one are so often a mess created BY the first error that its usually easier to fix the first problem and recompile to get new, unrelated errors until all are resolved. If you try to fix all the errors from one go, many will just keep pointing back to the first one, esp in a case like this where the local function totally unhinges the parser.

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    Forgot: If you try to make regular MAIN your main, you have to fool with the project settings to make it work -- somewhere deep in them is a setting to tell the compiler what function main is, you change that setting.

Similar Threads

  1. Replies: 3
    Last Post: 11-19-2008, 08:09 AM
  2. Access V Basic
    By JK in forum VB Classic
    Replies: 1
    Last Post: 04-02-2001, 09:04 AM
  3. Replies: 0
    Last Post: 09-13-2000, 10:18 AM
  4. Launch Default Web Browser
    By Abdulla Hussein Al-Adhal in forum VB Classic
    Replies: 0
    Last Post: 07-04-2000, 07:25 AM
  5. Replies: 2
    Last Post: 04-27-2000, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center