Skip to content

Commit 00add9a

Browse files
committed
Fixed formatting of file TypeLibHelper.cpp.
1 parent 9f73115 commit 00add9a

1 file changed

Lines changed: 118 additions & 118 deletions

File tree

src/shellextension/TypeLibHelper.cpp

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,134 +8,134 @@ extern HRESULT GetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName,
88

99
HRESULT GetTypeLibGuid(_In_ HINSTANCE hInstTypeLib, _In_opt_z_ LPCOLESTR lpszIndex, GUID& guid)
1010
{
11-
ZeroMemory(&guid, sizeof(GUID));
12-
TLIBATTR sTLibAttr;
13-
HRESULT hr = GetTypeLibAttribute(hInstTypeLib, lpszIndex, &sTLibAttr);
14-
if ( SUCCEEDED(hr) )
15-
guid = sTLibAttr.guid;
16-
return hr;
11+
ZeroMemory(&guid, sizeof(GUID));
12+
TLIBATTR sTLibAttr;
13+
HRESULT hr = GetTypeLibAttribute(hInstTypeLib, lpszIndex, &sTLibAttr);
14+
if (SUCCEEDED(hr))
15+
guid = sTLibAttr.guid;
16+
return hr;
1717
}
1818

1919
HRESULT GetTypeLibAttribute(_In_ HINSTANCE hInstTypeLib, _In_opt_z_ LPCOLESTR lpszIndex, _Out_ LPTLIBATTR pTLibAttr)
2020
{
21-
if ( NULL == pTLibAttr )
22-
return E_INVALIDARG;
23-
24-
ZeroMemory(pTLibAttr, sizeof(TLIBATTR));
25-
26-
CComBSTR bstrPath;
27-
CComPtr<ITypeLib> pTypeLib;
28-
HRESULT hr = AtlLoadTypeLib(hInstTypeLib, lpszIndex, &bstrPath, &pTypeLib);
29-
if ( SUCCEEDED(hr) )
30-
{
31-
TLIBATTR* ptla;
32-
hr = pTypeLib->GetLibAttr(&ptla);
33-
if ( SUCCEEDED(hr) )
34-
{
35-
*pTLibAttr = *ptla;
36-
37-
pTypeLib->ReleaseTLibAttr(ptla);
38-
}
39-
}
40-
return hr;
21+
if (NULL == pTLibAttr)
22+
return E_INVALIDARG;
23+
24+
ZeroMemory(pTLibAttr, sizeof(TLIBATTR));
25+
26+
CComBSTR bstrPath;
27+
CComPtr<ITypeLib> pTypeLib;
28+
HRESULT hr = AtlLoadTypeLib(hInstTypeLib, lpszIndex, &bstrPath, &pTypeLib);
29+
if (SUCCEEDED(hr))
30+
{
31+
TLIBATTR* ptla;
32+
hr = pTypeLib->GetLibAttr(&ptla);
33+
if (SUCCEEDED(hr))
34+
{
35+
*pTLibAttr = *ptla;
36+
37+
pTypeLib->ReleaseTLibAttr(ptla);
38+
}
39+
}
40+
return hr;
4141
}
4242

4343
HRESULT IsTypeLibRegisteredOnSystem(const GUID& guid, PCWSTR szVersion)
4444
{
45-
TLIBATTR sTLibAttr;
46-
ZeroMemory(&sTLibAttr, sizeof(TLIBATTR));
47-
sTLibAttr.guid = guid;
48-
sTLibAttr.syskind = SYS_WIN64;
49-
sTLibAttr.wMajorVerNum = 1;
50-
sTLibAttr.wMinorVerNum = 0;
51-
52-
HRESULT hr = IsTypeLibRegisteredOnSystem(&sTLibAttr);
53-
return hr;
45+
TLIBATTR sTLibAttr;
46+
ZeroMemory(&sTLibAttr, sizeof(TLIBATTR));
47+
sTLibAttr.guid = guid;
48+
sTLibAttr.syskind = SYS_WIN64;
49+
sTLibAttr.wMajorVerNum = 1;
50+
sTLibAttr.wMinorVerNum = 0;
51+
52+
HRESULT hr = IsTypeLibRegisteredOnSystem(&sTLibAttr);
53+
return hr;
5454
}
5555

