HOWTO: Create Custom AppWizards that Generate Non-MFC ProjectsLast reviewed: October 20, 1997Article ID: Q173483 |
The information in this article applies to:
SUMMARYVisual C++ 5.0 custom AppWizards always generates an MFC-based project initially. Now the custom AppWizards can change the essential MFC project settings for the generated project through the new automation object model of Developer Studio.
MORE INFORMATIONWhen a custom AppWizard generates a project, it cannot simply replace the automatically created .dsp project settings file. The project settings in the .dsp file are set by internal rules that assume all generated projects are MFC projects. However, Visual C++ 5.0's new object model allows custom AppWizards to modify tool settings such that all dependencies on MFC are removed from the resulting project. The CCustomAppWiz class in Visual C++ 5.0 now has a virtual override called CustomizeProject. CustomizeProject provides the custom wizard with an IBuildProject interface. The Configurations method of IBuildProject provides an IConfiguration interface for each build configuration in the project. IConfiguration can add and remove settings supplied to tools such as the compiler. Using these methods, a custom wizard can remove settings that add dependencies on MFC.
Sample CodeFollowing is an example CustomizeProject override that demonstrates the removal of MFC dependencies:
#import "c:\Program Files\DevStudio\SharedIDE\bin\ide\devbld.pkg" void CNoMfcCustWizAppWiz::CustomizeProject(IBuildProject* pProject) { using namespace DSProjectSystem; long lNumConfigs; IConfigurationsPtr pConfigs; IBuildProjectPtr pProj; // Needed to convert IBuildProject to the DSProjectSystem namespace pProj.Attach((DSProjectSystem::IBuildProject*)pProject, true); pProj->get_Configurations(&pConfigs); pConfigs->get_Count(&lNumConfigs); //Get each individual configuration for (long j = 1 ; j < lNumConfigs+1 ; j++) { _bstr_t varTool; _bstr_t varSwitch; IConfigurationPtr pConfig; _variant_t varj = j; pConfig = pConfigs->Item(varj); // Remove Preprocessor def for MFC DLL specifier, _AFXDLL varTool = "cl.exe"; varSwitch = "/D \"_AFXDLL\""; pConfig->RemoveToolSettings(varTool, varSwitch, varj); varTool = "rc.exe"; varSwitch = "/d \"_AFXDLL\""; pConfig->RemoveToolSettings(varTool, varSwitch, varj); // OPTIONAL // Add Libs that MFC headers would have pulled in automatically // Feel free to customize this listing to your tastes varTool = "link.exe"; varSwitch = "kernel32.lib user32.lib gdi32.lib winspool.lib " "comdlg32.lib advapi32.lib shell32.lib ole32.lib " "oleaut32.lib uuid.lib odbc32.lib odbccp32.lib"; pConfig->AddToolSettings(varTool, varSwitch, varj); } }Note that this code sample uses features from Visual C++ 5.0's new COM compiler support. The #import statement imports and creates definitions for all of the types in the DEVBLD.PKG type library. This allows the code to use the COM smart pointers of the form IInterfacePtr, as well as the new _bstr_t and _variant_t types. All of these new types automatically clean up used memory and release held interface pointers when they go out of scope. Refer to the Visual C++ documentation for more information.
Caveats
REFERENCESVisual C++ Books Online: Visual C++; Developer Studio Environment; Automating Tasks in Developer Studio Visual C++ Books Online: Visual C++; Visual C++ Programmer's Guide; Beginning Your Program; Creating a Custom AppWizard; Creating Custom AppWizards; Customizing the Generated Custom AppWizard Project Visual C++ Books Online: Visual C++; Visual C++ Programmer's Guide; Adding Program Functionality; Overviews; Compiler COM Support: Overview Keywords : WizardIss Version : WINNT:5.0 Platform : winnt Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |