dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: DLL to Launch Default Browser

  1. #1
    Join Date
    Dec 2010
    Posts
    9

    Question DLL to Launch Default Browser

    I need to implement a DLL that will take the parameter passed (SessionNumber) and add it to a web address, and then launch the default browser using that address.

    I'm having problems getting it to work correctly.

    Currently, I have:

    Code:
    namespace WebsiteLaunch
    {
        public class LaunchSite
        {
            public LaunchSite(ref string SessionNumber)
            {
                string SessionPassed = SessionNumber;
                string target = "https://www.website.com/sessionHandler.do?" + SessionPassed;
    
                try
                {
                    System.Diagnostics.Process.Start(target);
                    SessionNumber = "SUCCESS";
                }
                catch
                {
                    SessionNumber = "ERROR";
                }
            }
        }
    }
    The source compiles fine, but doesn't work successfully when called from another program.
    Last edited by mkswanson; January 19th, 2011 at 01:26 PM.

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: DLL to Launch Default Browser

    Hi MK.

    The first thought that comes to mind is "Is he appending the session number directly to the .com so that the url reads "https://www.website.com246" ?

    Shouldn't there be an intervening slash between the ".com" and the page you wish to visit (for instance, "https://www.website.com/246.htm"). Perhaps the argument INCLUDES the slash, in which case you're probably OK.

    two suggestions:
    1) determine what the actual url you're using is and try to reach that page from your browser, manually.

    2) run with the debugger and see which statement is dying and WHY it's dying (ie check out the exception assistant (if you're getting an exception - you don't mention what problem indications you're seeing))

    Also, have you tried the Process.Start method specifying both the process (in this case, the browser), and the URL to the browser as an argument ?

    Process.Start("IExplore.exe", "www.northwindtraders.com");

    I dunno ... just a thought.

  3. #3
    Join Date
    Dec 2010
    Posts
    9

    Re: DLL to Launch Default Browser

    Thank you. I added something extra to the site address. The string is actually quite a bit more complicated, but I'd expect the browser to launch and receive an address resolution error if the problem were my string.

    I would prefer to use the system's default browser, although I am willing to specify a particular browser if necessary.

    The error I'm getting is actually an exception from another program, but it is happening after it begins to execute this code. I was hoping there was something obvious in my code that I had wrong that a sharper (and smarter) set of eyes would identify.

  4. #4
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: DLL to Launch Default Browser

    According to the VS2010 documentation regarding the Process.Start(filenameString) method,
    "If the address of the executable file to start is a URL, the process is not started and NULL is returned".

    A similar note exists in the documentation for the Start (string filename, string argument) overload.

    It would be interesting to examine the value returned by the Start method you're using and see if it returns a process or NULL.

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: DLL to Launch Default Browser

    Try following code
    Code:
    Process process = new Process();
    process.StartInfo.FileName = "https://www.website.com/sessionHandler.do?" + SessionPassed;
    process.StartInfo.Verb = "open";                              
    process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    process.Start();
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)