Click here to Skip to main content
15,921,622 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Memory required by a form Pin
Dave Kreskowiak30-Oct-12 7:07
mveDave Kreskowiak30-Oct-12 7:07 
GeneralRe: Memory required by a form Pin
Gagnon Claude30-Oct-12 13:24
Gagnon Claude30-Oct-12 13:24 
GeneralRe: Memory required by a form Pin
Dave Kreskowiak30-Oct-12 13:45
mveDave Kreskowiak30-Oct-12 13:45 
QuestionWhy can't i find a consistent set of examples for SQL and Linq Pin
Gerald Connolly29-Oct-12 11:51
Gerald Connolly29-Oct-12 11:51 
AnswerRe: Why can't i find a consistent set of examples for SQL and Linq Pin
Eddy Vluggen30-Oct-12 1:12
professionalEddy Vluggen30-Oct-12 1:12 
GeneralRe: Why can't i find a consistent set of examples for SQL and Linq Pin
Gerald Connolly30-Oct-12 3:42
Gerald Connolly30-Oct-12 3:42 
GeneralRe: Why can't i find a consistent set of examples for SQL and Linq Pin
Eddy Vluggen30-Oct-12 4:05
professionalEddy Vluggen30-Oct-12 4:05 
QuestionAttempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Kimhoy25-Oct-12 17:57
Kimhoy25-Oct-12 17:57 
I'm a novice programmer. I am having problem in connecting a printer "DATECS DPP-250" in my code. I tried to add "PrintDriver.dll"
but it output's like there is some kind of error that THE memory is being corrupted. I've searched a lot forums but still I can't solve it. Please I really need all of your help.

THIS IS THE PROBLEM:
_________________________________________________________
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at PrintDriverNet.Printer.PDSDK_OpenPrinter(Int32 nKernelMode, String strPrinterName)
at PrintDriverNet.Printer.OpenPrinter() in d:\Sources\Projects\Datecs\PrinterUtility\PrintDriverNet\PrintDriverNet.cs:line 471
at Testing.MainForm.buttonRead_Click(Object sender, EventArgs e) in D:\Works\Testing\Testing\MainForm.vb:line 44
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Testing
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Works/Testing/Testing/bin/Debug/Testing.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
PrintDriverNet
Assembly Version: 1.0.4652.23888
Win32 Version: 1.0.4652.23888
CodeBase: file:///D:/Works/Testing/Testing/bin/Debug/PrintDriverNet.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitdebugging="true">


When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
___________________________________________________________


AND HERE IS MY CODE:

__________________________________________________________
Imports PrintDriverNet
Public Class Form1

Private Sub buttonRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRead.Click
Dim printer__1 As New Printer()
Dim msr_params As Integer = Printer.MRPARAM_PREFIX
Dim buffer As Byte() = New Byte(256 * 3 - 1) {}
Dim res As Integer

textBoxTrack1.Text = String.Empty
textBoxTrack1.Update()
textBoxTrack2.Text = String.Empty
textBoxTrack2.Update()
textBoxTrack3.Text = String.Empty
textBoxTrack3.Update()

Try
textBoxTrack1.Text = "Connecting ..."
textBoxTrack1.Update()
textBoxTrack2.Text = "Connecting ..."
textBoxTrack2.Update()
textBoxTrack3.Text = "Connecting ..."
textBoxTrack3.Update()

''-----I can't connect to my printer here in this statement,it crashes

*--> If printer__1.OpenPrinter() < 0 Then
Throw New ApplicationException("Failed to open connection with printer.")
End If
.------''

textBoxTrack1.Text = "Swipe a magnetic card ..."
textBoxTrack1.Update()
textBoxTrack2.Text = "Swipe a magnetic card ..."
textBoxTrack2.Update()
textBoxTrack3.Text = "Swipe a magnetic card ..."
textBoxTrack3.Update()

If checkBoxTrack1.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK1
End If

If checkBoxTrack2.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK2
End If

If checkBoxTrack3.Checked Then
msr_params = msr_params Or Printer.MRPARAM_TRACK3
End If

If (InlineAssignHelper(res, printer__1.ReadMagstripe(10000, msr_params, buffer, buffer.Length))) < 0 Then
Throw New ApplicationException("Failed to read magstripe data.")
End If

textBoxTrack1.Text = "No track selected or available data."
textBoxTrack2.Text = "No track selected or available data."
textBoxTrack3.Text = "No track selected or available data."

Dim i As Integer = 0, j As Integer = -1
While i < res
Select Case buffer(i)
Case &HF1
j = buffer(i)
textBoxTrack1.Text = String.Empty
Exit Select
Case &HF2
j = buffer(i)
textBoxTrack2.Text = String.Empty
Exit Select
Case &HF3
j = buffer(i)
textBoxTrack3.Text = String.Empty
Exit Select
Case Else
Select Case j
Case &HF1
textBoxTrack1.Text += Convert.ToChar(buffer(i))
Exit Select
Case &HF2
textBoxTrack2.Text += Convert.ToChar(buffer(i))
Exit Select
Case &HF3
textBoxTrack3.Text += Convert.ToChar(buffer(i))
Exit Select
End Select
Exit Select

End Select
i += 1
End While

If checkBoxOnPaper.Checked Then
Dim receipt As String = String.Empty
receipt += vbLf
receipt += "Track1: " & textBoxTrack1.Text & vbLf
receipt += "Track2: " & textBoxTrack2.Text & vbLf
receipt += "Track3: " & textBoxTrack3.Text & vbLf
receipt += vbLf & vbLf & vbLf

Dim printBuff As Byte() = System.Text.Encoding.ASCII.GetBytes(receipt)
If printer__1.WritePrinterDirect(printBuff, printBuff.Length) < 0 Then
Throw New ApplicationException("Failed to print data.")
End If
End If

If printer__1.ClosePrinter() < 0 Then
Throw New ApplicationException("Failed to close connection with printer.")
End If
Catch ae As ApplicationException
textBoxTrack1.Text = ae.Message
textBoxTrack2.Text = ae.Message
textBoxTrack3.Text = ae.Message
Finally
printer__1.Dispose()
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function

End Class

__________________________________________________________
AnswerRe: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Dave Kreskowiak25-Oct-12 18:29
mveDave Kreskowiak25-Oct-12 18:29 
GeneralRe: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Kimhoy25-Oct-12 19:37
Kimhoy25-Oct-12 19:37 
GeneralRe: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Dave Kreskowiak26-Oct-12 2:20
mveDave Kreskowiak26-Oct-12 2:20 
GeneralRe: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Kimhoy26-Oct-12 2:34
Kimhoy26-Oct-12 2:34 
AnswerRe: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Pin
Bernhard Hiller26-Oct-12 2:39
Bernhard Hiller26-Oct-12 2:39 
QuestionVB6 on Windows 7 Pin
Member 451235624-Oct-12 20:09
Member 451235624-Oct-12 20:09 
AnswerRe: VB6 on Windows 7 Pin
Eddy Vluggen24-Oct-12 23:21
professionalEddy Vluggen24-Oct-12 23:21 
AnswerRe: VB6 on Windows 7 Pin
Bernhard Hiller26-Oct-12 2:43
Bernhard Hiller26-Oct-12 2:43 
GeneralRe: VB6 on Windows 7 Pin
Member 451235629-Oct-12 18:42
Member 451235629-Oct-12 18:42 
AnswerRe: VB6 on Windows 7 Pin
Member 45123564-Dec-12 21:27
Member 45123564-Dec-12 21:27 
QuestionBinar array into user defined Type (How to?) Pin
Member 953964724-Oct-12 11:45
Member 953964724-Oct-12 11:45 
AnswerRe: Binar array into user defined Type (How to?) Pin
Eddy Vluggen24-Oct-12 23:19
professionalEddy Vluggen24-Oct-12 23:19 
QuestionVB.Net q Pin
khalid33323-Oct-12 23:30
khalid33323-Oct-12 23:30 
AnswerRe: VB.Net q Pin
Eddy Vluggen24-Oct-12 0:03
professionalEddy Vluggen24-Oct-12 0:03 
AnswerRe: VB.Net q Pin
khalid33324-Oct-12 17:19
khalid33324-Oct-12 17:19 
QuestionCOM Interop between C++ program and VB.NET DLL Pin
_obi_22-Oct-12 13:14
_obi_22-Oct-12 13:14 
AnswerRe: COM Interop between C++ program and VB.NET DLL Pin
Bernhard Hiller22-Oct-12 20:57
Bernhard Hiller22-Oct-12 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.