C ++ program needs file association

I am distributing a free product that reads and writes text files with a unique extension. I was hoping that double-clicking on such a file would automatically launch the application.

During development on Windows 7 Professional, I created an association to open my files by double-clicking, right-clicking the file-> Open with ...-> Select the default program ...-> Browse., And then "Always use the selected program to open this file type. " Good. He did what he needed. I was about to send my program with instructions for users to do the same.

However, when I moved the location of the binary, I see that "Always Use" is now grayed out / insensitive, so although I could go to the new binary, I could not make it the default. Since I thought that my users would also have problems with this, I would like to know if I can install or run the program, taking care of the comparison.

I looked at the Windows installer for about 5 minutes before determining that it had much more power and complexity than I needed (for my needs, a zip file would be sufficient, except for this file mapping.)

So, I looked at the fact that my program at startup set up the display, if it was not already there. (I know that this would be very bad behavior if we talked about the general type of files, such as .html or .jpg, but in this case it is its extension .blahblah, which, of course, no one uses for anything .)

Based on the information at http://www.cplusplus.com/forum/windows/26987/ and http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx I managed to run my program at startup, open HKEY_CLASSES_ROOT \ .blahblah and confirm (and if necessary change) the default text to be an exact description of the file (replacing some text that might have been created by default when I was the official association last summer of the year). However, when it came to creating the HKEY_CLASSES_ROOT \ firm.app.1 \ shell \ open \ command, my RegCreateKeyEx () shell, which works fine to change the value of \ .blahblah, now gives a return code of 5, apparently lacking permission .

, . - ? , , ?

, ? Windows? , , ?

. Visual Studio 2008 Windows 7 Professional, , Windows, ++ 80- Unix/Linux...

+4
2

, , , .

1) ProgID. vender.app.versionnumber , regedit , . .

2) MSFT HKEY_CLASSES_ROOT, http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx:

: HKEY_CLASSES_ROOT - , HKEY_CURRENT_USER\ \ HKEY_LOCAL_MACHINE\Software\Classes , HKEY_CLASSES_ROOT - , . . HKEY_CLASSES_ROOT.

3), , SHChangeNotify(). ( , , .)

, . REGEDIT .moselle( ) MoselleIDE ( ), , , , , .. , , , : 1) , 2) , 3) .

void RegSet( HKEY hkeyHive, const char* pszVar, const char* pszVa

lue ) {

  HKEY hkey;

  char szValueCurrent[1000];
  DWORD dwType;
  DWORD dwSize = sizeof( szValueCurrent );

  int iRC = RegGetValue( hkeyHive, pszVar, NULL, RRF_RT_ANY, &dwType, szValueCurrent, &dwSize );

  bool bDidntExist = iRC == ERROR_FILE_NOT_FOUND;

  if ( iRC != ERROR_SUCCESS && !bDidntExist )
      AKS( AKSFatal, "RegGetValue( %s ): %s", pszVar, strerror( iRC ) );

  if ( !bDidntExist ) {
      if ( dwType != REG_SZ )
          AKS( AKSFatal, "RegGetValue( %s ) found type unhandled %d", pszVar, dwType );

      if ( strcmp( szValueCurrent, pszValue ) == 0 ) {
          AKS( AKSTrace, "RegSet( \"%s\" \"%s\" ): already correct", pszVar, pszValue );
          return;
      }
  }

  DWORD dwDisposition;
  iRC = RegCreateKeyEx( hkeyHive, pszVar, 0, 0, 0, KEY_ALL_ACCESS, NULL, &hkey, &dwDisposition );
  if ( iRC != ERROR_SUCCESS )
      AKS( AKSFatal, "RegCreateKeyEx( %s ): %s", pszVar, strerror( iRC ) );

  iRC = RegSetValueEx( hkey, "", 0, REG_SZ, (BYTE*) pszValue, strlen( pszValue ) + 1 );
  if ( iRC != ERROR_SUCCESS )
      AKS( AKSFatal, "RegSetValueEx( %s ): %s", pszVar, strerror( iRC ) );

  if ( bDidntExist )
      AKS( AKSTrace, "RegSet( %s ): set to \"%s\"", pszVar, pszValue );
  else
      AKS( AKSTrace, "RegSet( %s ): changed \"%s\" to \"%s\"", pszVar, szValueCurrent, pszValue );

  RegCloseKey(hkey);
}



int SetUpRegistry() {

  //app doesn't have permission for this when run as normal user, but may for Admin?  Anyway, not needed.
  //RegSet( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\MoselleIDE.exe", "C:\\Moselle\\bin\\MoselleIDE.exe" );

  RegSet( HKEY_CURRENT_USER, "Software\\Classes\\.moselle", "Moselle.MoselleIDE.1" );

  // Not needed.
  RegSet( HKEY_CURRENT_USER, "Software\\Classes\\.moselle\\Content Type", "text/plain" );
  RegSet( HKEY_CURRENT_USER, "Software\\Classes\\.moselle\\PerceivedType", "text" );

  //Not needed, but may be be a way to have wordpad show up on the default list.
  //RegSet( HKEY_CURRENT_USER, "Software\\Classes\\.moselle\\OpenWithProgIds\\Moselle.MoselleIDE.1", "" );

  RegSet( HKEY_CURRENT_USER, "Software\\Classes\\Moselle.MoselleIDE.1", "Moselle IDE" );

  RegSet( HKEY_CURRENT_USER, "Software\\Classes\\Moselle.MoselleIDE.1\\Shell\\Open\\Command", "C:\\Moselle\\bin\\MoselleIDE.exe %1" );

  SHChangeNotify( SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL );
  return 0;
}

, , , , ++, Windows , 50 , , . -, .

+5

, , , . , . .

0

All Articles