locked
CreateFileA trigger invalid handle in win7 RRS feed

  • 問題

  • 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.

    2010年7月21日 6:07

所有回覆

  • What is the error message?
    大家一齊探討、學習和研究,謝謝!
    Microsoft MVP, Microsoft Community Star(TW & HK), MCT,
    MCSD, MCAD, MCSE+I, MCDBA, MCDST, MCSA, MCTS, MCITP, MCPD
    2011年4月20日 6:44