Problems in exe file of project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • creative1
    Contributor
    • Sep 2007
    • 274

    Problems in exe file of project

    Hi everyone
    I am facing a strange problem in the exe file of my project. i.e

    I created setup for software instllation. I tried it on my PC and works fine. However, when my supervisor run it on his laptop i.e connected to a wireless network; and a printer is attached in the network. He complains that:

    he is not able to Save a transaction and Print it on his laptop.(When I save a transection it prints a ticket and then save it). When he Reprint Last Ticket(last performed transection) it generates a MDI file and opens Microsift Office Document Imaging.

    p.s.Currently I m working on a standalone computer with a dedicated printer attached to it.

    I am not able ti understand what the problem is. As its working on my pc and save a transection. I hope I'll get a useful information to resolve thid problem.
    Farhana
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    It could just be a matter of what he has set up as his default printer.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      Hi,

      Why don't you try installing a new printer in your client's system?
      Maybe his default printer is configured to print to a file.

      Regards
      Veena
      Last edited by Killer42; Oct 7 '07, 05:07 AM.

      Comment

      • Mayur2007
        New Member
        • Aug 2007
        • 67

        #4
        Originally posted by creative1
        ...when my supervisor run it on his laptop i.e connected to a wireless network; and a printer is attached in the network. He complains that:

        he is not able to Save a transaction and Print it on his laptop...
        Hi ,

        Make sure that if you are using any .dll file or other then it should be in the same folder in which you have saved the VB project. Make changes in the code like if you give the path as "\\server\abc\d ddd\mm.bmp" then just change it to "mm.bmp".
        I was facing same type of problem as you are facing but after that solution my problem is solved out.

        Mayur
        Last edited by Killer42; Oct 12 '07, 08:22 AM. Reason: Reduced excessive quote block

        Comment

        • creative1
          Contributor
          • Sep 2007
          • 274

          #5
          Hello guys thanks for your help
          Problem is solved and ticket can be printed and transection is saved successfully into the machine.

          What I did?
          I used default printer attached to the PC to print ticket, before this I had mentioned which printer to use to print the ticket. I think my client and I didn't have same printers.

          But this is not what I want to do. Actually I want to select a printer at runtime because I want to print tickets on ticket printer and reports on another printer

          Any clues?? please

          thanks in advance
          Farhana

          Comment

          • 9815402440
            New Member
            • Oct 2007
            • 180

            #6
            hi
            following is the code to set default printer

            open a new standard exe project
            add a moudle

            on the form1 draw a command button and name it cmdSetDef
            add a listbox List1

            copy and paste following code in the Form1 code window
            [code=vb]
            Private Function PtrCtoVbString( Add As Long) As String

            Dim sTemp As String * 512, x As Long

            x = lstrcpy(sTemp, Add)
            If (InStr(1, sTemp, Chr(0)) = 0) Then
            PtrCtoVbString = ""
            Else
            PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)
            End If
            End Function

            Private Sub Win95SetDefault Printer()
            Dim Handle As Long 'handle to printer
            Dim PrinterName As String
            Dim pd As PRINTER_DEFAULT S
            Dim x As Long
            Dim need As Long ' bytes needed
            Dim pi5 As PRINTER_INFO_5 ' your PRINTER_INFO structure
            Dim LastError As Long

            ' determine which printer was selected
            PrinterName = List1.List(List 1.ListIndex)
            ' none - exit
            If PrinterName = "" Then
            Exit Sub
            End If

            ' set the PRINTER_DEFAULT S members
            pd.pDatatype = 0&
            pd.DesiredAcces s = PRINTER_ALL_ACC ESS

            ' Get a handle to the printer
            x = OpenPrinter(Pri nterName, Handle, pd)
            ' failed the open
            If x = False Then
            'error handler code goes here
            Exit Sub
            End If

            ' Make an initial call to GetPrinter, requesting Level 5
            ' (PRINTER_INFO_5 ) information, to determine how many bytes
            ' you need
            x = GetPrinter(Hand le, 5, ByVal 0&, 0, need)
            ' don't want to check GetLastError here - it's supposed to fail
            ' with a 122 - ERROR_INSUFFICI ENT_BUFFER
            ' redim t as large as you need
            ReDim t((need \ 4)) As Long

            ' and call GetPrinter for keepers this time
            x = GetPrinter(Hand le, 5, t(0), need, need)
            ' failed the GetPrinter
            If x = False Then
            'error handler code goes here
            Exit Sub
            End If

            ' set the members of the pi5 structure for use with SetPrinter.
            ' PtrCtoVbString copies the memory pointed at by the two string
            ' pointers contained in the t() array into a Visual Basic string.
            ' The other three elements are just DWORDS (long integers) and
            ' don't require any conversion
            pi5.pPrinterNam e = PtrCtoVbString( t(0))
            pi5.pPortName = PtrCtoVbString( t(1))
            pi5.Attributes = t(2)
            pi5.DeviceNotSe lectedTimeout = t(3)
            pi5.Transmissio nRetryTimeout = t(4)

            ' this is the critical flag that makes it the default printer
            pi5.Attributes = PRINTER_ATTRIBU TE_DEFAULT

            ' call SetPrinter to set it
            x = SetPrinter(Hand le, 5, pi5, 0)
            ' failed the SetPrinter
            If x = False Then
            MsgBox "SetPrinterFail ed. Error code: " & GetLastError()
            Exit Sub
            End If

            ' and close the handle
            ClosePrinter (Handle)

            End Sub
            Private Sub GetDriverAndPor t(ByVal Buffer As String, DriverName As String, PrinterPort As String)
            Dim iDriver As Integer
            Dim iPort As Integer
            DriverName = ""
            PrinterPort = ""

            'The driver name is first in the string terminated by a comma
            iDriver = InStr(Buffer, ",")
            If iDriver > 0 Then

            'Strip out the driver name
            DriverName = Left(Buffer, iDriver - 1)

            'The port name is the second entry after the driver name
            'separated by commas.
            iPort = InStr(iDriver + 1, Buffer, ",")

            If iPort > 0 Then
            'Strip out the port name
            PrinterPort = Mid(Buffer, iDriver + 1, _
            iPort - iDriver - 1)
            End If
            End If
            End Sub

            Private Sub ParseList(lstCt l As Control, ByVal Buffer As String)
            Dim i As Integer

            Dim s As String

            Do
            i = InStr(Buffer, Chr(0))
            If i > 0 Then
            s = Left(Buffer, i - 1)
            If Len(Trim(s)) Then lstCtl.AddItem s
            Buffer = Mid(Buffer, i + 1)
            Else
            If Len(Trim(Buffer )) Then lstCtl.AddItem Buffer
            Buffer = ""
            End If
            Loop While i > 0
            End Sub

            Private Sub WinNTSetDefault Printer()
            Dim Buffer As String
            Dim DeviceName As String
            Dim DriverName As String
            Dim PrinterPort As String
            Dim PrinterName As String
            Dim r As Long
            If List1.ListIndex > -1 Then
            'Get the printer information for the currently selected
            'printer in the list. The information is taken from the
            'WIN.INI file.
            Buffer = Space(1024)
            PrinterName = List1.Text
            r = GetProfileStrin g("PrinterPorts ", PrinterName, "", _
            Buffer, Len(Buffer))

            'Parse the driver name and port name out of the buffer
            GetDriverAndPor t Buffer, DriverName, PrinterPort

            If DriverName <> "" And PrinterPort <> "" Then
            SetDefaultPrint er List1.Text, DriverName, PrinterPort
            End If
            End If
            End Sub

            Private Sub SetDefaultPrint er(ByVal PrinterName As String, _
            ByVal DriverName As String, ByVal PrinterPort As String)
            Dim DeviceLine As String
            Dim r As Long
            Dim l As Long
            DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort
            ' Store the new printer information in the [WINDOWS] section of
            ' the WIN.INI file for the DEVICE= item
            r = WriteProfileStr ing("windows", "Device", DeviceLine)
            ' Cause all applications to reload the INI file:
            l = SendMessage(HWN D_BROADCAST, WM_WININICHANGE , 0, "windows")
            End Sub


            Private Sub cmdSetDef_Click ()
            Dim osinfo As OSVERSIONINFO
            Dim retvalue As Integer

            osinfo.dwOSVers ionInfoSize = 148
            osinfo.szCSDVer sion = Space$(128)
            retvalue = GetVersionExA(o sinfo)

            If osinfo.dwMajorV ersion = 3 And osinfo.dwMinorV ersion = 51 And _
            osinfo.dwBuildN umber = 1057 And osinfo.dwPlatfo rmId = 2 Then
            Call WinNTSetDefault Printer
            ElseIf osinfo.dwMajorV ersion = 4 And osinfo.dwMinorV ersion = 0 _
            And osinfo.dwBuildN umber >= 67109814 And osinfo.dwPlatfo rmId = 1 Then
            Call Win95SetDefault Printer
            ElseIf osinfo.dwMajorV ersion = 4 And osinfo.dwMinorV ersion = 0 _
            And osinfo.dwBuildN umber = 1381 And osinfo.dwPlatfo rmId = 2 Then
            Call WinNTSetDefault Printer
            End If

            End Sub

            Private Sub Form_Load()
            Dim r As Long
            Dim Buffer As String

            'Get the list of available printers from WIN.INI
            Buffer = Space(8192)
            r = GetProfileStrin g("PrinterPorts ", vbNullString, "", _
            Buffer, Len(Buffer))

            'Display the list of printer in the list box List1
            ParseList List1, Buffer
            End Sub
            [/code]

            *************** *********

            paste following code in the Module1
            [code=vb]
            Public Const WM_WININICHANGE = &H1A

            ' constants for DEVMODE structure
            Public Const CCHDEVICENAME = 32
            Public Const CCHFORMNAME = 32

            ' constants for DesiredAccess member of PRINTER_DEFAULT S
            Public Const STANDARD_RIGHTS _REQUIRED = &HF0000
            Public Const PRINTER_ACCESS_ ADMINISTER = &H4
            Public Const PRINTER_ACCESS_ USE = &H8
            Public Const PRINTER_ALL_ACC ESS = (STANDARD_RIGHT S_REQUIRED Or PRINTER_ACCESS_ ADMINISTER Or PRINTER_ACCESS_ USE)

            ' constant that goes into PRINTER_INFO_5 Attributes member
            ' to set it as default
            Public Const PRINTER_ATTRIBU TE_DEFAULT = 4

            Public Type OSVERSIONINFO
            dwOSVersionInfo Size As Long
            dwMajorVersion As Long
            dwMinorVersion As Long
            dwBuildNumber As Long
            dwPlatformId As Long
            szCSDVersion As String * 128
            End Type

            Type ACL
            AclRevision As Byte
            Sbz1 As Byte
            AclSize As Integer
            AceCount As Integer
            Sbz2 As Integer
            End Type


            Type SECURITY_DESCRI PTOR
            Revision As Byte
            Sbz1 As Byte
            Control As Long
            Owner As Long
            Group As Long
            Sacl As ACL
            Dacl As ACL
            End Type


            Public Type DEVMODE
            dmDeviceName As String * CCHDEVICENAME
            dmSpecVersion As Integer
            dmDriverVersion As Integer
            dmSize As Integer
            dmDriverExtra As Integer
            dmFields As Long
            dmOrientation As Integer
            dmPaperSize As Integer
            dmPaperLength As Integer
            dmPaperWidth As Integer
            dmScale As Integer
            dmCopies As Integer
            dmDefaultSource As Integer
            dmPrintQuality As Integer
            dmColor As Integer
            dmDuplex As Integer
            dmYResolution As Integer
            dmTTOption As Integer
            dmCollate As Integer
            dmFormName As String * CCHFORMNAME
            dmLogPixels As Integer
            dmBitsPerPel As Long
            dmPelsWidth As Long
            dmPelsHeight As Long
            dmDisplayFlags As Long
            dmDisplayFreque ncy As Long
            dmICMMethod As Long ' // Windows 95 only
            dmICMIntent As Long ' // Windows 95 only
            dmMediaType As Long ' // Windows 95 only
            dmDitherType As Long ' // Windows 95 only
            dmReserved1 As Long ' // Windows 95 only
            dmReserved2 As Long ' // Windows 95 only
            End Type

            Type PRINTER_INFO_2
            pServerName As String
            pPrinterName As String
            pShareName As String
            pPortName As String
            pDriverName As String
            pComment As String
            pLocation As String
            pDevMode As DEVMODE
            pSepFile As String
            pPrintProcessor As String
            pDatatype As String
            pParameters As String
            pSecurityDescri ptor As SECURITY_DESCRI PTOR
            Attributes As Long
            Priority As Long
            DefaultPriority As Long
            StartTime As Long
            UntilTime As Long
            Status As Long
            cJobs As Long
            AveragePPM As Long
            End Type


            Public Type PRINTER_INFO_5
            pPrinterName As String
            pPortName As String
            Attributes As Long
            DeviceNotSelect edTimeout As Long
            TransmissionRet ryTimeout As Long
            End Type

            Public Type PRINTER_DEFAULT S
            pDatatype As Long
            pDevMode As DEVMODE
            DesiredAccess As Long
            End Type

            Declare Function GetProfileStrin g Lib "kernel32" Alias "GetProfileStri ngA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedStrin g As String, ByVal nSize As Long) As Long
            Declare Function WriteProfileStr ing Lib "kernel32" Alias "WriteProfileSt ringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
            Declare Function SendMessage Lib "user32" Alias "SendMessag eA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As String) As Long
            Declare Function GetVersionExA Lib "kernel32" (lpVersionInfor mation As OSVERSIONINFO) As Integer
            Public Declare Function OpenPrinter Lib "winspool.d rv" Alias "OpenPrinte rA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULT S) As Long
            Public Declare Function SetPrinter Lib "winspool.d rv" Alias "SetPrinter A" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal Command As Long) As Long
            Public Declare Function GetPrinter Lib "winspool.d rv" Alias "GetPrinter A" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Any, ByVal cbBuf As Long, pcbNeeded As Long) As Long
            Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Any) As Long
            Public Declare Function ClosePrinter Lib "winspool.d rv" (ByVal hPrinter As Long) As Long
            Public Declare Function GetLastError Lib "kernel32" () As Long
            [/code]

            regards
            manpreet singh dhillon hoshiarpur
            Last edited by debasisdas; Oct 27 '07, 10:28 AM. Reason: Formatted using code=vb tags.

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              First Re-Name the Ticket Printer as TicketPrinter, and Another Default Printer as DefPrinter.

              write this Code in .bas Module:

              [code=vb]
              Public Declare Function WriteProfileStr ing Lib "kernel32" Alias "WriteProfileSt ringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long

              Public Declare Function SendMessage Lib "user32" Alias "SendMessag eA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

              Public Const HWND_BROADCAST = &HFFFF&
              Public Const WM_WININICHANGE = &H1A

              Public Function SetDefaultPrint er(objPrn As Printer) As Boolean
              Dim X As Long, sztemp As String
              sztemp = objPrn.DeviceNa me & "," & objPrn.DriverNa me & "," & objPrn.Port
              X = WriteProfileStr ing("windows", "device", sztemp)
              X = SendMessage(HWN D_BROADCAST, WM_WININICHANGE , 0&, "windows")
              End Function
              [/code]

              From VB call this To Select the Printer:

              Ticket :
              [code=vb]
              SetDefaultPrint er "TicketPrin ter"
              [/code]

              Default:
              [code=vb]
              SetDefaultPrint er "DefPrinter "
              [/code]


              REgards
              Veena

              Comment

              • creative1
                Contributor
                • Sep 2007
                • 274

                #8
                Thanks guys
                I'll try this code.
                farhana

                Comment

                Working...