// Finally use the function as intended and aim for success!
// After that, cbTemp contains the needed buffer size without the computer name prepended.
pMem=HeapAlloc(GetProcessHeap(),0,cbNeeded);
SetLastError(0xDEADBEEF);
ok(EnumPrintersW(PRINTER_ENUM_LOCAL,NULL,Level,pMem,cbNeeded,&cbTemp,&dwReturned),"EnumPrintersW returns FALSE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_SUCCESS,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
HeapFree(GetProcessHeap(),0,pMem);
if(Level!=4)
{
// Show that the Name parameter is checked when PRINTER_ENUM_NAME is also specified.
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL|PRINTER_ENUM_NAME,L"LOREM IPSUM",Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()!=ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==0,"cbNeeded is %lu for Level %lu!\n",cbNeeded,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
}
// Show that the structure is returned with its known size again when PRINTER_ENUM_NAME is specified and Name
// is the (case-insensitively compared) name of the Local Print Provider.
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL|PRINTER_ENUM_NAME,L"wInDoWs NT Local Print Providor",Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==cbTemp,"cbNeeded is %lu, reference size is %lu for Level %lu!\n",cbNeeded,cbTemp,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
// Now we specify the correct "\\COMPUTERNAME" for Name.
// The returned structure should have some strings prepended with the Computer Name and thus require a larger buffer.
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL|PRINTER_ENUM_NAME,wszComputerName,Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded>cbTemp,"cbNeeded is %lu, reference size is %lu for Level %lu!\n",cbNeeded,cbTemp,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
if(Level!=4)
{
// This won't work when there is a trailing backslash (i.e. "\\COMPUTERNAME\").
wszComputerName[cchComputerName++]=L'\\';
wszComputerName[cchComputerName]=0;
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL|PRINTER_ENUM_NAME,wszComputerName,Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INVALID_NAME,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==0,"cbNeeded is %lu for Level %lu!\n",cbNeeded,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
wszComputerName[--cchComputerName]=0;
}
// Now it gets funky. There are also cases where EnumPrintersW takes the Name parameter into account,
// although PRINTER_ENUM_NAME is not given.
// A bogus Name without two backslashes is ignored.
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL,L"LOREM IPSUM",Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==cbTemp,"cbNeeded is %lu, reference size is %lu for Level %lu!\n",cbNeeded,cbTemp,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
// Specifying "\\COMPUTERNAME" again prepends it to some strings.
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL,wszComputerName,Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded>cbTemp,"cbNeeded is %lu, reference size is %lu for Level %lu!\n",cbNeeded,cbTemp,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
// Specifying "\\COMPUTERNAME\" also verifies the Computer Name, but doesn't prepend it.
// This logic is crazy, and different to PRINTER_ENUM_NAME...
wszComputerName[cchComputerName++]=L'\\';
wszComputerName[cchComputerName]=0;
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL,wszComputerName,Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==cbTemp,"cbNeeded is %lu for Level %lu!\n",cbNeeded,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
// I can even put an additional bogus character after the trailing backslash, doesn't change anything.
wszComputerName[cchComputerName++]=L'a';
wszComputerName[cchComputerName]=0;
SetLastError(0xDEADBEEF);
ok(!EnumPrintersW(PRINTER_ENUM_LOCAL,wszComputerName,Level,NULL,0,&cbNeeded,&dwReturned),"EnumPrintersW returns TRUE for Level %lu!\n",Level);
ok(GetLastError()==ERROR_INSUFFICIENT_BUFFER,"EnumPrintersW returns error %lu for Level %lu!\n",GetLastError(),Level);
ok(cbNeeded==cbTemp,"cbNeeded is %lu for Level %lu!\n",cbNeeded,Level);
ok(dwReturned==0,"dwReturned is %lu for Level %lu!\n",dwReturned,Level);
cchComputerName-=2;
wszComputerName[cchComputerName]=0;
}
else
{
skip("cbNeeded is 0 on Level %lu, skipping additional tests!\n",Level);