Skip to content

Commit 757d271

Browse files
committed
Statically link undocumented shell32 functions
1 parent 275bb1a commit 757d271

5 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/OpenWithEx.vcxproj

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<SubSystem>Windows</SubSystem>
109109
<GenerateDebugInformation>true</GenerateDebugInformation>
110110
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
111-
<AdditionalDependencies>shell32.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
111+
<AdditionalDependencies>shell32.lib;$(OutDir)shell32p.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
112112
<AdditionalManifestDependencies>"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'";%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
113113
</Link>
114114
<ResourceCompile>
@@ -145,6 +145,9 @@ muirct -c "$(TargetPath)" -e "$(OutDir)ko-KR\$(TargetFileName).mui"
145145

146146
del "$(IntermediateOutputPath)temp.res"</Command>
147147
</PostBuildEvent>
148+
<PreBuildEvent>
149+
<Command>lib /def:shell32p.def /machine:$(PlatformTargetAsMSBuildArchitecture) /out:"$(OutDir)shell32p.lib"</Command>
150+
</PreBuildEvent>
148151
</ItemDefinitionGroup>
149152
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
150153
<ClCompile>
@@ -164,7 +167,7 @@ del "$(IntermediateOutputPath)temp.res"</Command>
164167
<OptimizeReferences>true</OptimizeReferences>
165168
<GenerateDebugInformation>true</GenerateDebugInformation>
166169
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
167-
<AdditionalDependencies>shell32.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
170+
<AdditionalDependencies>shell32.lib;$(OutDir)shell32p.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
168171
<AdditionalManifestDependencies>"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'";%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
169172
</Link>
170173
<ResourceCompile>
@@ -201,6 +204,9 @@ muirct -c "$(TargetPath)" -e "$(OutDir)ko-KR\$(TargetFileName).mui"
201204

202205
del "$(IntermediateOutputPath)temp.res"</Command>
203206
</PostBuildEvent>
207+
<PreBuildEvent>
208+
<Command>lib /def:shell32p.def /machine:$(PlatformTargetAsMSBuildArchitecture) /out:"$(OutDir)shell32p.lib"</Command>
209+
</PreBuildEvent>
204210
</ItemDefinitionGroup>
205211
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
206212
<ClCompile>
@@ -218,7 +224,7 @@ del "$(IntermediateOutputPath)temp.res"</Command>
218224
<SubSystem>Windows</SubSystem>
219225
<GenerateDebugInformation>true</GenerateDebugInformation>
220226
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
221-
<AdditionalDependencies>shell32.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
227+
<AdditionalDependencies>shell32.lib;$(OutDir)shell32p.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
222228
<AdditionalManifestDependencies>"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'";%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
223229
</Link>
224230
<ResourceCompile>
@@ -255,6 +261,9 @@ muirct -c "$(TargetPath)" -e "$(OutDir)ko-KR\$(TargetFileName).mui"
255261

256262
del "$(IntermediateOutputPath)temp.res"</Command>
257263
</PostBuildEvent>
264+
<PreBuildEvent>
265+
<Command>lib /def:shell32p.def /machine:$(PlatformTargetAsMSBuildArchitecture) /out:"$(OutDir)shell32p.lib"</Command>
266+
</PreBuildEvent>
258267
</ItemDefinitionGroup>
259268
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
260269
<ClCompile>
@@ -275,7 +284,7 @@ del "$(IntermediateOutputPath)temp.res"</Command>
275284
<OptimizeReferences>true</OptimizeReferences>
276285
<GenerateDebugInformation>true</GenerateDebugInformation>
277286
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
278-
<AdditionalDependencies>shell32.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
287+
<AdditionalDependencies>shell32.lib;$(OutDir)shell32p.lib;shlwapi.lib;comctl32.lib;uxtheme.lib;crypt32.lib;bcrypt.lib;rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
279288
<AdditionalManifestDependencies>"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'";%(AdditionalManifestDependencies)</AdditionalManifestDependencies>
280289
</Link>
281290
<ResourceCompile>
@@ -312,6 +321,9 @@ muirct -c "$(TargetPath)" -e "$(OutDir)ko-KR\$(TargetFileName).mui"
312321

