I have a program which use createfileA() to open a lan shared printer. It works fine in winxp. However, when run the program in Win7, it will produce "Invalid Handle" error. Below is my code extracted:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES,
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer
Dim hPortP As SafeHandle = Nothing
Dim printerPath as String =
\\199.198.2.1\SharedPrinter1"
'Create connection
hPortP = CreateFile(printerPath, GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
Any idea what is the cause and how to resolve it? Thanks.