5656
HRESULT IsTypeLibRegisteredOnSystem(_In_ LPTLIBATTR pTLibAttr)
5757
{
58-
if ( NULL == pTLibAttr )
59-
return E_INVALIDARG;
60-
61-
HRESULT hr;
62-
63-
// guid to string
64-
wchar_t szGUID[64] = { 0 };
65-
StringFromGUID2(pTLibAttr->guid, szGUID, 64);
66-
67-
// version to string
68-
wchar_t szVersion[32] = { 0 };
69-
hr = StringCchPrintf(szVersion, ARRAYSIZE(szVersion), L"%d.%d", pTLibAttr->wMajorVerNum, pTLibAttr->wMajorVerNum);
70-
if ( FAILED(hr) )
71-
return hr;
72-
73-
// syskind to string
74-
const wchar_t * szSysKind = NULL;
75-
switch ( pTLibAttr->syskind )
76-
{
77-
case SYS_WIN32:
78-
szSysKind = L"win32";
79-
break;
80-
case SYS_WIN64:
81-
szSysKind = L"win64";
82-
break;
83-
default:
84-
return HRESULT_FROM_WIN32(ERROR_INVALID_FLAGS);
85-
};
86-
87-
// Check for the "HKCR\TypeLib\{guid}\{version}" key.
88-
wchar_t szSubkey[MAX_PATH];
89-
hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"TypeLib\\%s\\%s", szGUID, szVersion);
90-
if ( FAILED(hr) )
91-
return hr;
92-
93-
// Get the TypeLib name
94-
wchar_t szTypeLibName[MAX_PATH];
95-
hr = GetHKCRRegistryKeyAndValue(szSubkey, nullptr, szTypeLibName, sizeof(szTypeLibName));
96-
if ( FAILED(hr) )
97-
{
98-
if ( hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )
99-
return S_FALSE;
100-
return hr; // unexpected error
101-
}
102-
103-
// If TypeLib name is empty.
104-
if ( szTypeLibName[0] == L'\0' )
105-
return S_FALSE;
106-
107-
// Check for the "HKCR\TypeLib\{guid}\{version}\0\{syskind}" key.
108-
hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"TypeLib\\%s\\%s\\0\\%s", szGUID, szVersion, szSysKind);
109-
if ( FAILED(hr) )
110-
return hr;
111-
112-
// Get the TypeLib dll path
113-
wchar_t szDllPath[MAX_PATH];
114-
hr = GetHKCRRegistryKeyAndValue(szSubkey, nullptr, szDllPath, sizeof(szDllPath));
115-
if ( FAILED(hr) )
116-
{
117-
if ( hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )
118-
return S_FALSE;
119-
return hr; // unexpected error
120-
}
121-
122-
// If TypeLib dll path is empty.
123-
if ( szDllPath[0] == L'\0' )
124-
return S_FALSE;
125-
126-
//// Get path to current module
127-
//wchar_t szModule[MAX_PATH];
128-
//HINSTANCE hInst = GetModuleHandle(NULL);
129-
//hr = S_OK;
130-
//if ( GetModuleFileName(hInst, szModule, ARRAYSIZE(szModule)) == 0 )
131-
//{
132-
// hr = HRESULT_FROM_WIN32(GetLastError());
133-
// return hr;
134-
//}
135-
136-
//// If TypeLib dll path is not this module's path.
137-
//if ( _wcsicmp(szDllPath, szModule) == 0)
138-
// return S_FALSE;
139-
140-
return S_OK;
58+
if (NULL == pTLibAttr)
59+
return E_INVALIDARG;
60+
61+
HRESULT hr;
62+
63+
// guid to string
64+
wchar_t szGUID[64] = { 0 };
65+
StringFromGUID2(pTLibAttr->guid, szGUID, 64);
66+
67+
// version to string
68+
wchar_t szVersion[32] = { 0 };
69+
hr = StringCchPrintf(szVersion, ARRAYSIZE(szVersion), L"%d.%d", pTLibAttr->wMajorVerNum, pTLibAttr->wMajorVerNum);
70+
if (FAILED(hr))
71+
return hr;
72+
73+
// syskind to string
74+
const wchar_t* szSysKind = NULL;
75+
switch (pTLibAttr->syskind)
76+
{
77+
case SYS_WIN32:
78+
szSysKind = L"win32";
79+
break;
80+
case SYS_WIN64:
81+
szSysKind = L"win64";
82+
break;
83+
default:
84+
return HRESULT_FROM_WIN32(ERROR_INVALID_FLAGS);
85+
};
86+
87+
// Check for the "HKCR\TypeLib\{guid}\{version}" key.
88+
wchar_t szSubkey[MAX_PATH];
89+
hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"TypeLib\\%s\\%s", szGUID, szVersion);
90+
if (FAILED(hr))
91+
return hr;
92+
93+
// Get the TypeLib name
94+
wchar_t szTypeLibName[MAX_PATH];
95+
hr = GetHKCRRegistryKeyAndValue(szSubkey, nullptr, szTypeLibName, sizeof(szTypeLibName));
96+
if (FAILED(hr))
97+
{
98+
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
99+
return S_FALSE;
100+
return hr; // unexpected error
101+
}
102+
103+
// If TypeLib name is empty.
104+
if (szTypeLibName[0] == L'\0')
105+
return S_FALSE;
106+
107+
// Check for the "HKCR\TypeLib\{guid}\{version}\0\{syskind}" key.
108+
hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"TypeLib\\%s\\%s\\0\\%s", szGUID, szVersion, szSysKind);
109+
if (FAILED(hr))
110+
return hr;
111+
112+
// Get the TypeLib dll path
113+
wchar_t szDllPath[MAX_PATH];
114+
hr = GetHKCRRegistryKeyAndValue(szSubkey, nullptr, szDllPath, sizeof(szDllPath));
115+
if (FAILED(hr))
116+
{
117+
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
118+
return S_FALSE;
119+
return hr; // unexpected error
120+
}
121+
122+
// If TypeLib dll path is empty.
123+
if (szDllPath[0] == L'\0')
124+
return S_FALSE;
125+
126+
//// Get path to current module
127+
//wchar_t szModule[MAX_PATH];
128+
//HINSTANCE hInst = GetModuleHandle(NULL);
129+
//hr = S_OK;
130+
//if ( GetModuleFileName(hInst, szModule, ARRAYSIZE(szModule)) == 0 )
131+
//{
132+
// hr = HRESULT_FROM_WIN32(GetLastError());
133+
// return hr;
134+
//}
135+
136+
//// If TypeLib dll path is not this module's path.
137+
//if ( _wcsicmp(szDllPath, szModule) == 0)
138+
// return S_FALSE;
139+
140+
return S_OK;
141141
}

0 commit comments

Comments
 (0)