home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / wins / wins.cpp < prev    next >
C/C++ Source or Header  |  1998-04-08  |  3KB  |  127 lines

  1. // wins.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //      To build a separate proxy/stub DLL, 
  6. //      run nmake -f winsps.mk in the project directory.
  7.  
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include <initguid.h>
  11. #include "wins.h"
  12. #include "winsapp.h"
  13.  
  14. #include "wins_i.c"
  15. #include "WindowsList.h"
  16.  
  17.  
  18. CComModule _Module;
  19.  
  20. BEGIN_OBJECT_MAP(ObjectMap)
  21. OBJECT_ENTRY(CLSID_WindowsList, CWindowsList)
  22. END_OBJECT_MAP()
  23.  
  24. BEGIN_MESSAGE_MAP(CWinsApp, CWinApp)
  25.     //{{AFX_MSG_MAP(CWinsApp)
  26.         // NOTE - the ClassWizard will add and remove mapping macros here.
  27.         //    DO NOT EDIT what you see in these blocks of generated code!
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. CString strMainKey = _T("Software\\Microsoft\\devstudio\\AddIns\\Wins.WindowsList.1\\");
  32. // don't put in 6.0 key as this will make msdev think it is already registered.
  33. // Then msdev crashes because it gets an empty CString and does a memcpy on it.
  34.  
  35.  
  36. CWinsApp theApp;
  37.  
  38. BOOL CWinsApp::InitInstance()
  39. {
  40.     _Module.Init(ObjectMap, m_hInstance, &LIBID_WINSLib);
  41.     CRegKey regKey;
  42.  
  43.     long lRes;
  44.     unsigned long lCol, lSize;
  45.  
  46.     lRes = regKey.Create(HKEY_CURRENT_USER, strMainKey);
  47.     if (SUCCEEDED(lRes))
  48.     {
  49.         regKey.QueryValue(m_fAutoSize, _T("AutoSize"));
  50.         regKey.QueryValue(m_fAutoVis, _T("AutoVis"));
  51.         regKey.QueryValue(m_fAutoDir, _T("AutoDir"));
  52.         regKey.QueryValue(lCol, _T("SortedCol"));
  53.         m_iSortedCol = (int)lCol;
  54.         regKey.QueryValue(lSize, _T("Width"));
  55.         if (lSize == 0)
  56.             lSize = DEFAULTWIDTH;
  57.         m_lSize = (int)lSize;
  58.     }
  59.     return CWinApp::InitInstance();
  60. }
  61.  
  62. int CWinsApp::ExitInstance()
  63. {
  64.     CRegKey regKey;
  65.     long lRes;
  66.  
  67.     lRes = regKey.Create(HKEY_CURRENT_USER, strMainKey);
  68.     regKey.SetValue(m_fAutoSize, _T("AutoSize"));
  69.     regKey.SetValue(m_fAutoVis, _T("AutoVis"));
  70.     regKey.SetValue(m_fAutoDir, _T("AutoDir"));
  71.     regKey.SetValue(m_iSortedCol, _T("SortedCol"));
  72.     regKey.SetValue(m_lSize, _T("Width"));
  73.  
  74.     _Module.Term();
  75.     return CWinApp::ExitInstance();
  76. }
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Used to determine whether the DLL can be unloaded by OLE
  80.  
  81. STDAPI DllCanUnloadNow(void)
  82. {
  83.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  84.     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // Returns a class factory to create an object of the requested type
  89.  
  90. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  91. {
  92.     return _Module.GetClassObject(rclsid, riid, ppv);
  93. }
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DllRegisterServer - Adds entries to the system registry
  97.  
  98. STDAPI DllRegisterServer(void)
  99. {
  100.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  101.     // registers object, typelib and all interfaces in typelib
  102.      // Register description of this add-in object in its own
  103.     //  "/Description" subkey.
  104.     
  105.  
  106.    return _Module.RegisterServer(TRUE);
  107. }
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // DllUnregisterServer - Removes entries from the system registry
  111.  
  112. STDAPI DllUnregisterServer(void)
  113. {
  114.     HRESULT hr = _Module.UnregisterServer();
  115.  
  116. #if _WIN32_WINNT >= 0x0400
  117.     if (FAILED(hr))
  118.         return hr;
  119.  
  120.     hr = UnRegisterTypeLib(LIBID_WINSLib, 1, 0, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SYS_WIN32);
  121. #endif
  122.  
  123.     return hr;
  124. }
  125.  
  126.  
  127.