313322
del "$(IntermediateOutputPath)temp.res"</Command>
314323
</PostBuildEvent>
324+
<PreBuildEvent>
325+
<Command>lib /def:shell32p.def /machine:$(PlatformTargetAsMSBuildArchitecture) /out:"$(OutDir)shell32p.lib"</Command>
326+
</PreBuildEvent>
315327
</ItemDefinitionGroup>
316328
<ItemGroup>
317329
<ClCompile Include="assocuserchoice.cpp" />
@@ -396,6 +408,9 @@ del "$(IntermediateOutputPath)temp.res"</Command>
396408
<ItemGroup>
397409
<Xml Include="muiconfig.xml" />
398410
</ItemGroup>
411+
<ItemGroup>
412+
<None Include="shell32p.def" />
413+
</ItemGroup>
399414
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
400415
<ImportGroup Label="ExtensionTargets">
401416
</ImportGroup>

src/OpenWithEx.vcxproj.filters

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,9 @@
236236
<ItemGroup>
237237
<Xml Include="muiconfig.xml" />
238238
</ItemGroup>
239+
<ItemGroup>
240+
<None Include="shell32p.def">
241+
<Filter>Source Files</Filter>
242+
</None>
243+
</ItemGroup>
239244
</Project>

src/openwithex.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ HMODULE g_hInst = nullptr;
1717
HMODULE g_hShell32 = nullptr;
1818
OPENWITHEXSTYLE g_style = OWXS_VISTA;
1919

20-
SHCreateAssocHandler_t SHCreateAssocHandler = nullptr;
21-
IsBlockedFromOpenWithBrowse_t IsBlockedFromOpenWithBrowse = nullptr;
22-
2320
WCHAR szPath[MAX_PATH] = { 0 };
2421

2522
void OpenDownloadURL(LPCWSTR pszExtension)
@@ -141,25 +138,7 @@ int WINAPI wWinMain(
141138
g_style = (OPENWITHEXSTYLE)dwValue;
142139
}
143140

144-
/* Load undocumented functions */
145141
g_hShell32 = GetModuleHandleW(L"shell32.dll");
146-
SHCreateAssocHandler = (SHCreateAssocHandler_t)GetProcAddress(
147-
g_hShell32,
148-
(LPCSTR)765 // Ordinal number
149-
);
150-
IsBlockedFromOpenWithBrowse = (IsBlockedFromOpenWithBrowse_t)GetProcAddress(
151-
g_hShell32,
152-
(LPCSTR)779
153-
);
154-
if (!SHCreateAssocHandler || !IsBlockedFromOpenWithBrowse)
155-
{
156-
LocalizedMessageBox(
157-
NULL,
158-
IDS_ERR_UNDOC,
159-
MB_ICONERROR
160-
);
161-
return -1;
162-
}
163142

164143
/**
165144
* HACKHACK: Windows loves to pass the full executable path as the first

src/openwithex.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,8 @@ enum IMMERSIVE_OPENWITH_FLAGS
4040
void OpenDownloadURL(LPCWSTR pszExtension);
4141
void ShowOpenWithDialog(HWND hWndParent, LPCWSTR lpszPath, IMMERSIVE_OPENWITH_FLAGS flags);
4242

43-
typedef HRESULT (WINAPI *SHCreateAssocHandler_t)(UINT uFlags, LPCWSTR pszExt, LPCWSTR pszApp, IAssocHandler **ppah);
44-
extern SHCreateAssocHandler_t SHCreateAssocHandler;
45-
46-
typedef bool (WINAPI *IsBlockedFromOpenWithBrowse_t)(LPCWSTR lpszPath);
47-
extern IsBlockedFromOpenWithBrowse_t IsBlockedFromOpenWithBrowse;
43+
EXTERN_C WINUSERAPI HRESULT WINAPI SHCreateAssocHandler(UINT uFlags, LPCWSTR pszExt, LPCWSTR pszApp, IAssocHandler **ppah);
44+
EXTERN_C WINUSERAPI bool WINAPI IsBlockedFromOpenWithBrowse(LPCWSTR lpszPath);
4845

4946
DEFINE_GUID(CLSID_ExecuteUnknown, 0xE44E9428, 0xBDBC, 0x4987, 0xA0,0x99, 0x40,0xDC,0x8F,0xD2,0x55,0xE7);
5047

src/shell32p.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LIBRARY SHELL32
2+
EXPORTS
3+
SHCreateAssocHandler @765 NONAME
4+
IsBlockedFromOpenWithBrowse @779 NONAME

0 commit comments

Comments
 (0)