Problem associating file types, that doesn't exist already, with my app

Discussion in 'C++' started by asger_gronnow@yahoo.com, Feb 18, 2007.

  1. Guest

    Hi
    I'm having trouble associating file types with my app. Associating a
    file type works as long as the file type is already associated with
    another program but if the file type doesn't exist already, it isn't
    associated. So my question is: how do I associate a file type that
    isn't registered already? How can I register this new file type if
    that's what I'll have to do before associating it.
    I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
    currently use to associate file types:

    void associatefile (string filetype)
    {
    HKEY hKey;
    string exepath=AppPath;
    string key = "LibertyExpress";
    string keyval = "LibertyExpress";

    int reg = RegCreateKey( HKEY_CLASSES_ROOT, key.c_str(),&hKey);
    if (reg == ERROR_SUCCESS) {reg=RegSetValue(hKey, "", REG_SZ,
    keyval.c_str(), 0);}
    else {return;}

    if(reg == ERROR_SUCCESS)
    {
    key=filetype;
    keyval="LibertyExpress";
    reg=RegCreateKey(HKEY_CLASSES_ROOT, key.c_str(),
    &hKey);
    if(reg == ERROR_SUCCESS)
    {
    reg=RegSetValue(hKey, "", REG_SZ,
    keyval.c_str(), 0);
    if(reg == ERROR_SUCCESS)
    {
    key="LibertyExpress";
    keyval=exepath+" %1";
    reg=RegCreateKey(HKEY_CLASSES_ROOT,
    key.c_str(), &hKey);
    if(reg == ERROR_SUCCESS)
    {reg=RegSetValue(hKey, "shell\\open\\command", REG_SZ, keyval.c_str(),
    MAX_PATH);}
    }
    }
    }
    }
     
    , Feb 18, 2007
    #1
    1. Advertising

  2. Larry Smith Guest

    Re: Problem associating file types, that doesn't exist already, withmy app

    wrote:
    > Hi
    > I'm having trouble associating file types with my app. Associating a
    > file type works as long as the file type is already associated with
    > another program but if the file type doesn't exist already, it isn't
    > associated. So my question is: how do I associate a file type that
    > isn't registered already? How can I register this new file type if
    > that's what I'll have to do before associating it.
    > I'm programming in Win32 using the Dev-Cpp compiler. Here's the code I
    > currently use to associate file types:
    >
    > void associatefile (string filetype)
    > {
    > HKEY hKey;
    > string exepath=AppPath;
    > string key = "LibertyExpress";
    > string keyval = "LibertyExpress";
    >
    > int reg = RegCreateKey( HKEY_CLASSES_ROOT, key.c_str(),&hKey);
    > if (reg == ERROR_SUCCESS) {reg=RegSetValue(hKey, "", REG_SZ,
    > keyval.c_str(), 0);}
    > else {return;}
    >
    > if(reg == ERROR_SUCCESS)
    > {
    > key=filetype;
    > keyval="LibertyExpress";
    > reg=RegCreateKey(HKEY_CLASSES_ROOT, key.c_str(),
    > &hKey);
    > if(reg == ERROR_SUCCESS)
    > {
    > reg=RegSetValue(hKey, "", REG_SZ,
    > keyval.c_str(), 0);
    > if(reg == ERROR_SUCCESS)
    > {
    > key="LibertyExpress";
    > keyval=exepath+" %1";
    > reg=RegCreateKey(HKEY_CLASSES_ROOT,
    > key.c_str(), &hKey);
    > if(reg == ERROR_SUCCESS)
    > {reg=RegSetValue(hKey, "shell\\open\\command", REG_SZ, keyval.c_str(),
    > MAX_PATH);}
    > }
    > }
    > }
    > }
    >


    This is Windows API specific code; not C++ related.
    Try a Microsoft Windows news group.
     
    Larry Smith, Feb 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LT
    Replies:
    7
    Views:
    2,099
    Phlip
    Jul 25, 2004
  2. Psymaster
    Replies:
    1
    Views:
    374
    John Roth
    Jul 24, 2003
  3. Noah Roberts

    Does this already exist?

    Noah Roberts, Nov 20, 2006, in forum: C++
    Replies:
    2
    Views:
    292
    Noah Roberts
    Nov 20, 2006
  4. Dave Angel
    Replies:
    0
    Views:
    151
    Dave Angel
    Dec 5, 2012
  5. Steven D'Aprano
    Replies:
    12
    Views:
    186
    Roy Smith
    Jan 19, 2013
Loading...

Share This Page