Skip to content

Commit aedf73e

Browse files
committed
Statically link undocumented shell32 functions (but better this time)
1 parent 91fb460 commit aedf73e

6 files changed

Lines changed: 40 additions & 26 deletions

File tree

src/OpenWithEx.vcxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@
1818
<Platform>x64</Platform>
1919
</ProjectConfiguration>
2020
</ItemGroup>
21+
<ItemGroup Condition="'$(Platform)'=='Win32'">
22+
<_DefToLib Include="defs\Win32\*.def" />
23+
</ItemGroup>
24+
<ItemGroup Condition="'$(Platform)'!='Win32'">
25+
<_DefToLib Include="defs\Win64\*.def" />
26+
</ItemGroup>
27+
<Target Name="_GenerateDefLib" BeforeTargets="Link" Inputs="@(_DefToLib)" Outputs="@(_DefToLib->'$(IntDir)%(Filename).lib')">
28+
<Exec Command="lib /nologo /def:&quot;%(_DefToLib.Identity)&quot; /machine:$(PlatformTargetAsMSBuildArchitecture) /out:&quot;$(IntDir)%(Filename).lib&quot;" />
29+
</Target>
30+
<PropertyGroup>
31+
<_GeneratedLibs>@(_DefToLib->'%(Filename).lib')</_GeneratedLibs>
32+
</PropertyGroup>
33+
<ItemDefinitionGroup>
34+
<Link>
35+
<AdditionalLibraryDirectories>$(IntDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
36+
<AdditionalDependencies>$(_GeneratedLibs);%(AdditionalDependencies)</AdditionalDependencies>
37+
</Link>
38+
</ItemDefinitionGroup>
2139
<PropertyGroup Label="Globals">
2240
<VCProjectVersion>17.0</VCProjectVersion>
2341
<Keyword>Win32Proj</Keyword>
@@ -396,6 +414,10 @@ del "$(IntermediateOutputPath)temp.res"</Command>
396414
<ItemGroup>
397415
<Xml Include="muiconfig.xml" />
398416
</ItemGroup>
417+
<ItemGroup>
418+
<None Include="defs\Win32\shell32p.def" />
419+
<None Include="defs\Win64\shell32p.def" />
420+
</ItemGroup>
399421
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
400422
<ImportGroup Label="ExtensionTargets">
401423
</ImportGroup>

src/OpenWithEx.vcxproj.filters

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,12 @@
236236
<ItemGroup>
237237
<Xml Include="muiconfig.xml" />
238238
</ItemGroup>
239+
<ItemGroup>
240+
<None Include="defs\Win32\shell32p.def">
241+
<Filter>Source Files</Filter>
242+
</None>
243+
<None Include="defs\Win64\shell32p.def">
244+
<Filter>Source Files</Filter>
245+
</None>
246+
</ItemGroup>
239247
</Project>

src/defs/Win32/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@16 @765 NONAME
4+
IsBlockedFromOpenWithBrowse@4 @779 NONAME

src/defs/Win64/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

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

0 commit comments

Comments
 (0)