ReactOS 0.4.16-dev-251-ga17b6e9
SHLoadIndirectString.c File Reference
#include <apitest.h>
#include <shlwapi.h>
#include "resource.h"
#include <pseh/pseh2.h>
Include dependency graph for SHLoadIndirectString.c:

Go to the source code of this file.

Functions

static void execute_test (LPCWSTR DllFile)
 
BOOL extract_resource (const WCHAR *Filename, LPCWSTR ResourceName)
 
 START_TEST (SHLoadIndirectString)
 

Function Documentation

◆ execute_test()

static void execute_test ( LPCWSTR  DllFile)
static

Definition at line 14 of file SHLoadIndirectString.c.

15{
16 WCHAR DllBuffer[MAX_PATH + 20];
17 WCHAR Buffer[MAX_PATH * 2] = {0};
18 HRESULT hr;
20 DWORD dwRet;
22
23 hEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\shlwapi_apitest_evt");
24
25 // Show that it is not signaled
26 dwRet = WaitForSingleObject(hEvent, 1);
27 ok_hex(dwRet, WAIT_TIMEOUT);
28
29 // Ensure the module is not loaded yet...
30 mod = GetModuleHandleW(DllFile);
31 if (mod != NULL)
32 {
34 skip("%S loaded, cannot continue\n", DllFile);
35 return;
36 }
37
38 wsprintfW(DllBuffer, L"@%s,-3", DllFile);
39
40 // Load a string from the dll
42 ok_hex(hr, S_OK);
43 if (SUCCEEDED(hr))
44 {
45 // Module should still not be loaded
46 mod = GetModuleHandleW(DllFile);
47 ok_ptr(mod, 0);
48
49 ok_wstr(Buffer, L"Test string one.");
50
51 // DllMain not called..
52 dwRet = WaitForSingleObject(hEvent, 1);
53 ok_hex(dwRet, WAIT_TIMEOUT);
54
55 // Show that calling DllMain will set the event
56 mod = LoadLibraryW(DllFile);
57 ok(mod != NULL, "Failed to load %S\n", DllFile);
58
59 if (mod)
60 {
61 dwRet = WaitForSingleObject(hEvent, 1);
62 ok_hex(dwRet, WAIT_OBJECT_0);
64 }
65 }
67}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define ok_wstr(x, y)
Definition: atltest.h:130
#define ok_ptr(expression, result)
Definition: atltest.h:108
Definition: bufpool.h:45
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
HRESULT WINAPI SHLoadIndirectString(LPCWSTR src, LPWSTR dst, UINT dst_len, void **reserved)
Definition: string.c:2884
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static HANDLE hEvent
Definition: comm.c:54
#define L(x)
Definition: ntvdm.h:50
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:70
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
#define WAIT_OBJECT_0
Definition: winbase.h:432
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ extract_resource()

BOOL extract_resource ( const WCHAR Filename,
LPCWSTR  ResourceName 
)

Definition at line 70 of file SHLoadIndirectString.c.

71{
73 DWORD dwWritten, Size;
74 HGLOBAL hGlobal;
77 HRSRC hRsrc = FindResourceW(GetModuleHandleW(NULL), ResourceName, (LPCWSTR)10);
78 ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
79 if (!hRsrc)
80 return FALSE;
81
82 hGlobal = LoadResource(GetModuleHandleW(NULL), hRsrc);
84 pData = LockResource(hGlobal);
85
86 ok(Size && !!pData, "Unable to load %s\n", wine_dbgstr_w(ResourceName));
87 if (!Size || !pData)
88 return FALSE;
89
91
93 {
94 skip("Failed to create temp file %ls, error %lu\n", Filename, GetLastError());
95 return FALSE;
96 }
97 Success = WriteFile(Handle, pData, Size, &dwWritten, NULL);
98 ok(Success == TRUE, "WriteFile failed with %lu\n", GetLastError());
99 ok(dwWritten == Size, "WriteFile wrote %lu bytes instead of %lu\n", dwWritten, Size);
101 Success = Success && (dwWritten == Size);
102
104 return Success;
105}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
@ Success
Definition: eventcreate.c:712
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:940
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG Handle
Definition: gdb_input.c:15
#define wine_dbgstr_w
Definition: kernel32.h:34
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define UnlockResource(handle)
Definition: winbase.h:3397
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( SHLoadIndirectString  )

Definition at line 107 of file SHLoadIndirectString.c.

108{
110 BOOL ret;
111 UINT Length;
112
114 ok(ret, "GetTempPathW error: %lu\n", GetLastError());
115
116 Length = GetTempFileNameW(workdir, L"ntdll", 0, dllpath);
117 ok(Length != 0, "GetTempFileNameW failed with %lu\n", GetLastError());
118
120 {
122 {
124 }
126 {
127 ok(0, "Ldr didnt handle exception\n");
128 }
129 _SEH2_END;
130 }
131 else
132 {
133 ok(0, "Failed to extract resource\n");
134 }
135
137}
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static void execute_test(void)
WCHAR dllpath[MAX_PATH]
static char workdir[MAX_PATH]
Definition: batch.c:26
unsigned int UINT
Definition: ndis.h:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
int ret