ReactOS 0.4.16-dev-983-g23ad936
NtGdiAddFontResource.c File Reference
#include "precomp.h"
#include <ndk/rtlfuncs.h>
Include dependency graph for NtGdiAddFontResource.c:

Go to the source code of this file.

Functions

INT APIENTRY NtGdiAddFontResourceW (_In_reads_(cwc) WCHAR *pwszFiles, _In_ ULONG cwc, _In_ ULONG cFiles, _In_ FLONG f, _In_ DWORD dwPidTid, _In_opt_ DESIGNVECTOR *pdv)
 
void Test_NtGdiAddFontResourceW ()
 
 START_TEST (NtGdiAddFontResource)
 

Function Documentation

◆ NtGdiAddFontResourceW()

INT APIENTRY NtGdiAddFontResourceW ( _In_reads_(cwc) WCHAR pwcFiles,
_In_ ULONG  cwc,
_In_ ULONG  cFiles,
_In_ FLONG  fl,
_In_ DWORD  dwPidTid,
_In_opt_ DESIGNVECTOR pdv 
)

Functions

Definition at line 465 of file font.c.

472{
473 UNICODE_STRING SafeFileName;
474 INT Ret;
475
478
479 DPRINT("NtGdiAddFontResourceW\n");
480
481 /* cwc = Length + trailing zero. */
482 if ((cwc <= 1) || (cwc > UNICODE_STRING_MAX_CHARS))
483 return 0;
484
485 SafeFileName.Length = (USHORT)((cwc - 1) * sizeof(WCHAR));
486 SafeFileName.MaximumLength = SafeFileName.Length + sizeof(UNICODE_NULL);
488 SafeFileName.MaximumLength,
489 TAG_STRING);
490 if (!SafeFileName.Buffer)
491 return 0;
492
494 {
495 ProbeForRead(pwcFiles, cwc * sizeof(WCHAR), sizeof(WCHAR));
496
497 if (!IntCheckFontPathNames(pwcFiles, cFiles, cwc))
498 return 0;
499
500 RtlCopyMemory(SafeFileName.Buffer, pwcFiles, SafeFileName.Length);
501 }
503 {
504 ExFreePoolWithTag(SafeFileName.Buffer, TAG_STRING);
505 _SEH2_YIELD(return 0);
506 }
507 _SEH2_END;
508
509 SafeFileName.Buffer[SafeFileName.Length / sizeof(WCHAR)] = UNICODE_NULL;
510
511 Ret = IntGdiAddFontResourceEx(&SafeFileName, cFiles, fl, 0);
512
513 ExFreePoolWithTag(SafeFileName.Buffer, TAG_STRING);
514 return Ret;
515}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
INT FASTCALL IntGdiAddFontResourceEx(_In_ PCUNICODE_STRING FileName, _In_ DWORD cFiles, _In_ DWORD Characteristics, _In_ DWORD dwFlags)
Definition: freetype.c:2291
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define UNICODE_NULL
#define UNICODE_STRING_MAX_CHARS
#define DBG_UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:326
#define TAG_STRING
Definition: oslist.h:22
unsigned short USHORT
Definition: pedump.c:61
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:184
#define DPRINT
Definition: sndvol32.h:73
USHORT MaximumLength
Definition: env_spec_w32.h:370
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
static BOOL IntCheckFontPathNames(_In_reads_(cwc) WCHAR *pwcFiles, _In_ ULONG cFiles, _In_ ULONG cwc)
Definition: font.c:442
_In_ FLONG fl
Definition: winddi.h:1279
_In_ ULONG_PTR _In_opt_ DESIGNVECTOR * pdv
Definition: winddi.h:3723
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GdiAddFontResourceW(), and Test_NtGdiAddFontResourceW().

◆ START_TEST()

START_TEST ( NtGdiAddFontResource  )

Definition at line 96 of file NtGdiAddFontResource.c.

97{
99}
void Test_NtGdiAddFontResourceW()

◆ Test_NtGdiAddFontResourceW()

void Test_NtGdiAddFontResourceW ( )

Definition at line 22 of file NtGdiAddFontResource.c.

23{
24 WCHAR lpszFontPath[MAX_PATH];
25 WCHAR lpszFontSearch[MAX_PATH];
26
27 INT ret;
28 UNICODE_STRING NtAbsPath;
29 WIN32_FIND_DATAW FindFileData;
30 HANDLE hFind;
31 ULONG cwc;
32
33 // Create "Font" folder Path
34 GetWindowsDirectoryW(lpszFontPath, MAX_PATH);
35 StringCbCatW(lpszFontPath, sizeof(lpszFontPath), L"\\Fonts\\");
36
37 // Search first .ttf file in Fonts Path
38 StringCbCopyW(lpszFontSearch, sizeof(lpszFontSearch), lpszFontPath);
39 StringCbCatW(lpszFontSearch, sizeof(lpszFontSearch), L"*.ttf");
40
41 hFind = FindFirstFileW(lpszFontSearch, &FindFileData);
42
43 if (hFind == INVALID_HANDLE_VALUE)
44 {
45 skip("Unable to find fonts in Font directory!\n");
46 return;
47 }
48
49 // File found. Create FontPath to File.
50 StringCbCatW(lpszFontPath, sizeof(lpszFontPath), FindFileData.cFileName);
51
52 // Fail due "cwc" being zero.
53 SetLastError(0xdeaddead);
54 RtlInitUnicodeString(&NtAbsPath, NULL);
55 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
56 cwc = 0;
57 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
58
59 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
60 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
61
62 RtlFreeUnicodeString(&NtAbsPath);
63
64 // "cwc" must count the null terminator. Otherwise fails.
65 SetLastError(0xdeaddead);
66 RtlInitUnicodeString(&NtAbsPath, NULL);
67 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
68 cwc = NtAbsPath.Length / sizeof(WCHAR);
69 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
70
71 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
72 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
73
74 RtlFreeUnicodeString(&NtAbsPath);
75
76 // Correct "cwc" value.
77 SetLastError(0xdeaddead);
78 RtlInitUnicodeString(&NtAbsPath, NULL);
79 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
80 cwc = NtAbsPath.Length / sizeof(WCHAR) + 1;
81 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
82
83 ok(ret == 1, "Expected 1 files added. Added: %d\n", ret);
84 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
85
86 RtlFreeUnicodeString(&NtAbsPath);
87
88 // Test an invalid pointer.
89 SetLastError(0xdeadbeef);
90 ret = NtGdiAddFontResourceW((PVOID)-4, 123, 1, 0, 0, NULL);
91
92 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
93 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef. Obtained: 0x%lx\n", GetLastError());
94}
INT APIENTRY NtGdiAddFontResourceW(_In_reads_(cwc) WCHAR *pwszFiles, _In_ ULONG cwc, _In_ ULONG cFiles, _In_ FLONG f, _In_ DWORD dwPidTid, _In_opt_ DESIGNVECTOR *pdv)
Definition: font.c:465
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define L(x)
Definition: ntvdm.h:50
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
uint32_t ULONG
Definition: typedefs.h:59
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().