OpenPrinter() Problem

Hello all,

I thought this would be pretty simple, but apparently I've managed to do something wrong. I'm trying to retrieve the handle to a certain printer on the network, as shown below:

1
2
3
4
5
6
LPHANDLE p_hPrinter;

if (OpenPrinter("\\\\saturn\\PHOBOS",p_hPrinter,NULL)) 
   MessageBox (hwnd,"Success.","",MB_OK);
else 
   MessageBox(hwnd,"Failure.","",MB_OK);


This fails. Yes, this is the correct location of the printer:

(\\servername\printername) \\saturn\PHOBOS

... and I believe I'm correct in using the escape characters, so what else could be incorrect here? Thanks in advance for any help.
had a quick look at the function description - and it seems like the second parameter (the handle has been setip incorrectly.
It should be like this?
1
2
3
4
5
6
HANDLE p_hPrinter;

if (OpenPrinter("\\\\saturn\\PHOBOS",&p_hPrinter,NULL)) 
   MessageBox (hwnd,"Success.","",MB_OK);
else 
   MessageBox(hwnd,"Failure.","",MB_OK);


Windows fills in the handle - so you pass the address of the handle - NOT a (unitialised) pointer to a handle.

The function also sets lasterror so you can call get getLastError() immediately to see what the error was.
Thank you! That worked...

So, I'm assuming that since I created only a pointer, but no value for it to actually point to, that the function does not actually create it if it does not exist.

So by declaring a HANDLE instead and passing by reference, the function is simply replacing the existing (but meaningless) handle value which was already initialized?

If that's the case, it makes plenty of sense, and now I'm a lot less confused about some other things as well. Thanks again.
Topic archived. No new replies allowed.