Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92899
  • 博文数量: 50
  • 博客积分: 1086
  • 博客等级: 少尉
  • 技术积分: 420
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-25 16:16
文章分类
文章存档

2011年(50)

我的朋友

分类: C/C++

2011-11-15 19:26:44

"MyGuids.h"
#pragma once
#include
DEFINE_GUID(IID_IX,
   0x32bb8320, 0xb41b, 0x11cf, 0xa6, 0xbb, 0x0, 0x80, 0xc7, 0xb2, 0xd6, 0x82);
______________________________________________________________________
"Iface.h"
#pragma once
#include
// Interfaces
interface IX : IUnknown
{
       virtual void __stdcall Fx() = 0 ;
} ;
_______________________________________________________________________
 
"***.cpp"
#include "stdafx.h"
#include
#include "Iface.h"
#include
#include
#include "MyGuids.h"
using namespace std;
void trace(const char* msg) { cout << "Component 1:\t" << msg << endl ;}
//
// Component
//
class CA : public IX
{
 // IUnknown implementation
 virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv) ;   
 virtual ULONG __stdcall AddRef() ;
 virtual ULONG __stdcall Release() ;  
 // Interface IX implementation
 virtual void __stdcall Fx() { cout << "Fx" << endl ;}
public:
 // Constructor
 CA() : m_cRef(0) {}
 // Destructor
 ~CA() { trace("Destroy self.") ;}
private:
 long m_cRef ;
} ;
HRESULT __stdcall CA::QueryInterface(const IID& iid, void** ppv)
{  
 if (iid == IID_IUnknown)
 {
  trace("Return pointer to IUnknown.") ;
  *ppv = static_cast(this) ;
 }
 else if (iid == IID_IX)
 {
  trace("Return pointer to IX.") ;
  *ppv = static_cast(this) ;
 }
 else
 {     
  trace("Interface not supported.") ;
  *ppv = NULL ;
  return E_NOINTERFACE ;
 }
 reinterpret_cast(*ppv)->AddRef() ;
 return S_OK ;
}
ULONG __stdcall CA::AddRef()
{
 return InterlockedIncrement(&m_cRef) ;
}
ULONG __stdcall CA::Release()
{
 if (InterlockedDecrement(&m_cRef) == 0)
 {
  delete this ;
  return 0 ;
 }
 return m_cRef ;
}
//
// Creation function
//
extern "C" IUnknown* CreateInstance()
{
 IUnknown* pI = static_cast(new CA) ;
 pI->AddRef() ;
 return pI ;
}
return pI ;
}
___________________________________________________________________________
"***.def"

LIBRARY         Cmpnt1.dll
DESCRIPTION     '(c)1996-1997 Dale E. Rogerson'
EXPORTS
                CreateInstance @1 PRIVATE
阅读(499) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~