lLeft As Long
lRight As Long
lTop As Long
lBottom As Long
End Type
Private Type ID_CD_S
sText(10) As String * 256
Rect(10) As HY_RT_S
End Type
请问上面两个vb程序如何转为vb.net,谢谢
5 个解决方案
#1
.net已经没有固定长度字符串,改如下
Public Structure HY_RT_S
Dim lLeft As Integer
Dim lRight As Integer
Dim lTop As Integer
Dim lBottom As Integer
End Structure
Public Structure ID_CD_S
Dim sText() As String
Dim Rect() As HY_RT_S
End Structure
Private Sub aa() '调用结构
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
'可以使用了
End Sub
Public Structure HY_RT_S
Dim lLeft As Integer
Dim lRight As Integer
Dim lTop As Integer
Dim lBottom As Integer
End Structure
Public Structure ID_CD_S
Dim sText() As String
Dim Rect() As HY_RT_S
End Structure
Private Sub aa() '调用结构
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
'可以使用了
End Sub
#2
感谢zdbb,但现在是提示参数格式不对?能否再帮我分析一下呢
我是这么处理的
Imports System.Runtime.InteropServices
声明:
Private Declare Function Get_cData Lib "Core.dll" (ByVal iType As Integer, ByVal sNameIn As String, ByVal sNameOut As String, ByVal szNameOut As String, ByRef PstOut As ID_CD_S) As Integer
通过
Private Sub aa() '调用结构
dim iResult as integer
dim sNameIn,sNameOut,sZNameOut as string
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
sNameIn="C:\1.bmp"
szNameOut="C:\11.bmp"
iResult=Get_cData(1,sNameIn,"","",ids)
'执行上面这句话时,系统报错,提示参数不正确
End Sub
'我用了多种方法,不能解决,请帮着分析一下,这样的问题怎么解决,谢谢
我是这么处理的
Imports System.Runtime.InteropServices
声明:
Private Declare Function Get_cData Lib "Core.dll" (ByVal iType As Integer, ByVal sNameIn As String, ByVal sNameOut As String, ByVal szNameOut As String, ByRef PstOut As ID_CD_S) As Integer
通过
Private Sub aa() '调用结构
dim iResult as integer
dim sNameIn,sNameOut,sZNameOut as string
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
sNameIn="C:\1.bmp"
szNameOut="C:\11.bmp"
iResult=Get_cData(1,sNameIn,"","",ids)
'执行上面这句话时,系统报错,提示参数不正确
End Sub
'我用了多种方法,不能解决,请帮着分析一下,这样的问题怎么解决,谢谢
#3
自己顶
#4
有人处理过这样的问题吗?
#5
Private Structure ID_CD_S
<VBFixedArray(10)> Dim sText() As System.Text.StringBuilder
<VBFixedArray(10)> Dim Rect() As HY_RT_S
End Structure
在某些环境中,必须将定长的字符缓冲区传递到非托管代码中以进行操作。在这种情况下,只传递字符串不起作用,原因是被调用方无法修改传递的缓冲区的内容。即使字符串是通过引用传递的,仍然无法将缓冲区初始化为给定的大小。
解决方案是将 StringBuilder 缓冲区作为参数而不是字符串传递。StringBuilder 可以由被调用方取消引用和修改,条件是它不超过 StringBuilder 的容量。还可将其初始化为固定长度。例如,如果将 StringBuilder 缓冲区初始化为容量为 N,则封送拆收器将提供大小为 (N+1) 个字符的缓冲区。这个 +1 说明非托管字符串具有 Null 结束符,而 StringBuilder 却没有。
<VBFixedArray(10)> Dim sText() As System.Text.StringBuilder
<VBFixedArray(10)> Dim Rect() As HY_RT_S
End Structure
在某些环境中,必须将定长的字符缓冲区传递到非托管代码中以进行操作。在这种情况下,只传递字符串不起作用,原因是被调用方无法修改传递的缓冲区的内容。即使字符串是通过引用传递的,仍然无法将缓冲区初始化为给定的大小。
解决方案是将 StringBuilder 缓冲区作为参数而不是字符串传递。StringBuilder 可以由被调用方取消引用和修改,条件是它不超过 StringBuilder 的容量。还可将其初始化为固定长度。例如,如果将 StringBuilder 缓冲区初始化为容量为 N,则封送拆收器将提供大小为 (N+1) 个字符的缓冲区。这个 +1 说明非托管字符串具有 Null 结束符,而 StringBuilder 却没有。
#1
.net已经没有固定长度字符串,改如下
Public Structure HY_RT_S
Dim lLeft As Integer
Dim lRight As Integer
Dim lTop As Integer
Dim lBottom As Integer
End Structure
Public Structure ID_CD_S
Dim sText() As String
Dim Rect() As HY_RT_S
End Structure
Private Sub aa() '调用结构
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
'可以使用了
End Sub
Public Structure HY_RT_S
Dim lLeft As Integer
Dim lRight As Integer
Dim lTop As Integer
Dim lBottom As Integer
End Structure
Public Structure ID_CD_S
Dim sText() As String
Dim Rect() As HY_RT_S
End Structure
Private Sub aa() '调用结构
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
'可以使用了
End Sub
#2
感谢zdbb,但现在是提示参数格式不对?能否再帮我分析一下呢
我是这么处理的
Imports System.Runtime.InteropServices
声明:
Private Declare Function Get_cData Lib "Core.dll" (ByVal iType As Integer, ByVal sNameIn As String, ByVal sNameOut As String, ByVal szNameOut As String, ByRef PstOut As ID_CD_S) As Integer
通过
Private Sub aa() '调用结构
dim iResult as integer
dim sNameIn,sNameOut,sZNameOut as string
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
sNameIn="C:\1.bmp"
szNameOut="C:\11.bmp"
iResult=Get_cData(1,sNameIn,"","",ids)
'执行上面这句话时,系统报错,提示参数不正确
End Sub
'我用了多种方法,不能解决,请帮着分析一下,这样的问题怎么解决,谢谢
我是这么处理的
Imports System.Runtime.InteropServices
声明:
Private Declare Function Get_cData Lib "Core.dll" (ByVal iType As Integer, ByVal sNameIn As String, ByVal sNameOut As String, ByVal szNameOut As String, ByRef PstOut As ID_CD_S) As Integer
通过
Private Sub aa() '调用结构
dim iResult as integer
dim sNameIn,sNameOut,sZNameOut as string
'初始化结构
Dim ids As New ID_CD_S
ReDim ids.sText(9)
ReDim ids.Rect(9)
Dim i As Integer
For i = 0 To 9
ids.sText(i) = Space(256)
Next
sNameIn="C:\1.bmp"
szNameOut="C:\11.bmp"
iResult=Get_cData(1,sNameIn,"","",ids)
'执行上面这句话时,系统报错,提示参数不正确
End Sub
'我用了多种方法,不能解决,请帮着分析一下,这样的问题怎么解决,谢谢
#3
自己顶
#4
有人处理过这样的问题吗?
#5
Private Structure ID_CD_S
<VBFixedArray(10)> Dim sText() As System.Text.StringBuilder
<VBFixedArray(10)> Dim Rect() As HY_RT_S
End Structure
在某些环境中,必须将定长的字符缓冲区传递到非托管代码中以进行操作。在这种情况下,只传递字符串不起作用,原因是被调用方无法修改传递的缓冲区的内容。即使字符串是通过引用传递的,仍然无法将缓冲区初始化为给定的大小。
解决方案是将 StringBuilder 缓冲区作为参数而不是字符串传递。StringBuilder 可以由被调用方取消引用和修改,条件是它不超过 StringBuilder 的容量。还可将其初始化为固定长度。例如,如果将 StringBuilder 缓冲区初始化为容量为 N,则封送拆收器将提供大小为 (N+1) 个字符的缓冲区。这个 +1 说明非托管字符串具有 Null 结束符,而 StringBuilder 却没有。
<VBFixedArray(10)> Dim sText() As System.Text.StringBuilder
<VBFixedArray(10)> Dim Rect() As HY_RT_S
End Structure
在某些环境中,必须将定长的字符缓冲区传递到非托管代码中以进行操作。在这种情况下,只传递字符串不起作用,原因是被调用方无法修改传递的缓冲区的内容。即使字符串是通过引用传递的,仍然无法将缓冲区初始化为给定的大小。
解决方案是将 StringBuilder 缓冲区作为参数而不是字符串传递。StringBuilder 可以由被调用方取消引用和修改,条件是它不超过 StringBuilder 的容量。还可将其初始化为固定长度。例如,如果将 StringBuilder 缓冲区初始化为容量为 N,则封送拆收器将提供大小为 (N+1) 个字符的缓冲区。这个 +1 说明非托管字符串具有 Null 结束符,而 StringBuilder 却没有。