Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
03210d44
Commit
03210d44
authored
Mar 07, 2004
by
Stefan Leichter
Committed by
Alexandre Julliard
Mar 07, 2004
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved implementation of GetDefaultPrinter from ascii to unicode, added
tests for GetDefaultPrinterA.
parent
b859a686
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
173 additions
and
49 deletions
+173
-49
info.c
dlls/winspool/info.c
+86
-47
info.c
dlls/winspool/tests/info.c
+87
-2
No files found.
dlls/winspool/info.c
View file @
03210d44
...
...
@@ -101,7 +101,10 @@ static const WCHAR Separator_FileW[] = {'S','e','p','a','r','a','t','o','r',' ',
'i'
,
'l'
,
'e'
,
0
};
static
const
WCHAR
Share_NameW
[]
=
{
'S'
,
'h'
,
'a'
,
'r'
,
'e'
,
' '
,
'N'
,
'a'
,
'm'
,
'e'
,
0
};
static
const
WCHAR
WinPrintW
[]
=
{
'W'
,
'i'
,
'n'
,
'P'
,
'r'
,
'i'
,
'n'
,
't'
,
0
};
static
const
WCHAR
deviceW
[]
=
{
'd'
,
'e'
,
'v'
,
'i'
,
'c'
,
'e'
,
0
};
static
const
WCHAR
devicesW
[]
=
{
'd'
,
'e'
,
'v'
,
'i'
,
'c'
,
'e'
,
's'
,
0
};
static
const
WCHAR
windowsW
[]
=
{
'w'
,
'i'
,
'n'
,
'd'
,
'o'
,
'w'
,
's'
,
0
};
static
const
WCHAR
emptyStringW
[]
=
{
0
};
static
const
WCHAR
May_Delete_Value
[]
=
{
'W'
,
'i'
,
'n'
,
'e'
,
'M'
,
'a'
,
'y'
,
'D'
,
'e'
,
'l'
,
'e'
,
't'
,
'e'
,
'M'
,
'e'
,
0
};
...
...
@@ -3114,66 +3117,102 @@ BOOL WINAPI EnumPortsA(LPSTR name,DWORD level,LPBYTE buffer,DWORD bufsize,
return
TRUE
;
}
/******************************************************************************
* GetDefaultPrinterA (WINSPOOL.@)
* GetDefaultPrinterW (WINSPOOL.@)
*
* FIXME
* This function must read the value from data 'device' of key
* HCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows
*/
BOOL
WINAPI
GetDefaultPrinter
A
(
LP
STR
name
,
LPDWORD
namesize
)
BOOL
WINAPI
GetDefaultPrinter
W
(
LPW
STR
name
,
LPDWORD
namesize
)
{
char
*
ptr
;
BOOL
retval
=
TRUE
;
DWORD
insize
,
len
;
WCHAR
*
buffer
,
*
ptr
;
if
(
*
namesize
<
1
)
{
SetLastError
(
ERROR_INSUFFICIENT_BUFF
ER
);
return
FALSE
;
}
if
(
!
namesize
)
{
SetLastError
(
ERROR_INVALID_PARAMET
ER
);
return
FALSE
;
}
if
(
!
GetProfileStringA
(
"windows"
,
"device"
,
""
,
name
,
*
namesize
))
{
SetLastError
(
ERROR_FILE_NOT_FOUND
);
return
FALSE
;
}
/* make the buffer big enough for the stuff from the profile/registry,
* the content must fit into the local buffer to compute the correct
* size even if the extern buffer is to small or not given.
* (20 for ,driver,port) */
insize
=
*
namesize
;
len
=
max
(
100
,
(
insize
+
20
));
buffer
=
HeapAlloc
(
GetProcessHeap
(),
0
,
len
*
sizeof
(
WCHAR
));
if
((
ptr
=
strchr
(
name
,
','
))
==
NULL
)
{
SetLastError
(
ERROR_FILE_NOT_FOUND
);
return
FALSE
;
}
if
(
!
GetProfileStringW
(
windowsW
,
deviceW
,
emptyStringW
,
buffer
,
len
))
{
SetLastError
(
ERROR_FILE_NOT_FOUND
);
retval
=
FALSE
;
goto
end
;
}
TRACE
(
"%s
\n
"
,
debugstr_w
(
buffer
));
if
((
ptr
=
strchrW
(
buffer
,
','
))
==
NULL
)
{
SetLastError
(
ERROR_INVALID_NAME
);
retval
=
FALSE
;
goto
end
;
}
*
ptr
=
'\0'
;
*
namesize
=
strlen
(
name
)
+
1
;
return
TRUE
;
*
ptr
=
0
;
*
namesize
=
strlenW
(
buffer
)
+
1
;
if
(
!
name
||
(
*
namesize
>
insize
))
{
SetLastError
(
ERROR_INSUFFICIENT_BUFFER
);
retval
=
FALSE
;
goto
end
;
}
strcpyW
(
name
,
buffer
);
end:
if
(
buffer
)
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
return
retval
;
}
/******************************************************************************
* GetDefaultPrinter
W
(WINSPOOL.@)
* GetDefaultPrinter
A
(WINSPOOL.@)
*/
BOOL
WINAPI
GetDefaultPrinter
W
(
LPW
STR
name
,
LPDWORD
namesize
)
BOOL
WINAPI
GetDefaultPrinter
A
(
LP
STR
name
,
LPDWORD
namesize
)
{
char
*
buf
;
BOOL
ret
;
if
(
*
namesize
<
1
)
{
SetLastError
(
ERROR_INSUFFICIENT_BUFFER
);
return
FALSE
;
}
buf
=
HeapAlloc
(
GetProcessHeap
(),
0
,
*
namesize
);
ret
=
GetDefaultPrinterA
(
buf
,
namesize
);
if
(
ret
)
{
DWORD
len
=
MultiByteToWideChar
(
CP_ACP
,
0
,
buf
,
-
1
,
name
,
*
namesize
);
if
(
!
len
)
{
SetLastError
(
ERROR_INSUFFICIENT_BUFFER
);
ret
=
FALSE
;
}
else
*
namesize
=
len
;
}
HeapFree
(
GetProcessHeap
(),
0
,
buf
);
return
ret
;
BOOL
retval
=
TRUE
;
DWORD
insize
=
0
;
WCHAR
*
bufferW
=
NULL
;
if
(
!
namesize
)
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
return
FALSE
;
}
if
(
name
&&
*
namesize
)
{
insize
=
*
namesize
;
bufferW
=
HeapAlloc
(
GetProcessHeap
(),
0
,
insize
*
sizeof
(
WCHAR
));
}
if
(
!
GetDefaultPrinterW
(
bufferW
,
namesize
))
{
retval
=
FALSE
;
goto
end
;
}
*
namesize
=
WideCharToMultiByte
(
CP_ACP
,
0
,
bufferW
,
-
1
,
name
,
insize
,
NULL
,
NULL
);
if
(
!*
namesize
)
{
*
namesize
=
WideCharToMultiByte
(
CP_ACP
,
0
,
bufferW
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
retval
=
FALSE
;
}
TRACE
(
"0x%08lx/0x%08lx:%s
\n
"
,
*
namesize
,
insize
,
debugstr_w
(
bufferW
));
end:
if
(
bufferW
)
HeapFree
(
GetProcessHeap
(),
0
,
bufferW
);
return
retval
;
}
...
...
dlls/winspool/tests/info.c
View file @
03210d44
/*
* Copyright (C) 2003 Stefan Leichter
* Copyright (C) 2003
, 2004
Stefan Leichter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
...
...
@@ -25,7 +25,91 @@
#include "wingdi.h"
#include "winspool.h"
static
void
test_printer_directory
(
ivoid
)
static
void
test_default_printer
(
void
)
{
#define DEFAULT_PRINTER_SIZE 1000
BOOL
retval
;
DWORD
exact
=
DEFAULT_PRINTER_SIZE
;
DWORD
size
;
FARPROC
func
=
NULL
;
HMODULE
lib
=
NULL
;
char
buffer
[
DEFAULT_PRINTER_SIZE
];
lib
=
GetModuleHandleA
(
"winspool.drv"
);
if
(
!
lib
)
{
ok
(
0
,
"GetModuleHandleA(
\"
winspool.drv
\"
) failed
\n
"
);
return
;
}
func
=
GetProcAddress
(
lib
,
"GetDefaultPrinterA"
);
if
(
!
func
)
/* only supported on NT like OSes starting with win2k */
return
;
retval
=
func
(
buffer
,
&
exact
);
if
(
ERROR_FILE_NOT_FOUND
==
GetLastError
())
{
ok
(
0
,
"this test requires a default printer to be set
\n
"
);
return
;
}
if
(
!
retval
||
!
exact
||
!
strlen
(
buffer
))
{
ok
(
0
,
"function call GetDefaultPrinterA failed unexpected!
\n
"
"function returned %s
\n
"
"returned buffer size 0x%08lx
\n
"
"returned buffer content %s
\n
"
,
retval
?
"true"
:
"false"
,
exact
,
buffer
);
return
;
}
SetLastError
(
ERROR_SUCCESS
);
retval
=
func
(
NULL
,
NULL
);
ok
(
!
retval
,
"function result wrong! False expected
\n
"
);
ok
(
ERROR_INVALID_PARAMETER
==
GetLastError
(),
"Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx
\n
"
,
GetLastError
());
SetLastError
(
ERROR_SUCCESS
);
retval
=
func
(
buffer
,
NULL
);
ok
(
!
retval
,
"function result wrong! False expected
\n
"
);
ok
(
ERROR_INVALID_PARAMETER
==
GetLastError
(),
"Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx
\n
"
,
GetLastError
());
SetLastError
(
ERROR_SUCCESS
);
size
=
0
;
retval
=
func
(
NULL
,
&
size
);
ok
(
!
retval
,
"function result wrong! False expected
\n
"
);
ok
(
ERROR_INSUFFICIENT_BUFFER
==
GetLastError
(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx
\n
"
,
GetLastError
());
ok
(
size
==
exact
,
"Parameter size wrong! %ld expected got %ld
\n
"
,
exact
,
size
);
SetLastError
(
ERROR_SUCCESS
);
size
=
DEFAULT_PRINTER_SIZE
;
retval
=
func
(
NULL
,
&
size
);
ok
(
!
retval
,
"function result wrong! False expected
\n
"
);
ok
(
ERROR_INSUFFICIENT_BUFFER
==
GetLastError
(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx
\n
"
,
GetLastError
());
ok
(
size
==
exact
,
"Parameter size wrong! %ld expected got %ld
\n
"
,
exact
,
size
);
size
=
0
;
retval
=
func
(
buffer
,
&
size
);
ok
(
!
retval
,
"function result wrong! False expected
\n
"
);
ok
(
ERROR_INSUFFICIENT_BUFFER
==
GetLastError
(),
"Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx
\n
"
,
GetLastError
());
ok
(
size
==
exact
,
"Parameter size wrong! %ld expected got %ld
\n
"
,
exact
,
size
);
size
=
exact
;
retval
=
func
(
buffer
,
&
size
);
ok
(
retval
,
"function result wrong! True expected
\n
"
);
ok
(
size
==
exact
,
"Parameter size wrong! %ld expected got %ld
\n
"
,
exact
,
size
);
}
static
void
test_printer_directory
(
void
)
{
LPBYTE
buffer
=
NULL
;
DWORD
cbBuf
,
pcbNeeded
;
BOOL
res
;
...
...
@@ -79,5 +163,6 @@ static void test_printer_directory(ivoid)
START_TEST
(
info
)
{
test_default_printer
();
test_printer_directory
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment