
C++ COM 组件的构建。
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
可运行的C++ COM组件实现方法,其中C++ COM作为一种接口技术,为客户程序提供了调用其他程序的便捷途径。 现有的关于COM原理和技术的文献浩如烟海,因此在此篇章中,我们将侧重于实际的实现细节。 以下将分若干步骤对进程内COM组件进行编码,旨在清晰地理解如何构建一个COM组件,并通过COM接口方法调用DLL中的函数。 首先,我们需要创建一个标准的win32 DLL项目命名为mycom。DLL的主入口函数(dllmain)的实现如下:
```c++
DWORD g_dwAttachedProcesses = 0L; // # of attached processes
DWORD g_dwPageSize = 0L; // System page size
HINSTANCE g_hInstance = 0L; // Instance Handle
LONG g_cLock = 0L; // # of outstanding objects
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
BOOL fRetVal = FALSE;
SYSTEM_INFO SystemInformation;
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
// Assume successfully initialized
fRetVal = TRUE;
// Do one-time initialization when first process attaches
if(!g_dwAttachedProcesses)
{
g_hInstance = (HINSTANCE)hModule;
// Get the system page size
if(!g_dwPageSize) { GetSystemInfo( &SystemInformation ); // cant fail } g_dwPageSize = SystemInformation.dwPageSize;
}
}
return fRetVal;
}
```
全部评论 (0)


