home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / Extension / Tutorial / step2 / ADsFirstExt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-28  |  3.7 KB  |  157 lines

  1. // ADsFirstExt.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //      To build a separate proxy/stub DLL, 
  6. //      run nmake -f ADsFirstExtps.mk in the project directory.
  7.  
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include <initguid.h>
  11. #include "ADsFirstExt.h"
  12.  
  13. #include "ADsFirstExt_i.c"
  14. #include "HelloWorld.h"
  15.  
  16.  
  17. CComModule _Module;
  18.  
  19. BEGIN_OBJECT_MAP(ObjectMap)
  20. OBJECT_ENTRY(CLSID_HelloWorld, HelloWorld)
  21. END_OBJECT_MAP()
  22.  
  23. class CADsFirstExtApp : public CWinApp
  24. {
  25. public:
  26.  
  27. // Overrides
  28.     // ClassWizard generated virtual function overrides
  29.     //{{AFX_VIRTUAL(CADsFirstExtApp)
  30.     public:
  31.     virtual BOOL InitInstance();
  32.     virtual int ExitInstance();
  33.     //}}AFX_VIRTUAL
  34.  
  35.     //{{AFX_MSG(CADsFirstExtApp)
  36.         // NOTE - the ClassWizard will add and remove member functions here.
  37.         //    DO NOT EDIT what you see in these blocks of generated code !
  38.     //}}AFX_MSG
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42.  
  43. STDAPI RegisterADsExt(void);
  44. STDAPI UnRegisterADsExt(void);
  45.  
  46. BEGIN_MESSAGE_MAP(CADsFirstExtApp, CWinApp)
  47.     //{{AFX_MSG_MAP(CADsFirstExtApp)
  48.         // NOTE - the ClassWizard will add and remove mapping macros here.
  49.         //    DO NOT EDIT what you see in these blocks of generated code!
  50.     //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52.  
  53. CADsFirstExtApp theApp;
  54.  
  55. BOOL CADsFirstExtApp::InitInstance()
  56. {
  57.     _Module.Init(ObjectMap, m_hInstance, &LIBID_ADSFIRSTEXTLib);
  58.     return CWinApp::InitInstance();
  59. }
  60.  
  61. int CADsFirstExtApp::ExitInstance()
  62. {
  63.     _Module.Term();
  64.     return CWinApp::ExitInstance();
  65. }
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Used to determine whether the DLL can be unloaded by OLE
  69.  
  70. STDAPI DllCanUnloadNow(void)
  71. {
  72.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  73.     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  74. }
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // Returns a class factory to create an object of the requested type
  78.  
  79. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  80. {
  81.     return _Module.GetClassObject(rclsid, riid, ppv);
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // DllRegisterServer - Adds entries to the system registry
  86.  
  87. STDAPI DllRegisterServer(void)
  88. {
  89.     // registers object, typelib and all interfaces in typelib
  90.     if ( SUCCEEDED(_Module.RegisterServer(TRUE) ) )
  91.     {
  92.          return RegisterADsExt();
  93.     }
  94.     return E_FAIL;
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // DllUnregisterServer - Removes entries from the system registry
  99.  
  100. STDAPI DllUnregisterServer(void)
  101. {
  102.     UnRegisterADsExt();
  103.     return _Module.UnregisterServer(TRUE);
  104. }
  105.  
  106. STDAPI RegisterADsExt(void)
  107. {
  108.     HRESULT hr;
  109.     HKEY hKey;
  110.     DWORD dwDisposition;
  111.     
  112.  
  113.     hr = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  114.                          _T("SOFTWARE\\Microsoft\\ADs\\Providers\\LDAP\\Extensions\\User\\{E1E3EDF8-48D1-11D2-B22B-0000F87A6B50}"),
  115.                          0,
  116.                          NULL,
  117.                          REG_OPTION_NON_VOLATILE,
  118.                          KEY_WRITE,
  119.                          NULL,
  120.                          &hKey,
  121.                          &dwDisposition );
  122.  
  123.     if ( !SUCCEEDED(hr) )
  124.     {
  125.         return hr;
  126.     }
  127.      
  128.  
  129.     ///////////////////////////////////////////
  130.     // Interface
  131.     //////////////////////////////////////////// 
  132.     const wchar_t szIf[] = L"{E1E3EDF7-48D1-11D2-B22B-0000F87A6B50}\0\0";
  133.  
  134.  
  135.     hr = RegSetValueEx( hKey, _T("Interfaces"), 0, REG_BINARY, (const BYTE *) szIf, sizeof(szIf));
  136.     
  137.     RegCloseKey(hKey);
  138.  
  139.     return hr;
  140. }
  141.  
  142.  
  143. STDAPI UnRegisterADsExt(void)
  144. {
  145.  
  146.     LONG lResult;
  147.     lResult = RegDeleteKey(  HKEY_LOCAL_MACHINE,        
  148.         _T("SOFTWARE\\Microsoft\\ADs\\Providers\\LDAP\\Extensions\\User\\{E1E3EDF8-48D1-11D2-B22B-0000F87A6B50}") );
  149.  
  150.     if ( lResult ==    ERROR_SUCCESS )
  151.     {
  152.         return S_OK;
  153.  
  154.     }
  155.  
  156.     return E_FAIL;
  157. }