Microsoft KB Archive/102666

From BetaArchive Wiki

HOWTO: How to Register Another File Type for an Application


The information in this article applies to:

  • The ClassWizard, used with:
    • Microsoft Visual C++, version 1.52


If you do not associate a file extension with a document when you create an application in App Wizard 1.0, App Wizard does not generate any code to register the file extension. The text below presents the changes necessary to register a file extension in the Registration database.

To define the default file extension for an application, use App Studio to change the application's string resources. For example, change the following:

   \nApp\nApp Document 

to read as follows: '

   \nApp\App Document\n.APP Files (*.app)\\nAppFileType\nAppFileType 

This code is required for the document template when the application calls AddDocTemplate(). You must also add the following code to the InitInstance() function:

Sample Code

 * Compiler options needed: None

// Cut and paste from line 155 of APPUI.CPP into your source file,
// before the InitInstance() call.
static BOOL NEAR PASCAL SetRegKey(LPCSTR lpszKey, LPCSTR lpszValue)
   if (::RegSetValue(HKEY_CLASSES_ROOT, lpszKey, REG_SZ, lpszValue,
          lstrlen(lpszValue)) != ERROR_SUCCESS)
      TRACE1("Warning: registration database update failed for key
          '%Fs'\n", lpszKey);
      return FALSE;

  return TRUE;

// Modify your InitInstance() definition to include the
// following code:

BOOL CAppApp::InitInstance()
   // Standard Initialization
   m_pMainWnd = pMainFrame;

   // Add the follow code.

   // Registration Type Name
   CString      strFileTypeName;

   // Position used if more than one document template.
   POSITION     pos;
   CDocTemplate *pTemplate =

   // Add another file extension to registration database.
   // If you double-click a .APP or .SAV file in File Manager it
   // automatically starts this application.
   // SetRegKey adds a file extension to the Registration Database
   ((void)SetRegKey(".sav", strFileTypeName);

   // create a new (empty) document)
   return TRUE;


In Visual C++ for Windows, version 1.5, if you create a project using App Wizard the code to register a file extension in the Registration database may be automatically generated by performing the following steps:

  1. Choose AppWizard from the Project menu to create a new project.
  2. Type in the Project Name.
  3. Click the Classes button in the MFC AppWizard dialog box.
  4. Click and select the document class to be created from the New Application Classes (the document class typically ends with doc).
  5. The new File Extension and Doc Type Name boxes should be displayed with suggested text in the Doc Type Name box.
  6. Fill in your file extension and doc type name.

NOTE: If you do not enter any text in the file extensions box the code to register your file extension in the Registration database will NOT be automatically generated.

  1. Click OK.
  2. Click OK.
  3. Review the New Application Information and click Create to generate your application.

Additional query words: kbinf 1.00 1.50

Keywords : kbwizard kbMFC kbVC
Issue type : kbhowto
Technology : kbVCsearch kbAudDeveloper kbClassWizard

Last Reviewed: May 8, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.