基本问题求助
VB 代码如下:
Private Declare Sub Make Lib "makebar.dll" _
(ucData As Byte, ByVal nLen As Long, ByVal szFileName As String, ByVal nClumn As Long, ByVal nErr As Long, ByVal nHLRatio As Long)
Private Sub Command1_Click()
Dim a() As Byte
a = StrConv(Text1.Text, vbFromUnicode)
Make a(0), UBound(a) - LBound(a) + 1, "abc.bmp", CLng(Text2.Text), CLng(Text3.Text), CLng(Text4.Text)
Image1.Picture = LoadPicture("abc.bmp")
End Sub
现同样的功能,用 VB.Net, 代码如下:
Public Class Form1
Private Declare Sub Make Lib "makebar.dll" _
(ByVal ucData As Byte, ByVal nLen As Long, ByVal szFileName As String, ByVal nClumn As Long, ByVal nErr As Long, ByVal nHLRatio As Long)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a() As Byte
a = System.Text.Encoding.Default.GetBytes(RichTextBox1.Text)
Make(a(0), UBound(a) - LBound(a) + 1, "temp.bmp", CLng(TextBox1.Text), CLng(TextBox2.Text), CLng(TextBox3.Text))
PictureBox1.Load("temp.bmp")
End Sub
End Class
结果提示 访问内存非法:
System.AccessViolationException: Attempted to read or write protected memory.
请问原因何在? 该如何修正?