只问耕耘
分类: C/C++
2006-05-29 14:30:19
OLE作为Windows的一个特征,通过把应用程序的功能作为对象暴露给其他应用程序,这些对象拥有属性(数据)和方法(函数),应用程序可以通过定义、调用OLE中的对象去执行相应的任务。Domino既可以作为一个OLE提供者被外部程序调用,也可以通过OLE去控制其他OLE对象。
1、建一个 MFC 的程序工程
2、找到App的InitInstance()函数,在其中添加 AfxOleInit()函数的调用
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
3、Using Type Libraries ..Lotus\notes\notes32.tlb, add following classes: NOTESUIWORKSPACE, NOTESUIVIEW, NOTESDOCUMENTCOLLECTION
<#include "notes32.h">
To create a dispatch class from a type-library (.tlb) file
The Add Class menu appears.
An Import from Type Library dialog box appears.
Tip Some type library information is stored in files with .DLL, .OCX, or .OLB file extensions.
The Confirm Classes dialog box appears. The list contains the external names of the classes described in the type-library file. Other controls in the Confirm Classes dialog box show the proposed names for the dispatch classes and for the header and implementation files for those classes. As you select a class in the list box, the Class Name box shows the name for the corresponding class.
You can use the Browse buttons to select other files, if you prefer to have the header and implementation information written in existing files or in a directory other than the project directory.
The Type Library Tool writes header and implementation code for your dispatch class, using the class names and file names you have supplied, and adds the .CPP file to your project.
4、Sample 调试通过:
#include "notes32.h"
void CADlg::OnOK()
{
VARIANT *uiview_v,*docs_v;
NOTESUIWORKSPACE ws;
NOTESUIVIEW uiview;
NOTESDOCUMENTCOLLECTION docs;
ws.CreateDispatch("Notes.NotesUIWorkspace");
uiview_v=&ws.GetCurrentview();
uiview.AttachDispatch(uiview_v->pdispVal);
docs_v=&uiview.GetDocuments();
docs.AttachDispatch(docs_v->pdispVal);
char *a=new char[50];
itoa(docs.GetCount(),a,10);
//显示选定的文档数量
MessageBox(a);
}