home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F37023_MDDlog2.cpp < prev    next >
Encoding:
Text File  |  2001-10-16  |  2.2 KB  |  78 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11.  
  12. HRESULT GetImsigxPath(LPTSTR lpszPath)
  13. {
  14.     OLECHAR subKey[_MAX_PATH];
  15.  
  16.     wcscpy(subKey, L"CLSID\\");
  17.     OLECHAR* pGuid = wcschr(subKey, 0);
  18.     if (::StringFromGUID2(CLSID_XApplication, pGuid, _MAX_PATH) == 0)
  19.         return E_FAIL;
  20.     wcscat(subKey, L"\\InProcServer32");
  21.  
  22.     HKEY hKey;
  23.     if (::RegOpenKeyExW(
  24.         HKEY_CLASSES_ROOT,    // handle of open key 
  25.         subKey,    // address of name of subkey to open 
  26.         0,    // reserved 
  27.         KEY_READ,    // security access mask 
  28.         &hKey)     // address of handle of open key 
  29.         != ERROR_SUCCESS)
  30.         return E_FAIL;
  31.  
  32.     DWORD dwType;
  33.     DWORD dwData;
  34.     LONG lResult = ::RegQueryValueEx(
  35.         hKey,    // handle of key to query 
  36.         NULL,    // address of name of value to query 
  37.         NULL,    // reserved 
  38.         &dwType,    // address of buffer for value type 
  39.         (LPBYTE)lpszPath,    // address of data buffer 
  40.         &dwData);     // address of data buffer size 
  41.    
  42.     ::RegCloseKey(hKey);
  43.     return (lResult == ERROR_SUCCESS) ? S_OK : E_FAIL;
  44. }
  45.  
  46. void CMakeDwgDlg::OnInprocServer()
  47. {
  48.     TCHAR szIMSIGXDLL[_MAX_PATH];
  49.     HRESULT hRes = GetImsigxPath(szIMSIGXDLL);
  50.     if (SUCCEEDED(hRes))
  51.     {
  52.         hRes = E_FAIL;
  53.         HINSTANCE hMod = ::LoadLibrary(szIMSIGXDLL);
  54.         if (hMod != NULL)
  55.         {
  56.             HRESULT (*GetApp)(IApplication**) = 
  57.                 (HRESULT (*)(IApplication**))
  58.                 ::GetProcAddress(hMod, "IMSIGXGetXApplication");
  59.             if (GetApp != NULL)
  60.                 hRes = (*GetApp)(&m_pIApplication);
  61.             // ::FreeLibrary(szIMSIGXDLL);
  62.         }
  63.         else
  64.         {
  65.             DWORD dwLastError = GetLastError();
  66.             hRes = E_FAIL;
  67.         }
  68.     }
  69.  
  70.     if (FAILED(hRes))
  71.     {
  72.         AfxMessageBox("Couldn't create application object (in-process server)!");
  73.     }
  74.  
  75.     EnableButtons();
  76. }
  77.  
  78.