问个VB6 -> C (ByRef ByVal) 基础的问题
最近遇到个BUG,搞了3天不断的尝试修改VC6代码,使用不同的写法,最后发现是因为VB6写久了,忽视了变量型态声明的重要性,和编译器对型态定义不同,尤其是VB6到VC6的参数传递,以至于出现各式各样,千奇百怪的结果。因此想问问,如果在VC6写了个DLL,VB6去呼叫来用
时,当参数型态和传递方式不同时,VB6和VC6在内存的配置是怎么个运作法?
虽然透过同事的协助,已经从结果推论原因了,但是还是想听听专业的说法。
VB6:
-----------------------------------------------------------------------------------------------------------------------------------------------------
'1
Public Declare Function DataReSet Lib "DataReSet.dll" (ByVal opt1 As Integer, ByVal opt2 As Integer, ByVal F1 As String, ByVal F2 As String) As Long
Dim label as Integer,Rate as Integer
label =1:Rate =1
MaxLine = DataReSet(label, Rate, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
'2
Public Declare Function DataReSet Lib "DataReSet.dll" (ByRef opt1 As Integer, ByRef opt2 As Integer, ByVal F1 As String, ByVal F2 As String) As Long
Dim label as Integer,Rate as Integer
label =1:Rate =1
MaxLine = DataReSet(label, Rate, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
'3
Public Declare Function DataReSet Lib "DataReSet.dll" (ByVal opt1 As Long, ByVal opt2 As Long, ByVal F1 As String, ByVal F2 As String) As Long
Dim label as Long,Rate as Long
label =1:Rate =1
MaxLine = DataReSet(label, Rate, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
'4
Public Declare Function DataReSet Lib "DataReSet.dll" (ByRef opt1 As Long, ByRef opt2 As Long, ByVal F1 As String, ByVal F2 As String) As Long
Dim label as Long,Rate as Long
label =1:Rate =1
MaxLine = DataReSet(label, Rate, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
'5
Public Declare Function DataReSet Lib "DataReSet.dll" (ByVal opt1 As Long, ByVal opt2 As Long, ByVal F1 As String, ByVal F2 As String) As Long
MaxLine = DataReSet(1, 1, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
'6
Public Declare Function DataReSet Lib "DataReSet.dll" (ByRef opt1 As Long, ByRef opt2 As Long, ByVal F1 As String, ByVal F2 As String) As Long
MaxLine = DataReSet(1, 1, File, Temp1)
-----------------------------------------------------------------------------------------------------------------------------------------------------
针对opt1(label)和opt2(Rate)两参数使用INT型态和Long型态和ByVal和ByRef,和直接指定1,6种模式交叉使用后的内存配置,
和到VC6取得的opt1和opt2的内存读取实际上的步骤有什么不同。
VC6:
int _stdcall DataReSet(int,int,char*,char*);
经过这次以后用VB6要尽量少用Integer型态的变量声明。才不会再遇到这种鸟事。