ComAddin
所属分类:Windows编程
开发工具:Visual C++
文件大小:941KB
下载次数:89
上传日期:2012-03-29 23:26:38
上 传 者:
kent751175
说明: vc++开发office插件,包括excel,word的二次开发
(msoffice )
文件列表:
ComAddin\BttnHandler.cpp (6425, 1999-05-01)
ComAddin\ComAddin.def (205, 1999-05-01)
ComAddin\ComAddin.h (6346, 1999-05-04)
ComAddin\MyAddin.cpp (11756, 1999-05-07)
ComAddin\MyAddinCF.cpp (2241, 1999-05-01)
ComAddin\TestAddin.001 (4218, 1999-05-01)
ComAddin\TestAddin.dsp (4257, 2011-05-31)
ComAddin\TestAddin.ncb (230400, 2012-03-29)
ComAddin\Debug\vc60.idb (156672, 2012-03-17)
ComAddin\Debug\vc60.pdb (102400, 2012-03-12)
ComAddin\Debug\TestAddin.dll (221238, 2012-03-12)
ComAddin\Debug\TestAddin.lib (1778, 2012-03-12)
ComAddin\Debug\TestAddin.exp (1021, 2012-03-12)
ComAddin\Debug\TestAddin.pdb (721920, 2012-03-12)
ComAddin\Debug\BttnHandler.sbr (0, 2012-03-12)
ComAddin\Debug\BttnHandler.obj (23483, 2012-03-12)
ComAddin\Debug\ComAddin.sbr (0, 2012-03-12)
ComAddin\Debug\ComAddin.obj (28690, 2012-03-12)
ComAddin\Debug\MyAddin.sbr (0, 2012-03-12)
ComAddin\Debug\MyAddin.obj (34991, 2012-03-12)
ComAddin\Debug\MyAddinCF.sbr (0, 2012-03-12)
ComAddin\Debug\MyAddinCF.obj (26418, 2012-03-12)
ComAddin\Debug\Sadd.sbr (0, 2012-03-12)
ComAddin\Debug\TestAddin.pch (188284, 2012-03-12)
ComAddin\Debug\Sadd.obj (2978, 2012-03-12)
ComAddin\Debug\TestAddin.ilk (313336, 2012-03-12)
ComAddin\Debug\TestAddin.bsc (2040832, 2012-03-12)
ComAddin\TestAddin.plg (1773, 2012-03-12)
ComAddin\TestAddin.dsw (547, 2011-06-12)
ComAddin\ComAddin.cpp (8603, 2011-06-12)
ComAddin\TestAddin.opt (128000, 2012-03-29)
ComAddin\Debug (0, 2011-06-03)
ComAddin (0, 2011-06-03)
Microsoft Knowledge Base Article Q230689
SAMPLE: Office 2000 COM Add-In Written in Visual C++
-------------------------------------------------------------------------------
The information in this article applies to:
- Microsoft Office 2000 Developer, version 2000
- Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
- Microsoft Excel 2000
- Microsoft FrontPage 2000
- Microsoft PowerPoint 2000
- Microsoft Word 2000
-------------------------------------------------------------------------------
SUMMARY
=======
COMADDIN.EXE is a self-extracting executable that demonstrates building an Office
2000 COM add-in in Visual C++. A COM add-in is simply an in-process COM server
(DLL) specifically designed to run within the context of one or more Office 2000
applications. COM add-ins provide a flexible, efficient, and uniform method of
extending the Office 2000 environment.
COM add-ins are a new feature of Office 2000. They are built using any
programming language that can create COM components, such as Visual Basic,
Visual C++, Visual J++, and the Office 2000 Developer Edition of VBA.
This sample demonstrates the necessary steps to build a COM add-in in Visual C++.
The sample creates a basic add-in shell that you can extend to build your own
Office add-in.
* THE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND/OR FITNESS FOR A PARTICULAR PURPOSE.
MORE INFORMATION
================
The following file is available for download from the Microsoft Software
Library:
COMADDIN.EXE
(http://support.microsoft.com/download/support/mslfiles/COMADDIN.EXE)
Release Date: Jan-04-1999
For more information about downloading files from the Microsoft Software Library,
please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
http://support.microsoft.com/support/kb/articles/q119/5/91.asp
COMADDIN.EXE will extract the following files to a folder of your choosing:
FileName Size
----------------------------------------
TestAddin.dsw 541 bytes
TestAddin.dsp 4.11 KB
ComAddin.h 6.19 KB
ComAddin.cpp 8.38 KB
ComAddin.def 205 bytes
MyAddin.cpp 10.6 KB
MyAddinCF.cpp 2.18 KB
BttnHandler.cpp 6.27 KB
IDTExensibility2
----------------
For a COM object to be an Office 2000 add-in, it must support the
IDTExensibility2 interface as described in the Microsoft Add-In Designer Type
Library (MSADDNDR.DLL). This interface has been declared for you in ComAddin.h
so no import is necessary. All COM add-ins inherit from this interface and must
implement each of its five methods:
- OnConnection
- OnDisconnection
- OnAddInsUpdate
- OnStartupComplete
- OnBeginShutdown
When a COM add-in is first loaded, a QueryInterface call is made for
IDTExtensibility2. If this call fails, the add-in is unloaded. If the call
succeeds, the host application will use the reference returned to notify the
add-in of changes made to its state. Below is a description of each of these
methods.
OnConnection:
The OnConnection event fires whenever the COM add-in is connected. The add-in may
be connected on startup, by the end user, or through automation. If OnConnection
returns S_OK, the add-in is said to be loaded. If any other value is returned,
the host application will immediately release its reference to the add-in and
the object will be destroyed.
OnConnection takes four parameters as described below:
- Application - A reference to the IDispatch interface of the host application.
- ConnectMode - A constant that specifies how the add-in was connected.
- ext_cm_AfterStartup - Started by the end user from the COM add-ins dialog.
- ext_cm_CommandLine - Connected from the command line.
- ext_cm_External - Connected by an external application through Automation.
- ext_cm_Startup - Started by the host at application startup. This behavior
can be controlled by a setting in the registry.
- AddInInst - A reference to the COMAddIn object that refers to this add-in in
the COMAddIns Collection for the host application.
- Custom - An array of Variants that can hold user-defined data.
OnDisconnection:
The OnDisconnection event fires when the COM add-in is disconnected and just
before it unloads from memory. The add-in should perform any cleanup of
resources in this event, and restore any changes made to the host application.
OnDisconnection takes two parameters as described below:
- RemoveMode - A constant that specifies how the add-in was disconnected.
- ext_dm_HostShutdown - Disconnected when the host application closed.
- ext_dm_UserClosed - Disconnected by the end user or an Automation
controller.
- Custom - An array of Variants that can hold user-defined data.
OnStartupComplete and OnBeginShutdown:
Both the OnStartupComplete and OnBeginShutdown events notify the add-in when the
host application has left or is entering a state where user-interaction should
be avoided because the application is busy loading or unloading itself from
memory. OnStartupComplete will only fire if your add-in was connected during
startup, and OnBeginShutdown will only fire if your add-in is disconnected by
the host during shutdown.
Because the user-interface for the host application is fully active when these
events fire, they may be the only way to perform certain actions that otherwise
would be unavailable from OnConnection and OnDisconnection.
OnAddInsUpdate:
The OnAddInsUpdate event fires when the set of registered COM add-ins changes. In
other words, whenever a COM add-in is installed or removed from the host
application, this event fires.
Registering the COM Add-In
--------------------------
In addition to normal COM registration, a COM add-in needs to register itself
with each Office 2000 application it can safely run in. To register itself with
a particular application, the add-in creates a subkey, using its ProgID as the
name for the key, under the following location:
HKEY_CURRENT_USER\Software\Microsoft\Office\
\Addins\
The add-in can provide values at this key location for both a friendly display
name and a full description. In addition, the add-in should specify its desired
load behavior using a DWORD value called "LoadBehavior." This value determines
how the add-in will be loaded by the host application, and is made up of a
combination of the following values:
- 0x00 = Disconnect - Is not loaded.
- 0x01 = Connected - Is loaded.
- 0x02 = Bootload - Load on application Startup.
- 0x08 = DemandLoad - Load only when requested by user.
- 0x16 = ConnectFirstTime - Load only once (on next startup).
The typical value specified is 0x03 (Connected | Bootload).
Add-ins that implement IDTExtensibility2 should also specify a DWORD value called
"CommandLineSafe" to indicate whether they are safe for operations that do not
support a user interface. A value of 0x00 means False, 0x01 is True. Because
this sample displays a message box, it is not safe for command line execution,
and therefore sets the value to 0x00.
Getting Started
---------------
To get started writing add-ins, compile the sample project, run regsvr32.exe on
the built DLL, and then launch Microsoft Word, Excel, Powerpoint and/or
Frontpage 2000. You should see a dialog box come up as the add-in gets loaded
that says "Hello" and tells you what application it is in.
(c) Microsoft Corporation 1999, All Rights Reserved.
Contributions by Richard R. Taylor, Microsoft Corporation
近期下载者:
相关文件:
收藏者: