Resolved Problem with command line arguments

ExEdzy

Active member
Joined
Nov 25, 2010
Messages
37
Programming Experience
3-5
Hey guys.
So i'm making application that i want to use to view gif files in windows 7, because there is no viewer (i dont think internet explorer is a good choose..)
So everything seems to be ok..
I made the image, that is send to my application command line argument, to be opened in picturebox.. And it works when i drag gif image over my application shortcut or executable, but..

I wanted to add my app to default programs list, to open gif..
So i used registry, added this key:

HKEY_CLASSES_ROOT\giffile\shell\Open\command
in the default i set path to my application

My application opens with the file, but i get this error mesage:

1292100998.png



Help me please, whats the problem? :(
 
You don't "get" that error message. You "set" that error message. That message is coming from your code because something bad happened. You need to determine exactly what that bad thing was, not just display a generic error message. If you're catching an exception, use it. It provides all the available information about the bad thing that happened.
 
well, i use try to get the message, but i dont quite understand whats wrong.. here is my code:

VB.NET:
If My.Application.CommandLineArgs.Count = 0 Then
            Application.Exit()
        Else
            For Each item In My.Application.CommandLineArgs
                If IO.File.Exists(item) Then
                    Try
                        image_file = item
                        Dim image As Image = image.FromFile(image_file)
                        PictureBox.Image = image
                        Form2.Label1.Text = image_file

                        image_size = image.Size
                        Me.Size = image.Size


                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
                    Exit Sub
                Else
                    Application.Exit()
                End If
            Next
        End If
 
Last edited:
The error message is a DDE error from Windows. Most likely because you changed the registry manually and didn't get everything right. Gif files has a ddeexec configuration by default, and your application does not handle this. Try to let Windows set up the file association for you, for example right click a .gif file, there should be an option for 'open with' or similar where you browse to the application and choose this as default, Vista and W7 also has a 'Default Programs' in Start Menu and in Control Panel for this.
 
Hey again.

so i found this article:

File Association in VB.NET - CodeProject

and i modified my code to this:

VB.NET:
 Dim RegFolder As String = "giffile\\shell\\Open\\command"
        If CheckBox1.Checked = True Then
            Dim regKey As RegistryKey
            regKey = Registry.ClassesRoot.OpenSubKey(RegFolder, True)
            regKey.SetValue("", Application.ExecutablePath & _
 " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
            regKey.Close()
        Else
            Dim regKey As RegistryKey
            regKey = Registry.ClassesRoot.OpenSubKey(RegFolder, True)
            regKey.SetValue("", "C:\Program Files\Internet Explorer\iexplore.exe")
            regKey.Close()
        End If


and when i double-click on gif file it opens my application, and picturebox shows the gif animation, BUT I STILL GET THAT DAMN ERROR...

P.S. i removed "try" to dont show the message.. but still..

mlq8eavl6yuiv042ai4.png
 
Hey guys i figured it out.. searched the registry and found the reg key, that i need to add, to set my application as default to view gif files..

So here it is:

VB.NET:
        Dim AppName As String = Process.GetCurrentProcess.MainModule.ModuleName
        Dim RegFolder1 As String = "Software\Classes\Applications\" + AppName + "\shell\open\command"

        If CheckBox1.Checked = True Then
            Dim regKey As RegistryKey
            regKey = Registry.CurrentUser.CreateSubKey(RegFolder1)
            regKey = Registry.CurrentUser.OpenSubKey(RegFolder1, True)
            regKey.SetValue("", FullAppPath & " """ & "%1")
            regKey.Close()
            MsgBox("Applcation and settings saved")
        Else
            Dim regKey As RegistryKey
            regKey = Registry.CurrentUser.OpenSubKey("Software\Classes\Applications\", True)
            regKey.DeleteSubKeyTree(AppName)
            MsgBox("Applcation and settings saved")
        End If


If checkbox1 is checked, then program adds it self to be default gif viewer , if not checked, then removes..

Simple. :)
Good luck..
 
Back
Top