2 * Implementation of the Local Printmonitor
4 * Copyright 2006-2008 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
31 #include "ddk/winsplp.h"
34 #include "wine/list.h"
35 #include "wine/debug.h"
36 #include "wine/unicode.h"
37 #include "localspl_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(localspl
);
41 /* ############################### */
44 WCHAR src
[MAX_PATH
+MAX_PATH
];
45 WCHAR dst
[MAX_PATH
+MAX_PATH
];
67 LPCWSTR versionregpath
;
68 LPCWSTR versionsubdir
;
72 /* ############################### */
74 HINSTANCE LOCALSPL_hInstance
= NULL
;
76 static const PRINTPROVIDOR
* pp
= NULL
;
78 static const WCHAR backslashW
[] = {'\\',0};
79 static const WCHAR configuration_fileW
[] = {'C','o','n','f','i','g','u','r','a','t','i','o','n',' ','F','i','l','e',0};
80 static const WCHAR datatypeW
[] = {'D','a','t','a','t','y','p','e',0};
81 static const WCHAR data_fileW
[] = {'D','a','t','a',' ','F','i','l','e',0};
82 static const WCHAR default_devmodeW
[] = {'D','e','f','a','u','l','t',' ','D','e','v','M','o','d','e',0};
83 static const WCHAR dependent_filesW
[] = {'D','e','p','e','n','d','e','n','t',' ','F','i','l','e','s',0};
84 static const WCHAR descriptionW
[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
85 static const WCHAR driverW
[] = {'D','r','i','v','e','r',0};
86 static const WCHAR fmt_driversW
[] = { 'S','y','s','t','e','m','\\',
87 'C','u', 'r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
88 'c','o','n','t','r','o','l','\\',
89 'P','r','i','n','t','\\',
90 'E','n','v','i','r','o','n','m','e','n','t','s','\\',
91 '%','s','\\','D','r','i','v','e','r','s','%','s',0 };
92 static const WCHAR hardwareidW
[] = {'H','a','r','d','w','a','r','e','I','D',0};
93 static const WCHAR help_fileW
[] = {'H','e','l','p',' ','F','i','l','e',0};
94 static const WCHAR locationW
[] = {'L','o','c','a','t','i','o','n',0};
95 static const WCHAR manufacturerW
[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
96 static const WCHAR monitorW
[] = {'M','o','n','i','t','o','r',0};
97 static const WCHAR monitorsW
[] = {'S','y','s','t','e','m','\\',
98 'C','u', 'r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
99 'C','o','n','t','r','o','l','\\',
100 'P','r','i','n','t','\\',
101 'M','o','n','i','t','o','r','s','\\',0};
102 static const WCHAR monitorUIW
[] = {'M','o','n','i','t','o','r','U','I',0};
103 static const WCHAR nameW
[] = {'N','a','m','e',0};
104 static const WCHAR oem_urlW
[] = {'O','E','M',' ','U','r','l',0};
105 static const WCHAR parametersW
[] = {'P','a','r','a','m','e','t','e','r','s',0};
106 static const WCHAR portW
[] = {'P','o','r','t',0};
107 static const WCHAR previous_namesW
[] = {'P','r','e','v','i','o','u','s',' ','N','a','m','e','s',0};
108 static const WCHAR spooldriversW
[] = {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\',0};
109 static const WCHAR versionW
[] = {'V','e','r','s','i','o','n',0};
111 static const WCHAR win40_envnameW
[] = {'W','i','n','d','o','w','s',' ','4','.','0',0};
112 static const WCHAR win40_subdirW
[] = {'w','i','n','4','0',0};
113 static const WCHAR version0_regpathW
[] = {'\\','V','e','r','s','i','o','n','-','0',0};
114 static const WCHAR version0_subdirW
[] = {'\\','0',0};
116 static const WCHAR x86_envnameW
[] = {'W','i','n','d','o','w','s',' ','N','T',' ','x','8','6',0};
117 static const WCHAR x86_subdirW
[] = {'w','3','2','x','8','6',0};
118 static const WCHAR version3_regpathW
[] = {'\\','V','e','r','s','i','o','n','-','3',0};
119 static const WCHAR version3_subdirW
[] = {'\\','3',0};
122 static const printenv_t env_x86
= {x86_envnameW
, x86_subdirW
, 3,
123 version3_regpathW
, version3_subdirW
};
125 static const printenv_t env_win40
= {win40_envnameW
, win40_subdirW
, 0,
126 version0_regpathW
, version0_subdirW
};
128 static const printenv_t
* const all_printenv
[] = {&env_x86
, &env_win40
};
131 static const DWORD di_sizeof
[] = {0, sizeof(DRIVER_INFO_1W
), sizeof(DRIVER_INFO_2W
),
132 sizeof(DRIVER_INFO_3W
), sizeof(DRIVER_INFO_4W
),
133 sizeof(DRIVER_INFO_5W
), sizeof(DRIVER_INFO_6W
),
134 0, sizeof(DRIVER_INFO_8W
)};
137 /******************************************************************
138 * apd_copyfile [internal]
140 * Copy a file from the driverdirectory to the versioned directory
147 static BOOL
apd_copyfile(LPWSTR filename
, apd_data_t
*apd
)
153 apd
->src
[apd
->srclen
] = '\0';
154 apd
->dst
[apd
->dstlen
] = '\0';
156 if (!filename
|| !filename
[0]) {
157 /* nothing to copy */
161 ptr
= strrchrW(filename
, '\\');
170 if (apd
->copyflags
& APD_COPY_FROM_DIRECTORY
) {
171 /* we have an absolute Path */
177 lstrcatW(srcname
, ptr
);
179 lstrcatW(apd
->dst
, ptr
);
181 TRACE("%s => %s\n", debugstr_w(filename
), debugstr_w(apd
->dst
));
183 /* FIXME: handle APD_COPY_NEW_FILES */
184 res
= CopyFileW(srcname
, apd
->dst
, FALSE
);
185 TRACE("got %u with %u\n", res
, GetLastError());
187 return (apd
->lazy
) ? TRUE
: res
;
190 /******************************************************************
191 * copy_servername_from_name (internal)
193 * for an external server, the serverpart from the name is copied.
196 * the length (in WCHAR) of the serverpart (0 for the local computer)
197 * (-length), when the name is to long
200 static LONG
copy_servername_from_name(LPCWSTR name
, LPWSTR target
)
204 WCHAR buffer
[MAX_COMPUTERNAME_LENGTH
+1];
208 if (target
) *target
= '\0';
210 if (name
== NULL
) return 0;
211 if ((name
[0] != '\\') || (name
[1] != '\\')) return 0;
214 /* skip over both backslash, find separator '\' */
215 ptr
= strchrW(server
, '\\');
216 serverlen
= (ptr
) ? ptr
- server
: lstrlenW(server
);
218 /* servername is empty or to long */
219 if (serverlen
== 0) return 0;
221 TRACE("found %s\n", debugstr_wn(server
, serverlen
));
223 if (serverlen
> MAX_COMPUTERNAME_LENGTH
) return -serverlen
;
225 len
= sizeof(buffer
) / sizeof(buffer
[0]);
226 if (GetComputerNameW(buffer
, &len
)) {
227 if ((serverlen
== len
) && (strncmpiW(server
, buffer
, len
) == 0)) {
228 /* The requested Servername is our computername */
230 memcpy(target
, server
, serverlen
* sizeof(WCHAR
));
231 target
[serverlen
] = '\0';
239 /******************************************************************
240 * Return the number of bytes for an multi_sz string.
241 * The result includes all \0s
242 * (specifically the extra \0, that is needed as multi_sz terminator).
244 static int multi_sz_lenW(const WCHAR
*str
)
246 const WCHAR
*ptr
= str
;
250 ptr
+= lstrlenW(ptr
) + 1;
253 return (ptr
- str
+ 1) * sizeof(WCHAR
);
256 /******************************************************************
257 * validate_envW [internal]
259 * validate the user-supplied printing-environment
262 * env [I] PTR to Environment-String or NULL
265 * Success: PTR to printenv_t
266 * Failure: NULL and ERROR_INVALID_ENVIRONMENT
269 * An empty string is handled the same way as NULL.
273 static const printenv_t
* validate_envW(LPCWSTR env
)
275 const printenv_t
*result
= NULL
;
278 TRACE("(%s)\n", debugstr_w(env
));
281 for (i
= 0; i
< sizeof(all_printenv
)/sizeof(all_printenv
[0]); i
++)
283 if (lstrcmpiW(env
, all_printenv
[i
]->envname
) == 0)
285 result
= all_printenv
[i
];
289 if (result
== NULL
) {
290 FIXME("unsupported Environment: %s\n", debugstr_w(env
));
291 SetLastError(ERROR_INVALID_ENVIRONMENT
);
293 /* on win9x, only "Windows 4.0" is allowed, but we ignore this */
297 result
= (GetVersion() & 0x80000000) ? &env_win40
: &env_x86
;
300 TRACE("=> using %p: %s\n", result
, debugstr_w(result
? result
->envname
: NULL
));
304 /*****************************************************************************
305 * enumerate the local monitors (INTERNAL)
307 * returns the needed size (in bytes) for pMonitors
308 * and *lpreturned is set to number of entries returned in pMonitors
310 * Language-Monitors are also installed in the same Registry-Location but
311 * they are filtered in Windows (not returned by EnumMonitors).
312 * We do no filtering to simplify our Code.
315 static DWORD
get_local_monitors(DWORD level
, LPBYTE pMonitors
, DWORD cbBuf
, LPDWORD lpreturned
)
320 LPMONITOR_INFO_2W mi
;
321 WCHAR buffer
[MAX_PATH
];
322 WCHAR dllname
[MAX_PATH
];
330 entrysize
= (level
== 1) ? sizeof(MONITOR_INFO_1W
) : sizeof(MONITOR_INFO_2W
);
332 numentries
= *lpreturned
; /* this is 0, when we scan the registry */
333 len
= entrysize
* numentries
;
334 ptr
= (LPWSTR
) &pMonitors
[len
];
337 len
= sizeof(buffer
)/sizeof(buffer
[0]);
340 /* Windows creates the "Monitors"-Key on reboot / start "spooler" */
341 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, monitorsW
, &hroot
) == ERROR_SUCCESS
) {
342 /* Scan all Monitor-Registry-Keys */
343 while (RegEnumKeyExW(hroot
, index
, buffer
, &len
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
) {
344 TRACE("Monitor_%d: %s\n", numentries
, debugstr_w(buffer
));
345 dllsize
= sizeof(dllname
);
348 /* The Monitor must have a Driver-DLL */
349 if (RegOpenKeyExW(hroot
, buffer
, 0, KEY_READ
, &hentry
) == ERROR_SUCCESS
) {
350 if (RegQueryValueExW(hentry
, driverW
, NULL
, NULL
, (LPBYTE
) dllname
, &dllsize
) == ERROR_SUCCESS
) {
351 /* We found a valid DLL for this Monitor. */
352 TRACE("using Driver: %s\n", debugstr_w(dllname
));
357 /* Windows returns only Port-Monitors here, but to simplify our code,
358 we do no filtering for Language-Monitors */
362 needed
+= (len
+1) * sizeof(WCHAR
); /* len is lstrlenW(monitorname) */
364 /* we install and return only monitors for "Windows NT x86" */
365 needed
+= (lstrlenW(x86_envnameW
) +1) * sizeof(WCHAR
);
369 /* required size is calculated. Now fill the user-buffer */
370 if (pMonitors
&& (cbBuf
>= needed
)){
371 mi
= (LPMONITOR_INFO_2W
) pMonitors
;
372 pMonitors
+= entrysize
;
374 TRACE("%p: writing MONITOR_INFO_%dW #%d\n", mi
, level
, numentries
);
376 lstrcpyW(ptr
, buffer
); /* Name of the Monitor */
377 ptr
+= (len
+1); /* len is lstrlenW(monitorname) */
379 mi
->pEnvironment
= ptr
;
380 lstrcpyW(ptr
, x86_envnameW
); /* fixed to "Windows NT x86" */
381 ptr
+= (lstrlenW(x86_envnameW
)+1);
384 lstrcpyW(ptr
, dllname
); /* Name of the Driver-DLL */
385 ptr
+= (dllsize
/ sizeof(WCHAR
));
390 len
= sizeof(buffer
)/sizeof(buffer
[0]);
395 *lpreturned
= numentries
;
396 TRACE("need %d byte for %d entries\n", needed
, numentries
);
400 /*****************************************************************************
401 * open_driver_reg [internal]
403 * opens the registry for the printer drivers depending on the given input
404 * variable pEnvironment
407 * Success: the opened hkey
410 static HKEY
open_driver_reg(LPCWSTR pEnvironment
)
414 const printenv_t
* env
;
416 TRACE("(%s)\n", debugstr_w(pEnvironment
));
418 env
= validate_envW(pEnvironment
);
419 if (!env
) return NULL
;
421 buffer
= HeapAlloc(GetProcessHeap(), 0, sizeof(fmt_driversW
) +
422 (lstrlenW(env
->envname
) + lstrlenW(env
->versionregpath
)) * sizeof(WCHAR
));
425 wsprintfW(buffer
, fmt_driversW
, env
->envname
, env
->versionregpath
);
426 RegCreateKeyW(HKEY_LOCAL_MACHINE
, buffer
, &retval
);
427 HeapFree(GetProcessHeap(), 0, buffer
);
432 /*****************************************************************************
433 * fpGetPrinterDriverDirectory [exported through PRINTPROVIDOR]
435 * Return the PATH for the Printer-Drivers
438 * pName [I] Servername (NT only) or NULL (local Computer)
439 * pEnvironment [I] Printing-Environment (see below) or NULL (Default)
440 * Level [I] Structure-Level (must be 1)
441 * pDriverDirectory [O] PTR to Buffer that receives the Result
442 * cbBuf [I] Size of Buffer at pDriverDirectory
443 * pcbNeeded [O] PTR to DWORD that receives the size in Bytes used /
444 * required for pDriverDirectory
447 * Success: TRUE and in pcbNeeded the Bytes used in pDriverDirectory
448 * Failure: FALSE and in pcbNeeded the Bytes required for pDriverDirectory,
449 * if cbBuf is too small
451 * Native Values returned in pDriverDirectory on Success:
452 *| NT(Windows NT x86): "%winsysdir%\\spool\\DRIVERS\\w32x86"
453 *| NT(Windows 4.0): "%winsysdir%\\spool\\DRIVERS\\win40"
454 *| win9x(Windows 4.0): "%winsysdir%"
456 * "%winsysdir%" is the Value from GetSystemDirectoryW()
459 static BOOL WINAPI
fpGetPrinterDriverDirectory(LPWSTR pName
, LPWSTR pEnvironment
,
460 DWORD Level
, LPBYTE pDriverDirectory
, DWORD cbBuf
, LPDWORD pcbNeeded
)
463 const printenv_t
* env
;
465 TRACE("(%s, %s, %d, %p, %d, %p)\n", debugstr_w(pName
),
466 debugstr_w(pEnvironment
), Level
, pDriverDirectory
, cbBuf
, pcbNeeded
);
468 if (pName
!= NULL
&& pName
[0]) {
469 FIXME("server %s not supported\n", debugstr_w(pName
));
470 SetLastError(ERROR_INVALID_PARAMETER
);
474 env
= validate_envW(pEnvironment
);
475 if (!env
) return FALSE
; /* pEnvironment invalid or unsupported */
478 /* GetSystemDirectoryW returns number of WCHAR including the '\0' */
479 needed
= GetSystemDirectoryW(NULL
, 0);
480 /* add the Size for the Subdirectories */
481 needed
+= lstrlenW(spooldriversW
);
482 needed
+= lstrlenW(env
->subdir
);
483 needed
*= sizeof(WCHAR
); /* return-value is size in Bytes */
487 if (needed
> cbBuf
) {
488 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
492 if (pDriverDirectory
== NULL
) {
493 /* ERROR_INVALID_USER_BUFFER is NT, ERROR_INVALID_PARAMETER is win9x */
494 SetLastError(ERROR_INVALID_USER_BUFFER
);
498 GetSystemDirectoryW((LPWSTR
) pDriverDirectory
, cbBuf
/sizeof(WCHAR
));
499 /* add the Subdirectories */
500 lstrcatW((LPWSTR
) pDriverDirectory
, spooldriversW
);
501 lstrcatW((LPWSTR
) pDriverDirectory
, env
->subdir
);
503 TRACE("=> %s\n", debugstr_w((LPWSTR
) pDriverDirectory
));
507 /******************************************************************************
508 * myAddPrinterDriverEx [internal]
510 * Install a Printer Driver with the Option to upgrade / downgrade the Files
511 * and a special mode with lazy error checking.
514 static BOOL WINAPI
myAddPrinterDriverEx(DWORD level
, LPBYTE pDriverInfo
, DWORD dwFileCopyFlags
, BOOL lazy
)
516 static const WCHAR emptyW
[1];
517 const printenv_t
*env
;
527 /* we need to set all entries in the Registry, independent from the Level of
528 DRIVER_INFO, that the caller supplied */
530 ZeroMemory(&di
, sizeof(di
));
531 if (pDriverInfo
&& (level
< (sizeof(di_sizeof
) / sizeof(di_sizeof
[0])))) {
532 memcpy(&di
, pDriverInfo
, di_sizeof
[level
]);
535 /* dump the most used infos */
536 TRACE("%p: .cVersion : 0x%x/%d\n", pDriverInfo
, di
.cVersion
, di
.cVersion
);
537 TRACE("%p: .pName : %s\n", di
.pName
, debugstr_w(di
.pName
));
538 TRACE("%p: .pEnvironment: %s\n", di
.pEnvironment
, debugstr_w(di
.pEnvironment
));
539 TRACE("%p: .pDriverPath : %s\n", di
.pDriverPath
, debugstr_w(di
.pDriverPath
));
540 TRACE("%p: .pDataFile : %s\n", di
.pDataFile
, debugstr_w(di
.pDataFile
));
541 TRACE("%p: .pConfigFile : %s\n", di
.pConfigFile
, debugstr_w(di
.pConfigFile
));
542 TRACE("%p: .pHelpFile : %s\n", di
.pHelpFile
, debugstr_w(di
.pHelpFile
));
543 /* dump only the first of the additional Files */
544 TRACE("%p: .pDependentFiles: %s\n", di
.pDependentFiles
, debugstr_w(di
.pDependentFiles
));
547 /* check environment */
548 env
= validate_envW(di
.pEnvironment
);
549 if (env
== NULL
) return FALSE
; /* ERROR_INVALID_ENVIRONMENT */
551 /* fill the copy-data / get the driverdir */
552 len
= sizeof(apd
.src
) - sizeof(version3_subdirW
) - sizeof(WCHAR
);
553 if (!fpGetPrinterDriverDirectory(NULL
, (LPWSTR
) env
->envname
, 1,
554 (LPBYTE
) apd
.src
, len
, &len
)) {
555 /* Should never Fail */
558 memcpy(apd
.dst
, apd
.src
, len
);
559 lstrcatW(apd
.src
, backslashW
);
560 apd
.srclen
= lstrlenW(apd
.src
);
561 lstrcatW(apd
.dst
, env
->versionsubdir
);
562 lstrcatW(apd
.dst
, backslashW
);
563 apd
.dstlen
= lstrlenW(apd
.dst
);
564 apd
.copyflags
= dwFileCopyFlags
;
566 CreateDirectoryW(apd
.src
, NULL
);
567 CreateDirectoryW(apd
.dst
, NULL
);
569 hroot
= open_driver_reg(env
->envname
);
571 ERR("Can't create Drivers key\n");
575 /* Fill the Registry for the Driver */
576 if ((lres
= RegCreateKeyExW(hroot
, di
.pName
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
577 KEY_WRITE
| KEY_QUERY_VALUE
, NULL
,
578 &hdrv
, &disposition
)) != ERROR_SUCCESS
) {
580 ERR("can't create driver %s: %u\n", debugstr_w(di
.pName
), lres
);
587 if (disposition
== REG_OPENED_EXISTING_KEY
) {
588 TRACE("driver %s already installed\n", debugstr_w(di
.pName
));
590 SetLastError(ERROR_PRINTER_DRIVER_ALREADY_INSTALLED
);
594 /* Verified with the Adobe PS Driver, that w2k does not use di.Version */
595 RegSetValueExW(hdrv
, versionW
, 0, REG_DWORD
, (LPBYTE
) &env
->driverversion
,
598 RegSetValueExW(hdrv
, driverW
, 0, REG_SZ
, (LPBYTE
) di
.pDriverPath
,
599 (lstrlenW(di
.pDriverPath
)+1)* sizeof(WCHAR
));
600 apd_copyfile(di
.pDriverPath
, &apd
);
602 RegSetValueExW(hdrv
, data_fileW
, 0, REG_SZ
, (LPBYTE
) di
.pDataFile
,
603 (lstrlenW(di
.pDataFile
)+1)* sizeof(WCHAR
));
604 apd_copyfile(di
.pDataFile
, &apd
);
606 RegSetValueExW(hdrv
, configuration_fileW
, 0, REG_SZ
, (LPBYTE
) di
.pConfigFile
,
607 (lstrlenW(di
.pConfigFile
)+1)* sizeof(WCHAR
));
608 apd_copyfile(di
.pConfigFile
, &apd
);
610 /* settings for level 3 */
612 RegSetValueExW(hdrv
, help_fileW
, 0, REG_SZ
, (LPBYTE
) di
.pHelpFile
,
613 (lstrlenW(di
.pHelpFile
)+1)* sizeof(WCHAR
));
615 RegSetValueExW(hdrv
, help_fileW
, 0, REG_SZ
, (LPBYTE
)emptyW
, sizeof(emptyW
));
616 apd_copyfile(di
.pHelpFile
, &apd
);
619 ptr
= di
.pDependentFiles
;
621 RegSetValueExW(hdrv
, dependent_filesW
, 0, REG_MULTI_SZ
, (LPBYTE
) di
.pDependentFiles
,
622 multi_sz_lenW(di
.pDependentFiles
));
624 RegSetValueExW(hdrv
, dependent_filesW
, 0, REG_MULTI_SZ
, (LPBYTE
)emptyW
, sizeof(emptyW
));
625 while ((ptr
!= NULL
) && (ptr
[0])) {
626 if (apd_copyfile(ptr
, &apd
)) {
627 ptr
+= lstrlenW(ptr
) + 1;
631 WARN("Failed to copy %s\n", debugstr_w(ptr
));
635 /* The language-Monitor was already copied by the caller to "%SystemRoot%\system32" */
637 RegSetValueExW(hdrv
, monitorW
, 0, REG_SZ
, (LPBYTE
) di
.pMonitorName
,
638 (lstrlenW(di
.pMonitorName
)+1)* sizeof(WCHAR
));
640 RegSetValueExW(hdrv
, monitorW
, 0, REG_SZ
, (LPBYTE
)emptyW
, sizeof(emptyW
));
642 if (di
.pDefaultDataType
)
643 RegSetValueExW(hdrv
, datatypeW
, 0, REG_SZ
, (LPBYTE
) di
.pDefaultDataType
,
644 (lstrlenW(di
.pDefaultDataType
)+1)* sizeof(WCHAR
));
646 RegSetValueExW(hdrv
, datatypeW
, 0, REG_SZ
, (LPBYTE
)emptyW
, sizeof(emptyW
));
648 /* settings for level 4 */
649 if (di
.pszzPreviousNames
)
650 RegSetValueExW(hdrv
, previous_namesW
, 0, REG_MULTI_SZ
, (LPBYTE
) di
.pszzPreviousNames
,
651 multi_sz_lenW(di
.pszzPreviousNames
));
653 RegSetValueExW(hdrv
, previous_namesW
, 0, REG_MULTI_SZ
, (LPBYTE
)emptyW
, sizeof(emptyW
));
655 if (level
> 5) TRACE("level %u for Driver %s is incomplete\n", level
, debugstr_w(di
.pName
));
658 TRACE("### DrvDriverEvent(...,DRIVEREVENT_INITIALIZE) not implemented yet\n");
660 TRACE("=> TRUE with %u\n", GetLastError());
665 /******************************************************************************
666 * fpAddPrinterDriverEx [exported through PRINTPROVIDOR]
668 * Install a Printer Driver with the Option to upgrade / downgrade the Files
671 * pName [I] Servername or NULL (local Computer)
672 * level [I] Level for the supplied DRIVER_INFO_*W struct
673 * pDriverInfo [I] PTR to DRIVER_INFO_*W struct with the Driver Parameter
674 * dwFileCopyFlags [I] How to Copy / Upgrade / Downgrade the needed Files
681 static BOOL WINAPI
fpAddPrinterDriverEx(LPWSTR pName
, DWORD level
, LPBYTE pDriverInfo
, DWORD dwFileCopyFlags
)
685 TRACE("(%s, %d, %p, 0x%x)\n", debugstr_w(pName
), level
, pDriverInfo
, dwFileCopyFlags
);
686 lres
= copy_servername_from_name(pName
, NULL
);
688 FIXME("server %s not supported\n", debugstr_w(pName
));
689 SetLastError(ERROR_ACCESS_DENIED
);
693 if ((dwFileCopyFlags
& ~APD_COPY_FROM_DIRECTORY
) != APD_COPY_ALL_FILES
) {
694 TRACE("Flags 0x%x ignored (using APD_COPY_ALL_FILES)\n", dwFileCopyFlags
& ~APD_COPY_FROM_DIRECTORY
);
697 return myAddPrinterDriverEx(level
, pDriverInfo
, dwFileCopyFlags
, TRUE
);
699 /******************************************************************
700 * fpDeleteMonitor [exported through PRINTPROVIDOR]
702 * Delete a specific Printmonitor from a Printing-Environment
705 * pName [I] Servername or NULL (local Computer)
706 * pEnvironment [I] Printing-Environment of the Monitor or NULL (Default)
707 * pMonitorName [I] Name of the Monitor, that should be deleted
714 * pEnvironment is ignored in Windows for the local Computer.
718 BOOL WINAPI
fpDeleteMonitor(LPWSTR pName
, LPWSTR pEnvironment
, LPWSTR pMonitorName
)
723 TRACE("(%s, %s, %s)\n",debugstr_w(pName
),debugstr_w(pEnvironment
),
724 debugstr_w(pMonitorName
));
726 lres
= copy_servername_from_name(pName
, NULL
);
728 FIXME("server %s not supported\n", debugstr_w(pName
));
729 SetLastError(ERROR_INVALID_NAME
);
733 /* pEnvironment is ignored in Windows for the local Computer */
734 if (!pMonitorName
|| !pMonitorName
[0]) {
735 TRACE("pMonitorName %s is invalid\n", debugstr_w(pMonitorName
));
736 SetLastError(ERROR_INVALID_PARAMETER
);
740 if(RegCreateKeyW(HKEY_LOCAL_MACHINE
, monitorsW
, &hroot
) != ERROR_SUCCESS
) {
741 ERR("unable to create key %s\n", debugstr_w(monitorsW
));
745 if(RegDeleteTreeW(hroot
, pMonitorName
) == ERROR_SUCCESS
) {
746 TRACE("%s deleted\n", debugstr_w(pMonitorName
));
751 TRACE("%s does not exist\n", debugstr_w(pMonitorName
));
754 /* NT: ERROR_UNKNOWN_PRINT_MONITOR (3000), 9x: ERROR_INVALID_PARAMETER (87) */
755 SetLastError(ERROR_UNKNOWN_PRINT_MONITOR
);
759 /*****************************************************************************
760 * fpEnumMonitors [exported through PRINTPROVIDOR]
762 * Enumerate available Port-Monitors
765 * pName [I] Servername or NULL (local Computer)
766 * Level [I] Structure-Level (1:Win9x+NT or 2:NT only)
767 * pMonitors [O] PTR to Buffer that receives the Result
768 * cbBuf [I] Size of Buffer at pMonitors
769 * pcbNeeded [O] PTR to DWORD that receives the size in Bytes used / required for pMonitors
770 * pcReturned [O] PTR to DWORD that receives the number of Monitors in pMonitors
774 * Failure: FALSE and in pcbNeeded the Bytes required for buffer, if cbBuf is too small
777 * Windows reads the Registry once and cache the Results.
780 BOOL WINAPI
fpEnumMonitors(LPWSTR pName
, DWORD Level
, LPBYTE pMonitors
, DWORD cbBuf
,
781 LPDWORD pcbNeeded
, LPDWORD pcReturned
)
783 DWORD numentries
= 0;
788 TRACE("(%s, %d, %p, %d, %p, %p)\n", debugstr_w(pName
), Level
, pMonitors
,
789 cbBuf
, pcbNeeded
, pcReturned
);
791 lres
= copy_servername_from_name(pName
, NULL
);
793 FIXME("server %s not supported\n", debugstr_w(pName
));
794 SetLastError(ERROR_INVALID_NAME
);
798 if (!Level
|| (Level
> 2)) {
799 WARN("level (%d) is ignored in win9x\n", Level
);
800 SetLastError(ERROR_INVALID_LEVEL
);
804 /* Scan all Monitor-Keys */
806 needed
= get_local_monitors(Level
, NULL
, 0, &numentries
);
808 /* we calculated the needed buffersize. now do more error-checks */
809 if (cbBuf
< needed
) {
810 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
814 /* fill the Buffer with the Monitor-Keys */
815 needed
= get_local_monitors(Level
, pMonitors
, cbBuf
, &numentries
);
819 if (pcbNeeded
) *pcbNeeded
= needed
;
820 if (pcReturned
) *pcReturned
= numentries
;
822 TRACE("returning %d with %d (%d byte for %d entries)\n",
823 res
, GetLastError(), needed
, numentries
);
828 /*****************************************************
829 * get_backend [internal]
831 static const PRINTPROVIDOR
* get_backend(void)
833 static const PRINTPROVIDOR backend
= {
834 NULL
, /* fpOpenPrinter */
837 NULL
, /* fpEnumJobs */
838 NULL
, /* fpAddPrinter */
839 NULL
, /* fpDeletePrinter */
840 NULL
, /* fpSetPrinter */
841 NULL
, /* fpGetPrinter */
842 NULL
, /* fpEnumPrinters */
843 NULL
, /* fpAddPrinterDriver */
844 NULL
, /* fpEnumPrinterDrivers */
845 NULL
, /* fpGetPrinterDriver */
846 fpGetPrinterDriverDirectory
,
847 NULL
, /* fpDeletePrinterDriver */
848 NULL
, /* fpAddPrintProcessor */
849 NULL
, /* fpEnumPrintProcessors */
850 NULL
, /* fpGetPrintProcessorDirectory */
851 NULL
, /* fpDeletePrintProcessor */
852 NULL
, /* fpEnumPrintProcessorDatatypes */
853 NULL
, /* fpStartDocPrinter */
854 NULL
, /* fpStartPagePrinter */
855 NULL
, /* fpWritePrinter */
856 NULL
, /* fpEndPagePrinter */
857 NULL
, /* fpAbortPrinter */
858 NULL
, /* fpReadPrinter */
859 NULL
, /* fpEndDocPrinter */
861 NULL
, /* fpScheduleJob */
862 NULL
, /* fpGetPrinterData */
863 NULL
, /* fpSetPrinterData */
864 NULL
, /* fpWaitForPrinterChange */
865 NULL
, /* fpClosePrinter */
866 NULL
, /* fpAddForm */
867 NULL
, /* fpDeleteForm */
868 NULL
, /* fpGetForm */
869 NULL
, /* fpSetForm */
870 NULL
, /* fpEnumForms */
872 NULL
, /* fpEnumPorts */
873 NULL
, /* fpAddPort */
874 NULL
, /* fpConfigurePort */
875 NULL
, /* fpDeletePort */
876 NULL
, /* fpCreatePrinterIC */
877 NULL
, /* fpPlayGdiScriptOnPrinterIC */
878 NULL
, /* fpDeletePrinterIC */
879 NULL
, /* fpAddPrinterConnection */
880 NULL
, /* fpDeletePrinterConnection */
881 NULL
, /* fpPrinterMessageBox */
882 NULL
, /* fpAddMonitor */
884 NULL
, /* fpResetPrinter */
885 NULL
, /* fpGetPrinterDriverEx */
886 NULL
, /* fpFindFirstPrinterChangeNotification */
887 NULL
, /* fpFindClosePrinterChangeNotification */
888 NULL
, /* fpAddPortEx */
889 NULL
, /* fpShutDown */
890 NULL
, /* fpRefreshPrinterChangeNotification */
891 NULL
, /* fpOpenPrinterEx */
892 NULL
, /* fpAddPrinterEx */
893 NULL
, /* fpSetPort */
894 NULL
, /* fpEnumPrinterData */
895 NULL
, /* fpDeletePrinterData */
896 NULL
, /* fpClusterSplOpen */
897 NULL
, /* fpClusterSplClose */
898 NULL
, /* fpClusterSplIsAlive */
899 NULL
, /* fpSetPrinterDataEx */
900 NULL
, /* fpGetPrinterDataEx */
901 NULL
, /* fpEnumPrinterDataEx */
902 NULL
, /* fpEnumPrinterKey */
903 NULL
, /* fpDeletePrinterDataEx */
904 NULL
, /* fpDeletePrinterKey */
905 NULL
, /* fpSeekPrinter */
906 NULL
, /* fpDeletePrinterDriverEx */
907 NULL
, /* fpAddPerMachineConnection */
908 NULL
, /* fpDeletePerMachineConnection */
909 NULL
, /* fpEnumPerMachineConnections */
910 NULL
, /* fpXcvData */
911 fpAddPrinterDriverEx
,
912 NULL
, /* fpSplReadPrinter */
913 NULL
, /* fpDriverUnloadComplete */
914 NULL
, /* fpGetSpoolFileInfo */
915 NULL
, /* fpCommitSpoolData */
916 NULL
, /* fpCloseSpoolFileHandle */
917 NULL
, /* fpFlushPrinter */
918 NULL
, /* fpSendRecvBidiData */
919 NULL
/* fpAddDriverCatalog */
921 TRACE("=> %p\n", &backend
);
926 /*****************************************************
929 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
931 TRACE("(%p, %d, %p)\n",hinstDLL
, fdwReason
, lpvReserved
);
935 case DLL_WINE_PREATTACH
:
936 return FALSE
; /* prefer native version */
938 case DLL_PROCESS_ATTACH
:
939 DisableThreadLibraryCalls( hinstDLL
);
940 LOCALSPL_hInstance
= hinstDLL
;
948 /*****************************************************
949 * InitializePrintProvidor (localspl.@)
951 * Initialize the Printprovider
954 * pPrintProvidor [I] Buffer to fill with a struct PRINTPROVIDOR
955 * cbPrintProvidor [I] Size of Buffer in Bytes
956 * pFullRegistryPath [I] Registry-Path for the Printprovidor
959 * Success: TRUE and pPrintProvidor filled
963 * The RegistryPath should be:
964 * "System\CurrentControlSet\Control\Print\Providers\<providername>",
965 * but this Parameter is ignored in "localspl.dll".
969 BOOL WINAPI
InitializePrintProvidor(LPPRINTPROVIDOR pPrintProvidor
,
970 DWORD cbPrintProvidor
, LPWSTR pFullRegistryPath
)
973 TRACE("(%p, %u, %s)\n", pPrintProvidor
, cbPrintProvidor
, debugstr_w(pFullRegistryPath
));
974 memcpy(pPrintProvidor
, pp
, (cbPrintProvidor
< sizeof(PRINTPROVIDOR
)) ? cbPrintProvidor
: sizeof(PRINTPROVIDOR
));