ReactOS
0.4.16-dev-136-g52192f1
printproviders.c
Go to the documentation of this file.
1
/*
2
* PROJECT: ReactOS Spooler API
3
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4
* PURPOSE: Functions related to Print Providers
5
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6
*/
7
8
#include "
precomp.h
"
9
10
BOOL
WINAPI
11
AddPrintProvidorA
(
PSTR
pName
,
DWORD
Level
,
PBYTE
pProviderInfo)
12
{
13
LPWSTR
nameW
=
NULL
;
14
PROVIDOR_INFO_1W
pi1W;
15
PROVIDOR_INFO_2W
pi2W;
16
DWORD
len
;
17
BOOL
res
;
18
PBYTE
pPI =
NULL
;
19
20
TRACE
(
"AddPrintProvidorA(%s, %lu, %p)\n"
,
pName
,
Level
, pProviderInfo);
21
22
ZeroMemory
(&pi1W,
sizeof
(
PROVIDOR_INFO_1W
));
23
pi2W.
pOrder
=
NULL
;
24
25
switch
(
Level
)
26
{
27
case
1:
28
{
29
PROVIDOR_INFO_1A
*pi1A = (
PROVIDOR_INFO_1A
*)pProviderInfo;
30
if
(pi1A->
pName
)
31
{
32
len
=
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pName
, -1,
NULL
, 0);
33
pi1W.
pName
=
HeapAlloc
(
GetProcessHeap
(), 0,
len
*
sizeof
(
WCHAR
));
34
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pName
, -1, pi1W.
pName
,
len
);
35
}
36
if
(pi1A->
pEnvironment
)
37
{
38
len
=
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pEnvironment
, -1,
NULL
, 0);
39
pi1W.
pEnvironment
=
HeapAlloc
(
GetProcessHeap
(), 0,
len
*
sizeof
(
WCHAR
));
40
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pEnvironment
, -1, pi1W.
pEnvironment
,
len
);
41
}
42
if
(pi1A->
pDLLName
)
43
{
44
len
=
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pDLLName
, -1,
NULL
, 0);
45
pi1W.
pDLLName
=
HeapAlloc
(
GetProcessHeap
(), 0,
len
*
sizeof
(
WCHAR
));
46
MultiByteToWideChar
(
CP_ACP
, 0, pi1A->
pDLLName
, -1, pi1W.
pDLLName
,
len
);
47
}
48
pPI = (
PBYTE
)&pi1W;
49
}
50
break
;
51
52
case
2:
53
{
54
PROVIDOR_INFO_2A
*pi2A = (
PROVIDOR_INFO_2A
*)pProviderInfo;
55
if
(pi2A->
pOrder
)
56
{
57
len
=
MultiByteToWideChar
(
CP_ACP
, 0, pi2A->
pOrder
, -1,
NULL
, 0);
58
pi2W.
pOrder
=
HeapAlloc
(
GetProcessHeap
(), 0,
len
*
sizeof
(
WCHAR
));
59
MultiByteToWideChar
(
CP_ACP
, 0, pi2A->
pOrder
, -1, pi2W.
pOrder
,
len
);
60
}
61
pPI = (
PBYTE
)&pi2W;
62
}
63
break
;
64
65
default
:
66
SetLastError
(
ERROR_INVALID_LEVEL
);
67
return
FALSE
;
68
}
69
70
if
(
pName
)
71
{
72
len
=
MultiByteToWideChar
(
CP_ACP
, 0,
pName
, -1,
NULL
, 0);
73
nameW
=
HeapAlloc
(
GetProcessHeap
(), 0,
len
*
sizeof
(
WCHAR
));
74
MultiByteToWideChar
(
CP_ACP
, 0,
pName
, -1,
nameW
,
len
);
75
}
76
77
res
=
AddPrintProvidorW
(
nameW
,
Level
, pPI );
78
79
if
(
pName
)
HeapFree
(
GetProcessHeap
(), 0,
nameW
);
80
if
(pi1W.
pName
)
HeapFree
(
GetProcessHeap
(), 0, pi1W.
pName
);
81
if
(pi1W.
pEnvironment
)
HeapFree
(
GetProcessHeap
(), 0, pi1W.
pEnvironment
);
82
if
(pi1W.
pDLLName
)
HeapFree
(
GetProcessHeap
(), 0, pi1W.
pDLLName
);
83
if
(pi2W.
pOrder
)
HeapFree
(
GetProcessHeap
(), 0, pi2W.
pOrder
);
84
85
return
res
;
86
}
87
88
BOOL
WINAPI
89
AddPrintProvidorW
(
PWSTR
pName
,
DWORD
Level
,
PBYTE
pProviderInfo)
90
{
91
DWORD
dwErrorCode;
92
WINSPOOL_PROVIDOR_CONTAINER
ProvidorContainer;
93
94
TRACE
(
"AddPrintProvidorW(%S, %lu, %p)\n"
,
pName
,
Level
, pProviderInfo);
95
96
if
((
Level
< 1) || (
Level
> 2))
97
{
98
SetLastError
(
ERROR_INVALID_LEVEL
);
99
return
FALSE
;
100
}
101
102
ProvidorContainer.
ProvidorInfo
.
pProvidorInfo1
= (
WINSPOOL_PROVIDOR_INFO_1
*)pProviderInfo;
103
ProvidorContainer.
Level
=
Level
;
104
105
RpcTryExcept
106
{
107
dwErrorCode =
_RpcAddPrintProvidor
(
pName
, &ProvidorContainer );
108
}
109
RpcExcept
(
EXCEPTION_EXECUTE_HANDLER
)
110
{
111
dwErrorCode =
RpcExceptionCode
();
112
ERR
(
"_RpcEnumPorts failed with exception code %lu!\n"
, dwErrorCode);
113
}
114
RpcEndExcept
;
115
116
SetLastError
(dwErrorCode);
117
return
(dwErrorCode ==
ERROR_SUCCESS
);
118
}
119
120
BOOL
WINAPI
121
DeletePrintProvidorA
(
PSTR
pName
,
PSTR
pEnvironment,
PSTR
pPrintProviderName)
122
{
123
UNICODE_STRING
NameW, EnvW, ProviderW;
124
BOOL
Ret;
125
126
TRACE
(
"DeletePrintProvidorW(%s, %s, %s)\n"
,
pName
, pEnvironment, pPrintProviderName);
127
128
AsciiToUnicode
(&NameW,
pName
);
129
AsciiToUnicode
(&EnvW, pEnvironment);
130
AsciiToUnicode
(&ProviderW, pPrintProviderName);
131
132
Ret =
DeletePrintProvidorW
(NameW.
Buffer
, EnvW.
Buffer
, ProviderW.
Buffer
);
133
134
RtlFreeUnicodeString
(&ProviderW);
135
RtlFreeUnicodeString
(&EnvW);
136
RtlFreeUnicodeString
(&NameW);
137
138
return
Ret;
139
}
140
141
BOOL
WINAPI
142
DeletePrintProvidorW
(
PWSTR
pName
,
PWSTR
pEnvironment,
PWSTR
pPrintProviderName)
143
{
144
DWORD
dwErrorCode;
145
146
TRACE
(
"DeletePrintProvidorW(%S, %S, %S)\n"
,
pName
, pEnvironment, pPrintProviderName);
147
148
RpcTryExcept
149
{
150
dwErrorCode =
_RpcDeletePrintProvidor
(
pName
, pEnvironment, pPrintProviderName );
151
}
152
RpcExcept
(
EXCEPTION_EXECUTE_HANDLER
)
153
{
154
dwErrorCode =
RpcExceptionCode
();
155
ERR
(
"_RpcEnumPorts failed with exception code %lu!\n"
, dwErrorCode);
156
}
157
RpcEndExcept
;
158
159
SetLastError
(dwErrorCode);
160
return
(dwErrorCode ==
ERROR_SUCCESS
);
161
}
nameW
static const WCHAR nameW[]
Definition:
main.c:49
ERR
#define ERR(fmt,...)
Definition:
precomp.h:57
ERROR_SUCCESS
#define ERROR_SUCCESS
Definition:
deptool.c:10
NULL
#define NULL
Definition:
types.h:112
FALSE
#define FALSE
Definition:
types.h:117
GetProcessHeap
#define GetProcessHeap()
Definition:
compat.h:736
CP_ACP
#define CP_ACP
Definition:
compat.h:109
SetLastError
#define SetLastError(x)
Definition:
compat.h:752
HeapAlloc
#define HeapAlloc
Definition:
compat.h:733
HeapFree
#define HeapFree(x, y, z)
Definition:
compat.h:735
MultiByteToWideChar
#define MultiByteToWideChar
Definition:
compat.h:110
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
DWORD
unsigned long DWORD
Definition:
ntddk_ex.h:95
res
GLuint res
Definition:
glext.h:9613
len
GLenum GLsizei len
Definition:
glext.h:6722
EXCEPTION_EXECUTE_HANDLER
#define EXCEPTION_EXECUTE_HANDLER
Definition:
excpt.h:85
AsciiToUnicode
wstring AsciiToUnicode(const char *AsciiString)
Definition:
tools.cpp:220
pName
static LPSTR pName
Definition:
security.c:75
RtlFreeUnicodeString
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PBYTE
BYTE * PBYTE
Definition:
pedump.c:66
RpcEndExcept
#define RpcEndExcept
Definition:
rpc.h:128
RpcTryExcept
#define RpcTryExcept
Definition:
rpc.h:126
RpcExcept
#define RpcExcept(expr)
Definition:
rpc.h:127
RpcExceptionCode
#define RpcExceptionCode()
Definition:
rpc.h:132
TRACE
#define TRACE(s)
Definition:
solgame.cpp:4
DeletePrintProvidorW
BOOL WINAPI DeletePrintProvidorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProviderName)
Definition:
printproviders.c:22
AddPrintProvidorW
BOOL WINAPI AddPrintProvidorW(PWSTR pName, DWORD Level, PBYTE pProviderInfo)
Definition:
printproviders.c:15
_RpcDeletePrintProvidor
DWORD _RpcDeletePrintProvidor(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, WCHAR *pPrintProviderName)
Definition:
printproviders.c:31
_RpcAddPrintProvidor
DWORD _RpcAddPrintProvidor(WINSPOOL_HANDLE pName, WINSPOOL_PROVIDOR_CONTAINER *pProvidorContainer)
Definition:
printproviders.c:11
_PROVIDOR_INFO_1A
Definition:
winspool.h:1303
_PROVIDOR_INFO_1A::pName
LPSTR pName
Definition:
winspool.h:1304
_PROVIDOR_INFO_1A::pDLLName
LPSTR pDLLName
Definition:
winspool.h:1306
_PROVIDOR_INFO_1A::pEnvironment
LPSTR pEnvironment
Definition:
winspool.h:1305
_PROVIDOR_INFO_1W
Definition:
winspool.h:1309
_PROVIDOR_INFO_1W::pName
LPWSTR pName
Definition:
winspool.h:1310
_PROVIDOR_INFO_1W::pDLLName
LPWSTR pDLLName
Definition:
winspool.h:1312
_PROVIDOR_INFO_1W::pEnvironment
LPWSTR pEnvironment
Definition:
winspool.h:1311
_PROVIDOR_INFO_2A
Definition:
winspool.h:1319
_PROVIDOR_INFO_2A::pOrder
LPSTR pOrder
Definition:
winspool.h:1320
_PROVIDOR_INFO_2W
Definition:
winspool.h:1323
_PROVIDOR_INFO_2W::pOrder
LPWSTR pOrder
Definition:
winspool.h:1324
_UNICODE_STRING
Definition:
env_spec_w32.h:368
_UNICODE_STRING::Buffer
PWSTR Buffer
Definition:
env_spec_w32.h:371
_WINSPOOL_PROVIDOR_CONTAINER
Definition:
winspool.idl:721
_WINSPOOL_PROVIDOR_CONTAINER::pProvidorInfo1
WINSPOOL_PROVIDOR_INFO_1 * pProvidorInfo1
Definition:
winspool.idl:727
_WINSPOOL_PROVIDOR_CONTAINER::Level
DWORD Level
Definition:
winspool.idl:722
_WINSPOOL_PROVIDOR_CONTAINER::ProvidorInfo
union _WINSPOOL_PROVIDOR_CONTAINER::@3441 ProvidorInfo
_WINSPOOL_PROVIDOR_INFO_1
Definition:
winspool.idl:457
PWSTR
uint16_t * PWSTR
Definition:
typedefs.h:56
PSTR
char * PSTR
Definition:
typedefs.h:51
precomp.h
ZeroMemory
#define ZeroMemory
Definition:
winbase.h:1712
WINAPI
#define WINAPI
Definition:
msvc.h:6
ERROR_INVALID_LEVEL
#define ERROR_INVALID_LEVEL
Definition:
winerror.h:196
AddPrintProvidorA
BOOL WINAPI AddPrintProvidorA(PSTR pName, DWORD Level, PBYTE pProviderInfo)
Definition:
printproviders.c:11
DeletePrintProvidorA
BOOL WINAPI DeletePrintProvidorA(PSTR pName, PSTR pEnvironment, PSTR pPrintProviderName)
Definition:
printproviders.c:121
Level
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition:
wmitypes.h:56
WCHAR
__wchar_t WCHAR
Definition:
xmlstorage.h:180
LPWSTR
WCHAR * LPWSTR
Definition:
xmlstorage.h:184
win32ss
printing
base
winspool
printproviders.c
Generated on Tue Oct 15 2024 06:14:51 for ReactOS by
1.9.6