AfxOleInit()/CoInitialize()/CoInitializeEx()
来源:互联网 发布:数值优化 编辑:程序博客网 时间:2024/06/06 07:30
具体可见msdn开发人员中心:
(一)AfxOleInit()
1、函数说明:Initializes OLE support for the application.
2、函数原型:
BOOL AFXAPI AfxOleInit( );
Nonzero if successful; 0 if initialization fails, possibly because incorrect versions of the OLE system DLLs are installed.
Remarks
Call this function to initialize the OLE support for an MFC application. When this function is called, the following actions occur:
Initializes the COM library on the current apartment of the calling application. For more information, seeOleInitialize.
Creates a message filter object, implementing the IMessageFilter interface. This message filter can be accessed with a call to AfxOleGetMessageFilter.
3、注意:If AfxOleInit is called from an MFC DLL, the call will fail. The failure occurs because the function assumes that, if it is called from a DLL, the OLE system was previously initialized by the calling application。
(二)CoInitialize()
1、函数说明:Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA).初始化当前线程中调用的COM组件,而且是单线程。
2、函数原型:
Syntax
HRESULT CoInitialize( __in_opt LPVOID pvReserved);
Parameters
- pvReserved [in, optional]
This parameter is reserved and must be NULL.
Return Value
This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.(异常结果)
- S_OK
The COM library was initialized successfully on this thread.(成功初始化)
- S_FALSE
The COM library is already initialized on this thread.(已初始化)
- RPC_E_CHANGED_MODE
A previous call to CoInitializeEx specified the concurrency model for this thread as multithread apartment (MTA). This could also indicate that a change from neutral-threaded apartment to single-threaded apartment has occurred.
(其他线程调用)3、注意:New applications should call CoInitializeEx instead of CoInitialize.
1、函数说明:Initializes the COM library for use by the calling thread, sets the thread's concurrency model, and creates a new apartment for the thread if one is required.
2、函数原型:
Syntax
HRESULT CoInitializeEx( __in_opt LPVOID pvReserved, __in DWORD dwCoInit);
Parameters
- pvReserved [in, optional]
This parameter is reserved and must be NULL.
- dwCoInit [in]
The concurrency model and initialization options for the thread. Values for this parameter are taken from theCOINIT enumeration. Any combination of values from COINIT can be used, except that the COINIT_APARTMENTTHREADED and COINIT_MULTITHREADED flags cannot both be set. The default is COINIT_MULTITHREADED.
Return Value
This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values.
- S_OK
The COM library was initialized successfully on this thread.
- S_FALSE
The COM library is already initialized on this thread.
- RPC_E_CHANGED_MODE
A previous call to CoInitializeEx specified the concurrency model for this thread as multithread apartment (MTA). This could also indicate that a change from neutral-threaded apartment to single-threaded apartment has occurred.
Syntax
void OleUninitialize(void);
Parameters
This function has no parameters.Return Value
This function does not return a value.
3、OleUninitialize calls the CoUninitialize function internally to shut down the OLE Component Object(COM) Library.
If the COM library was initialized on the apartment with a call to CoInitialize or CoInitializeEx, it must be closed with a call toCoUninitialize.
Syntax
HRESULT OleInitialize( __in LPVOID pvReserved);
Parameters
- pvReserved [in]
This parameter is reserved and must be NULL.
Return Value
This function returns S_OK on success. Other possible values include the following.
- S_FALSE
The COM library is already initialized on this apartment.
- OLE_E_WRONGCOMPOBJ
The versions of COMPOBJ.DLL and OLE2.DLL on your machine are incompatible with each other.
- RPC_E_CHANGED_MODE
A previous call to CoInitializeEx specified the concurrency model for this apartment as multithread apartment (MTA). This could also mean that a change from neutral threaded apartment to single threaded apartment occurred.
Remarks
Applications that use the following functionality must call OleInitialize before calling any other function in the COM library:
- Clipboard
- Drag and Drop
- Object linking and embedding (OLE)
- In-place activation
4、注意:
OleInitialize calls CoInitializeEx internally to initialize the COM library on the current apartment. Because OLE operations are not thread-safe, OleInitialize specifies the concurrency model as single-thread apartment.
- AfxOleInit()/CoInitialize()/CoInitializeEx()
- CoInitialize()、CoInitializeEx()和AfxOleInit()
- AfxOleInit()/CoInitialize()/CoInitializeEx()
- CoInitialize \CoInitializeEx\AfxOleInit
- CoInitialize与CoInitializeEx,AfxOleInit()的不同
- CoInitialize与CoInitializeEx,AfxOleInit()的不同
- OleInitialize、CoInitialize、CoInitializeEx和AfxOleInit()区别
- OleInitialize、CoInitialize、CoInitializeEx和AfxOleInit()区别
- OleInitialize、CoInitialize、CoInitializeEx和AfxOleInit()区别
- OleInitialize、CoInitialize、CoInitializeEx和AfxOleInit()区别
- OleInitialize、CoInitialize、CoInitializeEx和AfxOleInit()区别
- CoInitialize()、CoInitializeEx()和AfxOleInit()区别联系
- CoInitialize与CoInitializeEx,AfxOleInit()的不同 控制台程序中AfxOleInit失效原因
- CoInitialize()和AfxOleInit()区别
- AfxOleInit()和::CoInitialize(NULL)区别
- CoInitializeEx 与CoInitialize的区别
- AfxOleInit()和::CoInitialize(NULL)区别
- CoInitializeEx 与CoInitialize的区别
- 获得本机IP和DNS方法。
- 整数,小数及常用的正则表达式
- MFC在共享DLL中使用和在静态库中使用的一些问题
- 用正则表达式分割字符串
- Tumblr创始人David Karp:文艺技术男的成功之路
- AfxOleInit()/CoInitialize()/CoInitializeEx()
- 关于interface HttpServletRequest
- JVM调优总结(十)-调优方法
- Hadoop管理员的十个最佳实践
- VC 在多线程中调用Exce问题
- 潜入蓝翔技校二十天 探究蓝翔黑客真正的奥秘
- iMx把App预先装入系统
- 计算直线的交点数
- 用CMAKE同时配置64位和32位两种版本的QT