home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / DTS / dtsxform / dtsxform.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  3.6 KB  |  132 lines

  1. // dtsxform.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //        To build a separate proxy/stub DLL, 
  6. //        run nmake -f dtsxformps.mk in the project directory.
  7.  
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include "initguid.h"
  11. #include "dtsxform.h"
  12.  
  13. #include "dtsxform_i.c"
  14. #include "Xform.h"
  15. //category manager stuff
  16. #include <comcat.h>
  17.  
  18.  
  19. CComModule _Module;
  20.  
  21. STDAPI RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
  22. STDAPI UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
  23.  
  24.  
  25. BEGIN_OBJECT_MAP(ObjectMap)
  26.     OBJECT_ENTRY(CLSID_DTSStrCatXform, CXform)
  27. END_OBJECT_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // DLL Entry Point
  31.  
  32. extern "C"
  33. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  34. {
  35.     if (dwReason == DLL_PROCESS_ATTACH)
  36.     {
  37.         _Module.Init(ObjectMap, hInstance);
  38.         DisableThreadLibraryCalls(hInstance);
  39.     }
  40.     else if (dwReason == DLL_PROCESS_DETACH)
  41.         _Module.Term();
  42.     return TRUE;    // ok
  43. }
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Used to determine whether the DLL can be unloaded by OLE
  47.  
  48. STDAPI DllCanUnloadNow(void)
  49. {
  50.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  51. }
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // Returns a class factory to create an object of the requested type
  55.  
  56. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  57. {
  58.     return _Module.GetClassObject(rclsid, riid, ppv);
  59. }
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // DllRegisterServer - Adds entries to the system registry
  63.  
  64. STDAPI DllRegisterServer(void)
  65. {
  66.     HRESULT hr;
  67.     // registers object, typelib and all interfaces in typelib
  68.      hr = _Module.RegisterServer(TRUE);
  69.      if (SUCCEEDED(hr))
  70.      {
  71.          //Do this for every transform clsid in this dll
  72.         hr = RegisterCLSIDInCategory(CLSID_DTSStrCatXform, CATID_DTSCustomXform);
  73.      }
  74.      return hr;
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // DllUnregisterServer - Removes entries from the system registry
  79.  
  80. STDAPI DllUnregisterServer(void)
  81. {
  82.     _Module.UnregisterServer();
  83.     {
  84.          //Do this for every transform clsid in this dll
  85.         RegisterCLSIDInCategory(CLSID_DTSStrCatXform, CATID_DTSCustomXform);
  86.     }
  87.     return S_OK;
  88. }
  89.  
  90.  
  91. //Utility functions to do DTS specific registry entries
  92. //component category stuff..probably should be moved into oleutil
  93. STDAPI RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  94. {
  95.    // Register your component categories information.
  96.    ICatRegister* pcr = NULL ;
  97.    HRESULT hr = S_OK ;
  98.    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  99.    if (SUCCEEDED(hr))
  100.       {
  101.       // Register this category as being "implemented" by the class.
  102.       CATID rgcatid[1] ;
  103.       rgcatid[0] = catid;
  104.       hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
  105.       }
  106.  
  107.    if (pcr != NULL)
  108.       pcr->Release();
  109.  
  110.    return hr;
  111. }
  112.  
  113. STDAPI UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
  114. {
  115.    ICatRegister* pcr = NULL ;
  116.    HRESULT hr = S_OK ;
  117.    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
  118.    if (SUCCEEDED(hr))
  119.       {
  120.       // Unregister this category as being "implemented" by the class.
  121.       CATID rgcatid[1] ;
  122.       rgcatid[0] = catid;
  123.       hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
  124.       }
  125.  
  126.    if (pcr != NULL)
  127.       pcr->Release();
  128.  
  129.    return hr;
  130. }
  131.  
  132.