Andrew Falanga
2010-02-12 23:43:38 UTC
Hi,
Ultimately, this is to be used in C#, and I asked first there but was
told I might get better suggestions on using CreateFile( ) here. I
figured out how to use CreateFile( ), now I'm hoping that you all can
tell me if I'm doing it correctly because of the problems I'm having
with CloseHandle( ).
I'm using CreateFile( ) to make a file handle to a printer share so
that I write binary data directory to the printer. I'm able to create
my file ok using CreateFile( ). I'm passing the following parameters
to CreateFile:
CreateFile("path",
0x2, // Generic Write
0, // ignore sharing mode
IntPtr.Zero, // C# equivalent to NULL Pointer for
security attr
0x3, // OPEN_EXISTING
0x80, // flags and attr of FILE_ATTRIBUTE_NORMAL
IntPtr.Zero // again, NULL pointer template file
);
The call returns a valid handle and I'm even able to use it, though,
for some reason not 100% of the time. That is, sometimes I print ok,
others times the printer just sits there. At any rate, when I call
CloseHandle( ) on the handle that I made through CreateFile( ), I get
a false return (from the bool) and my code errors with "can't close
the handle." Is this normal? Should I open a printer share
differently than I am?
Any help is greatly appreciated.
Thanks,
Andy
Ultimately, this is to be used in C#, and I asked first there but was
told I might get better suggestions on using CreateFile( ) here. I
figured out how to use CreateFile( ), now I'm hoping that you all can
tell me if I'm doing it correctly because of the problems I'm having
with CloseHandle( ).
I'm using CreateFile( ) to make a file handle to a printer share so
that I write binary data directory to the printer. I'm able to create
my file ok using CreateFile( ). I'm passing the following parameters
to CreateFile:
CreateFile("path",
0x2, // Generic Write
0, // ignore sharing mode
IntPtr.Zero, // C# equivalent to NULL Pointer for
security attr
0x3, // OPEN_EXISTING
0x80, // flags and attr of FILE_ATTRIBUTE_NORMAL
IntPtr.Zero // again, NULL pointer template file
);
The call returns a valid handle and I'm even able to use it, though,
for some reason not 100% of the time. That is, sometimes I print ok,
others times the printer just sits there. At any rate, when I call
CloseHandle( ) on the handle that I made through CreateFile( ), I get
a false return (from the bool) and my code errors with "can't close
the handle." Is this normal? Should I open a printer share
differently than I am?
Any help is greatly appreciated.
Thanks,
Andy