ReactOS  0.4.15-dev-3308-g9455def
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;
19  HANDLE hEvent;
20  DWORD dwRet;
21  HMODULE mod;
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 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define CloseHandle
Definition: compat.h:598
HRESULT hr
Definition: shlfolder.c:183
#define TRUE
Definition: types.h:120
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define ok_hex(expression, result)
Definition: atltest.h:94
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
if SUCCEEDED(hr)
#define LoadLibraryW(x)
Definition: compat.h:606
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:637
Definition: bufpool.h:45
#define FreeLibrary(x)
Definition: compat.h:607
#define WAIT_OBJECT_0
Definition: winbase.h:403
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_TIMEOUT
Definition: dderror.h:14
static const WCHAR L[]
Definition: oid.c:1250
#define ok_wstr(x, y)
Definition: atltest.h:130
HRESULT WINAPI SHLoadIndirectString(LPCWSTR src, LPWSTR dst, UINT dst_len, void **reserved)
Definition: string.c:2876
#define S_OK
Definition: intsafe.h:52
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static int mod
Definition: i386-dis.c:1281

Referenced by START_TEST().

◆ extract_resource()

BOOL extract_resource ( const WCHAR Filename,
LPCWSTR  ResourceName 
)

Definition at line 70 of file SHLoadIndirectString.c.

71 {
72  BOOL Success;
73  DWORD dwWritten, Size;
74  HGLOBAL hGlobal;
75  LPVOID pData;
76  HANDLE Handle;
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 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:598
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
#define UnlockResource(handle)
Definition: winbase.h:3228
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:934
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:600
#define skip(...)
Definition: atltest.h:64
_In_ HANDLE Handle
Definition: extypes.h:390
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

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 
119  if (extract_resource(dllpath, (LPCWSTR)101))
120  {
121  _SEH2_TRY
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 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
_SEH2_TRY
Definition: create.c:4226
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
WCHAR dllpath[MAX_PATH]
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _countof(array)
Definition: sndvol32.h:68
static char workdir[MAX_PATH]
Definition: batch.c:26
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
int ret
static const WCHAR L[]
Definition: oid.c:1250
_SEH2_END
Definition: create.c:4400
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
static void execute_test(LPCWSTR DllFile)