d0917b201b2e9a275bb1f3511b781ef55d52ca24
[openafs.git] / src / WINNT / client_exp / afs_shl_ext.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "stdafx.h"
16 #include "afs_shl_ext.h"
17 #include <winsock2.h>
18 #include "help.h"
19 #include "shell_ext.h"
20
21 #ifdef _DEBUG
22 #define new DEBUG_NEW
23 #undef THIS_FILE
24 static char THIS_FILE[] = __FILE__;
25 #endif
26
27
28 /////////////////////////////////////////////////////////////////////////////
29 // CAfsShlExt
30
31 BEGIN_MESSAGE_MAP(CAfsShlExt, CWinApp)
32         //{{AFX_MSG_MAP(CAfsShlExt)
33                 // NOTE - the ClassWizard will add and remove mapping macros here.
34                 //    DO NOT EDIT what you see in these blocks of generated code!
35         //}}AFX_MSG_MAP
36 END_MESSAGE_MAP()
37
38 /////////////////////////////////////////////////////////////////////////////
39 // CAfsShlExt construction
40
41 CAfsShlExt::CAfsShlExt()
42 {
43         /* Start up sockets */
44         WSADATA WSAjunk;
45         WSAStartup(0x0101, &WSAjunk);
46 }
47
48 /////////////////////////////////////////////////////////////////////////////
49 // The one and only CAfsShlExt object
50
51 CAfsShlExt theApp;
52
53 /////////////////////////////////////////////////////////////////////////////
54 // CAfsShlExt initialization
55
56 BOOL CAfsShlExt::InitInstance()
57 {
58         // Load our translated resources
59         TaLocale_LoadCorrespondingModule (m_hInstance);
60
61         // Register all OLE server (factories) as running.  This enables the
62         //  OLE libraries to create objects from other applications.
63         COleObjectFactory::RegisterAll();
64
65         SetHelpPath(m_pszHelpFilePath);
66
67         return TRUE;
68 }
69
70 /////////////////////////////////////////////////////////////////////////////
71 // Special entry points required for inproc servers
72
73 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
74 {
75         AFX_MANAGE_STATE(AfxGetStaticModuleState());
76         return AfxDllGetClassObject(rclsid, riid, ppv);
77 }
78
79 STDAPI DllCanUnloadNow(void)
80 {
81         AFX_MANAGE_STATE(AfxGetStaticModuleState());
82
83         if (!nCMRefCount && !nSERefCount && !nICRefCount && !nTPRefCount && !nXPRefCount)
84                 return S_OK;
85
86         return S_FALSE;
87 }
88
89 // by exporting DllRegisterServer, you can use regsvr.exe
90 STDAPI DllRegisterServer(void)
91 {
92         int      i;
93         HKEY     hKey;
94         LRESULT  lResult;
95         DWORD    dwDisp;
96         TCHAR    szSubKey[MAX_PATH];
97         TCHAR    szCLSID[MAX_PATH];
98         TCHAR    szModule[MAX_PATH];
99         LPWSTR   pwsz;
100         AFX_MANAGE_STATE(AfxGetStaticModuleState());
101         COleObjectFactory::UpdateRegistryAll();
102         wsprintf(szSubKey, TEXT("%s\\%s"), STR_REG_PATH, STR_EXT_TITLE);
103         lResult = RegCreateKeyEx(  HKEY_LOCAL_MACHINE,
104                                                         szSubKey,
105                                                         0,
106                                                         NULL,
107                                                         REG_OPTION_NON_VOLATILE,
108                                                         KEY_WRITE,
109                                                         NULL,
110                                                         &hKey,
111                                                         &dwDisp);
112
113         if(NOERROR == lResult)
114         {
115         //Create the value string.
116                 lResult = RegSetValueEx(   hKey,
117                                                                 NULL,
118                                                                 0,
119                                                                 REG_SZ,
120                                                                 (LPBYTE)szCLSID,
121                                                                 (lstrlen(szCLSID) + 1) * sizeof(TCHAR));
122                 RegCloseKey(hKey);
123         }
124         else
125                 return SELFREG_E_CLASS;
126
127         //If running on NT, register the extension as approved.
128         OSVERSIONINFO  osvi;
129         osvi.dwOSVersionInfoSize = sizeof(osvi);
130         GetVersionEx(&osvi);
131         if(VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
132         {
133                 lstrcpy( szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
134
135                 lResult = RegCreateKeyEx(  HKEY_LOCAL_MACHINE,
136                                                                 szSubKey,
137                                                                 0,
138                                                                 NULL,
139                                                                 REG_OPTION_NON_VOLATILE,
140                                                                 KEY_WRITE,
141                                                                 NULL,
142                                                                 &hKey,
143                                                                 &dwDisp);
144
145                 if(NOERROR == lResult)
146                 {
147                         TCHAR szData[MAX_PATH];
148
149                 //Create the value string.
150                         lstrcpy(szData, STR_EXT_TITLE);
151
152                         lResult = RegSetValueEx(   hKey,
153                                                                         szCLSID,
154                                                                         0,
155                                                                         REG_SZ,
156                                                                         (LPBYTE)szData,
157                                                                         (lstrlen(szData) + 1) * sizeof(TCHAR));
158               
159                         RegCloseKey(hKey);
160                 } else
161                         return SELFREG_E_CLASS;
162         }
163         return S_OK;
164 }