Results 1 to 22 of 22

Thread: File extension association

  1. #1

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    File extension association

    Hi quys.

    I decompiled a cdlabel app 10 years ago and it works great. I can association the cdl extension no problem but when I double-click a cdl file it opens my app but it doesn't show the files data.

    I've done a search on here for file association but there are no hints on how to get this to work. I've downloaded every app of PSC and they association the file but it still doesn't open.

    I've added a Command$ for the file and it still doesn't show that file. Now Windows associates txt files to NotePad. I've checked every setting with txt files and they are exactly the same as my cdl but it still doesn't work.

    Any tips would be gratefully recieved?

    If you want a link to this app on PSC then let me know.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: File extension association

    Look at this example here http://www.vbforums.com/showthread.php?t=241188

    I think the part you missed when associating is presented in this line with %1

    Code:
    AssociateMyApp "MyFileType", "C:\MyApp.exe %1", "xyz", , "C:\MyApp.exe,-1"
    Which tells Windows to send the path of the file to the exe as a parameter, so you can pick it up with the Command function.

  3. #3

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Thanks for the reply baja_yu.

    I don 't think so baja_yu the %1 only associates the icon to the app which its already doing. It just won't open that file afterwards.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  4. #4
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: File extension association

    Well... if double-clicking the file name starts your program then there is no problem with the association code at all. It's done it's job.

    Your problem, most likely, is in parsing the datafile being passed. Are you parsing the file name passed for quotes and no quotes? Have you debugged the command$ open process?

  5. #5

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: File extension association

    Quote Originally Posted by Keithuk View Post
    Thanks for the reply baja_yu.

    I don 't think so baja_yu the %1 only associates the icon to the app which its already doing. It just won't open that file afterwards.
    erm... have you checked the parameter list?
    AssociateMyApp "MyFileType", "C:\MyApp.exe %1", "xyz", , "C:\MyApp.exe,-1"
    Public Sub AssociateMyApp(ByVal sAppName As String, ByVal sEXE As String, ByVal sExt As String, Optional ByVal sCommand As String, Optional ByVal sIcon As String)

  7. #7

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Thanks for your input guys.

    Quote Originally Posted by Tom Moran View Post
    Well... if double-clicking the file name starts your program then there is no problem with the association code at all. It's done it's job.
    It is associated but it doesn't show that file.

    Quote Originally Posted by Tom Moran View Post
    Are you parsing the file name passed for quotes and no quotes? Have you debugged the command$ open process?
    I've Run:

    "C:\WINDOWS\CD Case Labeller.exe" "c:\Temp2.cdl"

    and it opens CD Case Labeller.exe but it doesn't show Temp2.cdl.

    I've checked the Command$ in Form_Load and just added Me.Caption = Command$. It just shows the normal title.


    Quote Originally Posted by si_the_geek
    erm... have you checked the parameter list?
    Yes Si I've built a little app with that code and I've used

    Code:
    Private Sub Command1_Click()
    
    AssociateMyApp "CD Case Label", "c:\windows\CD Case Labeller.exe %1", "cdl", "c:\windows\CD Case Labeller.exe,-1"
    
    End Sub
    And that makes no difference.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  8. #8
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: File extension association

    I just tested the code that baja_yu linked to and it works fine for me on XP SP3.

    Temp2.cdl has the icon of the executable. When double-clicking on Temp2.cdl, it starts the executable and the full path of Temp2.cdl can be retrieved from the Command$ function.


    ::edit::

    Keithuk, you're using the wrong parameters.

    Code:
    AssociateMyApp "CD Case Label", "c:\windows\CD Case Labeller.exe %1", "cdl", "c:\windows\CD Case Labeller.exe,-1"
    should be


    Code:
    AssociateMyApp "CD Case Label", "c:\windows\CD Case Labeller.exe %1", "cdl", , "c:\windows\CD Case Labeller.exe,-1"
    Last edited by Chris001; May 23rd, 2010 at 03:33 PM.

  9. #9

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Quote Originally Posted by Chris001 View Post
    I just tested the code that baja_yu linked to and it works fine for me on XP SP3.

    Temp2.cdl has the icon of the executable. When double-clicking on Temp2.cdl, it starts the executable and the full path of Temp2.cdl can be retrieved from the Command$ function.

    Code:
    AssociateMyApp "CD Case Label", "c:\windows\CD Case Labeller.exe %1", "cdl", , "c:\windows\CD Case Labeller.exe,-1"
    Yes my mistake there I copied and pasted the code wrong. I've changed it and it still doesn't work.

    I don't know what you are associating Temp2.cdl with?

    I put this in Form_Load to try and catch the Command$ but it just shows the normal Form Caption so there can't be any Command$.
    Code:
    If Command$ <> "" Then
        Call LoadFile(Command$) 'Sub to load the file
    Else
        Me.Caption = Command$
    End If
    If you want the original app I posted on PSC 8 years ago then its CD Jewel Case Labeller

    Its not a bad app really. I've changed a few things over the years but I haven't reposted it in there.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: File extension association

    Quote Originally Posted by Keithuk View Post
    I put this in Form_Load to try and catch the Command$ but it just shows the normal Form Caption so there can't be any Command$.
    Code:
    If Command$ <> "" Then
        Call LoadFile(Command$) 'Sub to load the file
    Else
        Me.Caption = Command$
    End If
    That code will only change the caption if Command$ is empty - which means that either the caption is blank, or you are getting something in Command$.

    Based on that, I assume that LoadFile isn't working with it properly.

    This is the kind of test code you should use instead:
    Code:
    Me.Caption = Command$
    If Command$ <> "" Then
        Call LoadFile(Command$) 'Sub to load the file
    End If

  11. #11

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Quote Originally Posted by si_the_geek View Post
    That code will only change the caption if Command$ is empty - which means that either the caption is blank, or you are getting something in Command$.

    Based on that, I assume that LoadFile isn't working with it properly.

    This is the kind of test code you should use instead:
    Code:
    Me.Caption = Command$
    If Command$ <> "" Then
        Call LoadFile(Command$) 'Sub to load the file
    End If
    Yes Si I'm trying to check the Command$ or what ever but no Command$ is being sent to it.
    Code:
    If Command$ <> "" Then
        Call LoadFile(Command$)
    Else
        Me.Caption = Command$
    End If
    If the Command$ is blank then it should show a blank Caption, it just shows the default Caption. Its not easy trying to send a Command$ to the app because you can't see what is happening.

    I've added your Me.Caption = Command$ and it still only shows the default Caption.

    The LoadFile sub is working properly as I can make out. Its the same code I use the Open file I just copied and pasted it into a Sub I'm supplying the filename with the Command$.

    As I've said I've checked all the settings for a txt file with NotePad and they are exactly the same as mine. If you double-click a txt file that file opens in NotePad.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  12. #12
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: File extension association

    This is the CD Labeler program from pscode and I've added the file association code that baja_yu linked to.

    1) Compile the app.
    2) Start the app and go to Options -> Associate with CDL extension.
    3) Close the app.
    4) Double-click on the Label.cdl file.

    It should open the app and show a messagebox with the short and long path of the Label.cdl file.


    <project removed>
    Last edited by Chris001; May 24th, 2010 at 06:20 PM.

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: File extension association

    Quote Originally Posted by Keithuk View Post
    I've added your Me.Caption = Command$ and it still only shows the default Caption.
    In that case either Command$ is exactly the same as the default Caption (which is extremely doubtful), or the Command$ code is not being run, or you are running other code which resets the caption and thus making other code which changes the caption irrelevant.

  14. #14
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: File extension association

    To be positive what is passed, do: MsgBox Command$, at the very begining of Form Load event.

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File extension association

    I don 't think so baja_yu the &#37;1 only associates the icon to the app which its already doing. It just won't open that file afterwards.
    i don't know if you fixed this yet, but if you do not have the %1 no filename will be passed to the command string, it will just open your program without command stirng

    the icon is the -1 passed with the last argument

    also if you drag files over your exe, any path/filename that contains spaces will, in the command string, be enclosed in quotes and must be treated accordingly
    C:\temp\mytest.csv C:\temp\new.htaccess "C:\temp\no pics.doc" C:\temp\index.htm
    Last edited by westconn1; May 24th, 2010 at 04:58 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Quote Originally Posted by baja_yu View Post
    To be positive what is passed, do: MsgBox Command$, at the very begining of Form Load event.
    Ok I've tried MsgBox Command$ in Form Load and it shows the Command$. I've put the same MsgBox in the LoadFile Sub and it shows the same filename.

    I've copied and pasted the same code from Open. I don't know why it doesn't show the file details. Once it opens you can click on Open that same file and it opens as it should do.

    Thanks westconn1 I've dragged the file over the exe and the MsgBox shows correctly but it doesn't show the details.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  17. #17

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Thanks Chris001 it shows the long and short filenames in the MsgBox but it still doesn't open that files data. The association code is the same that I'm using.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  18. #18
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: File extension association

    Sorry, but I didn't add the code to open the CDL file, just the messagebox.

    Below is a new example. I've added a OpenFromCommand sub to load the data from the CDL file.
    Attached Files Attached Files

  19. #19

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Sorry for not replying earlier Chris I had malware problem which I couldn't resolve so I did a format and rebuild last night.

    No the problem is still there with your modded project2, if fact there is no difference between project1 and project2 Chris.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  20. #20
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: File extension association

    Sorry, then I have no idea what's wrong. It works fine for me.

    This is what I get when I start the executable normally.



    This is what I get when I double-click on the Label.cdl file.


  21. #21

    Thread Starter
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: File extension association

    Yes I've no idea whats stopping mine if yours works its got me baffled and I'm using WinXP SP3 just the same as you.

    Thanks for trying Chris.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  22. #22
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File extension association

    have you put breakpoint in openfromcommand ans stepped through?

    are you sure the input functions are returning what you expect, from the file
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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