Click to See Complete Forum and Search --> : [RESOLVED] EnumPorts error


rjbez
August 19th, 2009, 03:14 PM
I did a search and couldn't find any help. I am calling EnumPorts to get a list of network printers installed on the computer. When I call EnumPorts the first time (to find the buffer size) it returns 0 (fails) and GetLastError() gives : 1722 (RPC server is unavailable). Has anyone seen this before?

I call EnumPorts in the install, but when I call the uninstall it gives this error.

Further info: this is in a driver and being built with WDK 7100


DWORD needed(0);
DWORD returned(0);
DWORD status = ERROR_SUCCESS;
DWORD err;
SetLastError(ERROR_SUCCESS);

BOOL brc = EnumPorts(NULL, 1, NULL, 0, &needed, &returned);
err = GetLastError();//err = 1722 at this point
PORT_INFO_1* port_into_1s = (PORT_INFO_1*) new BYTE[needed];
brc = EnumPorts(NULL, 1, (PBYTE) port_into_1s, needed, &needed, &returned);
err = GetLastError(); err = 1722 at this point

rjbez
August 21st, 2009, 01:28 PM
Solved. Turns out I called EnumPorts() when we still had teh spooler turned off. Changed the call to after we restart the spooler and worked great.