ID: Q130842
The information in this article applies to:
MFC's App Wizard in Visual C++ version 2.0 will not generate an inproc OLE Automation server. This article gives steps you can follow to create an inproc automation server using MFC. You can also obtain a sample (MFCINP32) from the Microsoft Software Library that is a 32-bit inproc automation object created by following the steps in this article.
The following file is available for download from the Microsoft Software Library:
~ MFCINP32.EXE (size: 25194 bytes)
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591
TITLE : How to Obtain Microsoft Support Files from
Online Services
NOTE: The App Wizard in Visual C++ version 2.1 and above does generate an
inproc OLE Automation server.
MFC's App Wizard doesn't generate inproc (DLL) OLE servers because it is not possible for MFC to fully implement one that can open into a separate window. MFC needs to hook into the client's main message retrieval loop to translate accelerators of the separate window and to implement idle-time processing. OLE doesn't provide such a mechanism. It is entirely possible to implement an inproc server in MFC with no user interface or with a very simple user interface. This article provides the instructions to do this.
It is assumed that Visual C++ version 2.0 and the Control Development Kit have been installed.
1. Use INPROC.CPP, INPROC.H, and STDAFX.H from the sample as the starting
point. Copy these into a new directory. The names INPROC.CPP and
INPROC.H can be changed to something more appropriate for your project.
2. Create a new project of type Dynamic-Link Library. (Do not select MFC
AppWizard DLL.) Add INPROC.CPP to this project.
3. Create an .ODL file (INPROC.ODL) containing a modification of the
following code, and add it to the project.
[ uuid(ABEBE5A0-0C69-11CE-B774-00DD01103DE1), version(1.0) ]
library inproc
{
importlib("stdole32.tlb");
//{{AFX_APPEND_ODL}}
};
Don't use the same UUID as the one shown here. Instead generate a new
one by running GUIDGEN.EXE, and use that value. The library name can be
changed from inproc to a name more appropriate for your project. The
version number can also be changed.
4. Create the .DEF file (INPROC.DEF) containing the following code, and add
it to the project.
LIBRARY INPROC
EXPORTS
DllGetClassObject
DllCanUnloadNow
DllRegisterServer
The library name can be changed from INPROC to a name more appropriate
for your project.
5. Select Project Settings, as follows:
- In the ProjectSettings dialog box under General, select Use MFC in a
shared DLL.
- In the ProjectSettings dialog box under C/C++, remove _AFXDLL, and
add _USRDLL and _WINDLL under Preprocessor definitions.
- In the ProjectSettings dialog under Link, add the following libraries
to Object/Library modules:
ole32.lib oleaut32.lib
6. Choose ClassWizard from the Project menu. ClassWizard will complain that
the .CLW file does not exist. It will ask you to rebuild the .CLW file
by opening the .RC file and running ClassWizard again.
7. Open your .RC file or create a new .RC file by choosing New from the
File menu and selecting Resource Script. Save the new .RC file
(INPROC.RC). Now bring up ClassWizard. The .CLW file will now be built
after you choose OK in the SelectSourceFiles dialog box. Follow these
steps:
a. Select the OLE Automation tab in the ClassWizard dialog.
b. Choose the AddClass button, and add a class of type CCmdTarget.
c. Select the OLEAutomation check box.
d. Select the OLECreatable check box, and provide an ExternalName
(progID) if this is a top-level automation object. This external name
is used by the automation controller/client to create the object.
(The sample creates a class called TestObject that has an external
name Inproc.TestObject.)
8. Add the required automation properties and methods to the newly created
class. (The sample creates a method called TestMethod that returns void
and has no parameters. The method calls MessageBeep.)
9. Build the project. Register the inproc Automation object by using the
Tools/RegisterControl menu.
10. Note that a 16 bit controller like Visual Basic version 3.0 cannot
control a 32-bit inproc automation object because 16-bit to 32-bit
interoperability is not supported with inproc automation objects.
Instead, write a 32-bit controller to control this 32-bit inproc
automation object.
Additional query words: kbole kbfile
Keywords : kbole
Technology : kbMfc
Version : 2.03 2.00
Platform : NT WINDOWS
Last Reviewed: December 8, 1998