Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Pinvoking a non WIN32 API under VB, cant get handle to printer

Pinvoking a non WIN32 API under VB, cant get handle to printer

Scheduled Pinned Locked Moved Visual Basic
helpcsharpjsontutorial
25 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F freakyit

    did you try my example code ??? i am marshalling the string into a LPSTR ;) in the example. greetz

    H Offline
    H Offline
    Hrizip
    wrote on last edited by
    #6

    I have, I also tries it as safearray, LParray, char array and other stuff, same end result, no go.

    H 1 Reply Last reply
    0
    • H Hrizip

      I have, I also tries it as safearray, LParray, char array and other stuff, same end result, no go.

      H Offline
      H Offline
      Hrizip
      wrote on last edited by
      #7

      Its just wierd, the function does return a new value (changes the value before it runs through the function) and sets it to "0" which cant be right. The error code states that no data could be received from the printer. The printer is an USB printer, and it is on, and it does indeed work (prints normally). Why does it return an invalid handle?

      1 Reply Last reply
      0
      • H Hrizip

        I am having some problems getting a printer driver to work in Visual Basic. I am stuck at not being able to get a printer handle from the printer dll. This is what I got thus far;

        Static dll_loaded As Boolean
        If Not dll_loaded Then
        Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
        If dll_handle = 0 Then
        MsgBox("LoadLibrary failed")
        Return
        Else
        dll_loaded = True
        MsgBox("LoadLibrary success!")
        End If
        End If
        Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
        Dim hPrinter As IntPtr = 2
        Dim printerType = 330
        Dim err As Integer = 0

            Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err)
            If err = 61 Then
                MsgBox("Unable to open handle to Zebra printer driver")
            End If
        

        I am using the following pinvoke sig:

        DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
        End Function

        I am getting the following data returned to me as I run this code; hprinter gets changed from 2 (test number) to 0 pname is the stringbuilder (also tried it as a string) printertype is 330 err is 61 It seems that I am getting "through" to the dll but I am unable to get a proper printer handle. This is what I got in Zebra SDK:

        // Load the Zebra MIFARE SDK library
        HMODULE hModule = LoadLibrary(\_T("ZBRGPMF.dll"));
        if (hModule)
        {
        	form1.StatusBox->Text = "The DLL has been successfully loaded.";
        }
        else
        {
        //StatusBox->Text = "Error loading Zebra SDK DLL.";
        return FALSE;
        }
        
        // Get the functions
        zsdkGetHandle		= (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");
        

        HANDLE hPrinter = NULL;
        INT printerType = NULL;
        INT err = 0,
        ret = 0;

        ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err);
        ret = getPrinterStatus(&err);
        

        And by running that example I do get a handle returned (its 0x000000) and the thing works. This is the typedef I got with the SDK:

        typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);

        I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API b

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #8

        Hi, I'd try ByVal hPrinter As IntPtr :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

        H 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, I'd try ByVal hPrinter As IntPtr :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

          H Offline
          H Offline
          Hrizip
          wrote on last edited by
          #9

          Still getting 63 ZBR_ERROR_GETPRINTERDATA_ERROR The handle still = 0

          F 1 Reply Last reply
          0
          • H Hrizip

            Still getting 63 ZBR_ERROR_GETPRINTERDATA_ERROR The handle still = 0

            F Offline
            F Offline
            freakyit
            wrote on last edited by
            #10

            hmm the lib returns an error code so every thing goes right for me. if the function can't be called you will get an exception during the call! that means there will be no return value! check what exactly ZBR_ERROR_GETPRINTERDATA_ERROR means. you may have other errors that cause to an ZBR_ERROR_GETPRINTERDATA_ERROR by calling your pinvoke sig... blessssss it :)

            H 1 Reply Last reply
            0
            • F freakyit

              hmm the lib returns an error code so every thing goes right for me. if the function can't be called you will get an exception during the call! that means there will be no return value! check what exactly ZBR_ERROR_GETPRINTERDATA_ERROR means. you may have other errors that cause to an ZBR_ERROR_GETPRINTERDATA_ERROR by calling your pinvoke sig... blessssss it :)

              H Offline
              H Offline
              Hrizip
              wrote on last edited by
              #11

              I am having doubts that Zebra SDK dll doesnt communicate with the printer for some reason which I cannot discern as I did not make the dll itself. I have no option but to contact Zebra, although I wont hold my breath, software programming support is usually abysmal. ;(

              1 Reply Last reply
              0
              • H Hrizip

                I am having some problems getting a printer driver to work in Visual Basic. I am stuck at not being able to get a printer handle from the printer dll. This is what I got thus far;

                Static dll_loaded As Boolean
                If Not dll_loaded Then
                Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
                If dll_handle = 0 Then
                MsgBox("LoadLibrary failed")
                Return
                Else
                dll_loaded = True
                MsgBox("LoadLibrary success!")
                End If
                End If
                Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
                Dim hPrinter As IntPtr = 2
                Dim printerType = 330
                Dim err As Integer = 0

                    Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err)
                    If err = 61 Then
                        MsgBox("Unable to open handle to Zebra printer driver")
                    End If
                

                I am using the following pinvoke sig:

                DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                End Function

                I am getting the following data returned to me as I run this code; hprinter gets changed from 2 (test number) to 0 pname is the stringbuilder (also tried it as a string) printertype is 330 err is 61 It seems that I am getting "through" to the dll but I am unable to get a proper printer handle. This is what I got in Zebra SDK:

                // Load the Zebra MIFARE SDK library
                HMODULE hModule = LoadLibrary(\_T("ZBRGPMF.dll"));
                if (hModule)
                {
                	form1.StatusBox->Text = "The DLL has been successfully loaded.";
                }
                else
                {
                //StatusBox->Text = "Error loading Zebra SDK DLL.";
                return FALSE;
                }
                
                // Get the functions
                zsdkGetHandle		= (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");
                

                HANDLE hPrinter = NULL;
                INT printerType = NULL;
                INT err = 0,
                ret = 0;

                ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err);
                ret = getPrinterStatus(&err);
                

                And by running that example I do get a handle returned (its 0x000000) and the thing works. This is the typedef I got with the SDK:

                typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);

                I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API b

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #12

                the SDK said INT printerType = NULL; yet you pass 330? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                H 1 Reply Last reply
                0
                • L Luc Pattyn

                  the SDK said INT printerType = NULL; yet you pass 330? :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                  H Offline
                  H Offline
                  Hrizip
                  wrote on last edited by
                  #13

                  I tried both; 1) nothing, 2) 330, 1) byval and 2) byref, same result in all cases.

                  1 Reply Last reply
                  0
                  • H Hrizip

                    I am having some problems getting a printer driver to work in Visual Basic. I am stuck at not being able to get a printer handle from the printer dll. This is what I got thus far;

                    Static dll_loaded As Boolean
                    If Not dll_loaded Then
                    Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
                    If dll_handle = 0 Then
                    MsgBox("LoadLibrary failed")
                    Return
                    Else
                    dll_loaded = True
                    MsgBox("LoadLibrary success!")
                    End If
                    End If
                    Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
                    Dim hPrinter As IntPtr = 2
                    Dim printerType = 330
                    Dim err As Integer = 0

                        Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err)
                        If err = 61 Then
                            MsgBox("Unable to open handle to Zebra printer driver")
                        End If
                    

                    I am using the following pinvoke sig:

                    DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                    End Function

                    I am getting the following data returned to me as I run this code; hprinter gets changed from 2 (test number) to 0 pname is the stringbuilder (also tried it as a string) printertype is 330 err is 61 It seems that I am getting "through" to the dll but I am unable to get a proper printer handle. This is what I got in Zebra SDK:

                    // Load the Zebra MIFARE SDK library
                    HMODULE hModule = LoadLibrary(\_T("ZBRGPMF.dll"));
                    if (hModule)
                    {
                    	form1.StatusBox->Text = "The DLL has been successfully loaded.";
                    }
                    else
                    {
                    //StatusBox->Text = "Error loading Zebra SDK DLL.";
                    return FALSE;
                    }
                    
                    // Get the functions
                    zsdkGetHandle		= (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");
                    

                    HANDLE hPrinter = NULL;
                    INT printerType = NULL;
                    INT err = 0,
                    ret = 0;

                    ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err);
                    ret = getPrinterStatus(&err);
                    

                    And by running that example I do get a handle returned (its 0x000000) and the thing works. This is the typedef I got with the SDK:

                    typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);

                    I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API b

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #14

                    I looked deeper into the matter, here is my conclusion:

                    <DllImport("ZBRPrinter.dll")>
                    Public Shared Function ZBRGetHandle(ByVal hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                    End Function

                    which means: 1. no SetLastError (where did you get that idea? there already is an error pointer) 2. no Charset.Auto (the native code expects ANSI, which is the default) 3. pointers normally get passed by value reminder: printerType in the SDK example was zero, not 330. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                    H 2 Replies Last reply
                    0
                    • L Luc Pattyn

                      I looked deeper into the matter, here is my conclusion:

                      <DllImport("ZBRPrinter.dll")>
                      Public Shared Function ZBRGetHandle(ByVal hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                      End Function

                      which means: 1. no SetLastError (where did you get that idea? there already is an error pointer) 2. no Charset.Auto (the native code expects ANSI, which is the default) 3. pointers normally get passed by value reminder: printerType in the SDK example was zero, not 330. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                      H Offline
                      H Offline
                      Hrizip
                      wrote on last edited by
                      #15

                      In the meantime I also tried it without SetLastError and Charset.Auto, and I toyed around with byval/byref, nothing changed. I also did try it with printerType set to both zero and 330 , with same result. I have found someone with a similar problem, unfortuantely the said individual does his programming in delphi so I am still trying to understand what he said, heres the text: I am attempting to access a function in a C-style DLL, written in Microsoft Visual C++ version 6.0. The function is defined as follows: INT __stdcall ZBRGetHandle(LPHANDLE hPrinter, LPSTR pName, LPINT printerType, LPINT err) In my Delphi project, I prototype the function as: function ZBRGetHandle(var handle: THandle; var drvName: Array of Byte; var prnType: Integer; var err: Integer) : Integer; {$IFDEF WIN32} stdcall; {$ENDIF} external 'ZBRPrinter.dll' ; I have a wrapper function within a class that calls this function. The class method is defined as: function Open(var drvName: array of Byte; var errValue: Integer) : Integer; stdcall; I call it as: function TZBRPrinter.Open(var drvName: Array of Byte; var errValue: Integer) : Integer; stdcall; begin Result := ZBRGetHandle(_handle, drvName, _prnType, errValue); end; note: _handle & _prnType are defined within the class TZBRPrinter as: private _handle: THandle; // _handle to printer driver _prnType: Integer; I initialize both variables in the class constructor: constructor TZBRPrinter.Create; begin // Execute the parent (TObject) constructor first inherited; // Call the parent Create method // Now set defaults self._handle := 0; self._prnType := 100; end; errValue is set to -1 prior to the call to TZBRPrinter.Open. In an attempt to root-cause the problem, I used my delphi executable as the debugging application for my ZBRPrinter.dll project. When the ZBRGetHandle is called via the Delphi application, what I find is puzzling: With respect to ZBRGetHandle within the dll source code, I find that the 3rd parameter, LPINT printerType, is invalid, and the 4th parameter, LPINT err is set to 100. The first 2 parameters are correct. I have tried using a fixed array of bytes and chars as the second parameter, and a String, yet I find that I still encounter problems when passing all 4 parameters to this DLL function. I find that if the dll's second parameter only gets the first char of the string, then the 3rd parameter gets the value 100, and the 4th gets the value -1 as I intend. If t

                      L 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        I looked deeper into the matter, here is my conclusion:

                        <DllImport("ZBRPrinter.dll")>
                        Public Shared Function ZBRGetHandle(ByVal hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                        End Function

                        which means: 1. no SetLastError (where did you get that idea? there already is an error pointer) 2. no Charset.Auto (the native code expects ANSI, which is the default) 3. pointers normally get passed by value reminder: printerType in the SDK example was zero, not 330. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                        Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                        H Offline
                        H Offline
                        Hrizip
                        wrote on last edited by
                        #16

                        And here is the SDK manual for those who may find it interesting, the same web page also hosts the entire SDK. http://support.online-dubai.com/embu/Zebra/ZEBRA%20CARD%20PRINTERS/Technical/PrinterSetup_v2.06.04/program%20files/Zebra%20Technologies/Zebra%20SDK/Zebra%20SDK%20Reference%20Manual/SDKReferenceManual.pdf

                        H 1 Reply Last reply
                        0
                        • H Hrizip

                          In the meantime I also tried it without SetLastError and Charset.Auto, and I toyed around with byval/byref, nothing changed. I also did try it with printerType set to both zero and 330 , with same result. I have found someone with a similar problem, unfortuantely the said individual does his programming in delphi so I am still trying to understand what he said, heres the text: I am attempting to access a function in a C-style DLL, written in Microsoft Visual C++ version 6.0. The function is defined as follows: INT __stdcall ZBRGetHandle(LPHANDLE hPrinter, LPSTR pName, LPINT printerType, LPINT err) In my Delphi project, I prototype the function as: function ZBRGetHandle(var handle: THandle; var drvName: Array of Byte; var prnType: Integer; var err: Integer) : Integer; {$IFDEF WIN32} stdcall; {$ENDIF} external 'ZBRPrinter.dll' ; I have a wrapper function within a class that calls this function. The class method is defined as: function Open(var drvName: array of Byte; var errValue: Integer) : Integer; stdcall; I call it as: function TZBRPrinter.Open(var drvName: Array of Byte; var errValue: Integer) : Integer; stdcall; begin Result := ZBRGetHandle(_handle, drvName, _prnType, errValue); end; note: _handle & _prnType are defined within the class TZBRPrinter as: private _handle: THandle; // _handle to printer driver _prnType: Integer; I initialize both variables in the class constructor: constructor TZBRPrinter.Create; begin // Execute the parent (TObject) constructor first inherited; // Call the parent Create method // Now set defaults self._handle := 0; self._prnType := 100; end; errValue is set to -1 prior to the call to TZBRPrinter.Open. In an attempt to root-cause the problem, I used my delphi executable as the debugging application for my ZBRPrinter.dll project. When the ZBRGetHandle is called via the Delphi application, what I find is puzzling: With respect to ZBRGetHandle within the dll source code, I find that the 3rd parameter, LPINT printerType, is invalid, and the 4th parameter, LPINT err is set to 100. The first 2 parameters are correct. I have tried using a fixed array of bytes and chars as the second parameter, and a String, yet I find that I still encounter problems when passing all 4 parameters to this DLL function. I find that if the dll's second parameter only gets the first char of the string, then the 3rd parameter gets the value 100, and the 4th gets the value -1 as I intend. If t

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #17

                          sorry, that's too messy for me to understand. you have an existing Delphi program that works? and your own VB.NET program that doesn't? if .NET 4.0 calling conventions are checked more severely. if Win64, pointers take 8-byte :)

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                          Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                          H 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            sorry, that's too messy for me to understand. you have an existing Delphi program that works? and your own VB.NET program that doesn't? if .NET 4.0 calling conventions are checked more severely. if Win64, pointers take 8-byte :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                            Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                            H Offline
                            H Offline
                            Hrizip
                            wrote on last edited by
                            #18

                            I have SDkit provided by Zebra company, which features some C examples (which produce the same error as my VB.net code), I have my own code done in VB.net, the Delphi code was done by someone else on the internet (I do not have this code) and he stumbled into an extremely similar (maybe even identical) problem as I did. My string (the name of the printer) is null terminated and I did try to pass that as LParray, safearray, char array and stringbuilder (same result = fail), one time I passed it as a pointer to the first character in the arrey (namely character "Z"), that time I didnt get the error code 63 nor 61 but the handle returned was still 0. It is possible that I need to find a way to marshal this null terminated char array by the way of not sending only the pointer to the first element in the array but to the entire segment of memory, I do not know how to do this. Even if I manage to do it, which I will certainly try to do, I might still get 0 as returned printer handle value. No matter what I do, the returned printer handle always is "0", I think the dll is not able to communicate to the hardware hence errors 61 and 63 (no data from printer), hence invalid printer handle.

                            L 1 Reply Last reply
                            0
                            • H Hrizip

                              I have SDkit provided by Zebra company, which features some C examples (which produce the same error as my VB.net code), I have my own code done in VB.net, the Delphi code was done by someone else on the internet (I do not have this code) and he stumbled into an extremely similar (maybe even identical) problem as I did. My string (the name of the printer) is null terminated and I did try to pass that as LParray, safearray, char array and stringbuilder (same result = fail), one time I passed it as a pointer to the first character in the arrey (namely character "Z"), that time I didnt get the error code 63 nor 61 but the handle returned was still 0. It is possible that I need to find a way to marshal this null terminated char array by the way of not sending only the pointer to the first element in the array but to the entire segment of memory, I do not know how to do this. Even if I manage to do it, which I will certainly try to do, I might still get 0 as returned printer handle value. No matter what I do, the returned printer handle always is "0", I think the dll is not able to communicate to the hardware hence errors 61 and 63 (no data from printer), hence invalid printer handle.

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #19

                              I looked in the manual (ZBRGetHandle defined on p12 , example p219), and I now see: - the Handle is going to be returned, so it must be ByRef after all. - passing the name should be no problem at all, a simple string is all it takes, not even a StringBuilder; - strangely enough printerType is an int and needs being passed by reference (don't see why). So I'll go for:

                              Dim hPrinter As IntPtr 
                              Dim printerType As Integer = 330
                              Dim err As Integer = 0
                              
                              Dim ret As IntPtr = ZBRGetHandle(hPrinter, "Zebra P330i USB Card Printer", printerType, err)
                              

                              <DllImport("ZBRPrinter.dll")>
                              Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As String, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                              End Function

                              What I do not understand is why you load the DLL first, see your LoadLibrary. P/Invoke does not need (not even want?) that, and the DLL must be found by regular Windows PATH scanning. :)

                              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                              Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                              H 1 Reply Last reply
                              0
                              • L Luc Pattyn

                                I looked in the manual (ZBRGetHandle defined on p12 , example p219), and I now see: - the Handle is going to be returned, so it must be ByRef after all. - passing the name should be no problem at all, a simple string is all it takes, not even a StringBuilder; - strangely enough printerType is an int and needs being passed by reference (don't see why). So I'll go for:

                                Dim hPrinter As IntPtr 
                                Dim printerType As Integer = 330
                                Dim err As Integer = 0
                                
                                Dim ret As IntPtr = ZBRGetHandle(hPrinter, "Zebra P330i USB Card Printer", printerType, err)
                                

                                <DllImport("ZBRPrinter.dll")>
                                Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As String, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
                                End Function

                                What I do not understand is why you load the DLL first, see your LoadLibrary. P/Invoke does not need (not even want?) that, and the DLL must be found by regular Windows PATH scanning. :)

                                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                                Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                                H Offline
                                H Offline
                                Hrizip
                                wrote on last edited by
                                #20

                                No idea why I implemented loadlibrary, when I started working on this project first I tried to translate c code to vb code practically line by line, loadlibrary was the first thing on the way. I didnt think it might wreak havoc when combined with pinvoking , I will be removing it to see what happens. I have already tried your solution - it didnt work. I always get hPrinter returned as "0". I simply cant get the printer to return a valid handle. There is no way of finding out whether the dll communicates with the printer, therefore I cannot figure out what this 0 I get returned means, does it mean that no printer was found or something else? With no way of knowing how (and if) the dll, in itself, communicates with the hardware, I cant troubleshoot this.

                                L 1 Reply Last reply
                                0
                                • H Hrizip

                                  No idea why I implemented loadlibrary, when I started working on this project first I tried to translate c code to vb code practically line by line, loadlibrary was the first thing on the way. I didnt think it might wreak havoc when combined with pinvoking , I will be removing it to see what happens. I have already tried your solution - it didnt work. I always get hPrinter returned as "0". I simply cant get the printer to return a valid handle. There is no way of finding out whether the dll communicates with the printer, therefore I cannot figure out what this 0 I get returned means, does it mean that no printer was found or something else? With no way of knowing how (and if) the dll, in itself, communicates with the hardware, I cant troubleshoot this.

                                  L Offline
                                  L Offline
                                  Luc Pattyn
                                  wrote on last edited by
                                  #21

                                  while there isn't much text in the manual, the way I understand the available information is: 1. you need to install your printer and its driver somehow; that should result in it being visible in the list of installed printers. 2. your program needs to start with a GetHandle, which returns success/failure and an error code on failure. Those should be self-explanatory. The one thing .NET adds here is some uncertainty about the P/Invoke stuff, due to gaps in the doc, not shortcomings of .NET Therefore: 1. do you see your printer in say MS Word? 2. could you try the C example? Once those two work well, getting VB.NET up and printing should be simple. :)

                                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                                  Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                                  H 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    while there isn't much text in the manual, the way I understand the available information is: 1. you need to install your printer and its driver somehow; that should result in it being visible in the list of installed printers. 2. your program needs to start with a GetHandle, which returns success/failure and an error code on failure. Those should be self-explanatory. The one thing .NET adds here is some uncertainty about the P/Invoke stuff, due to gaps in the doc, not shortcomings of .NET Therefore: 1. do you see your printer in say MS Word? 2. could you try the C example? Once those two work well, getting VB.NET up and printing should be simple. :)

                                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                                    Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                                    H Offline
                                    H Offline
                                    Hrizip
                                    wrote on last edited by
                                    #22

                                    USB interface - tested, can print, can use windows driver, cant use my app, cant use SDK app Ethernet interface - tested, can print, can use win driver, cant use my app, cant use SDK app This was tested on both win 7 and win Vista, I also tried it on VMWARE windows XP SP2 but it crashed immidiately, but possible due to virtualization itself. Tomorrow I will try it on "pure" Windows XP, but I dont expect much.

                                    L 1 Reply Last reply
                                    0
                                    • H Hrizip

                                      USB interface - tested, can print, can use windows driver, cant use my app, cant use SDK app Ethernet interface - tested, can print, can use win driver, cant use my app, cant use SDK app This was tested on both win 7 and win Vista, I also tried it on VMWARE windows XP SP2 but it crashed immidiately, but possible due to virtualization itself. Tomorrow I will try it on "pure" Windows XP, but I dont expect much.

                                      L Offline
                                      L Offline
                                      Luc Pattyn
                                      wrote on last edited by
                                      #23

                                      from that information, I would focus on a real XP system, no virtualization, no UAC stuff. Vista & 7 keep regular users away from protected data, you can't even get a disk's serial number as that requires an OpenFile(mydisk). If that turns out to be the problem, the manufacturer will be bound to come up with a solution, as the Windows world is slowly moving to Vista/7 and they can't ignore that. FWIW: and the error code(s) should be more informative! :)

                                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                                      Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                                      H 1 Reply Last reply
                                      0
                                      • L Luc Pattyn

                                        from that information, I would focus on a real XP system, no virtualization, no UAC stuff. Vista & 7 keep regular users away from protected data, you can't even get a disk's serial number as that requires an OpenFile(mydisk). If that turns out to be the problem, the manufacturer will be bound to come up with a solution, as the Windows world is slowly moving to Vista/7 and they can't ignore that. FWIW: and the error code(s) should be more informative! :)

                                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                                        Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                                        H Offline
                                        H Offline
                                        Hrizip
                                        wrote on last edited by
                                        #24

                                        Their SDK is from 2007, done in C, and their support people havent responded to my queries yet, I wont hold my breath ;) If we had known we would have gone with a different manufacturer.

                                        1 Reply Last reply
                                        0
                                        • H Hrizip

                                          And here is the SDK manual for those who may find it interesting, the same web page also hosts the entire SDK. http://support.online-dubai.com/embu/Zebra/ZEBRA%20CARD%20PRINTERS/Technical/PrinterSetup_v2.06.04/program%20files/Zebra%20Technologies/Zebra%20SDK/Zebra%20SDK%20Reference%20Manual/SDKReferenceManual.pdf

                                          H Offline
                                          H Offline
                                          Hrizip
                                          wrote on last edited by
                                          #25

                                          It (SDK example) crashes with no relevant error code even on "pure" windows XP SP2 machine which normally accesses the printer. I have (finally) been contacted by Zebra support, they have given me an email address, which unfortunately does not exist.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups