请教一个DLL方法如何传递参数?
跟大家请教个问题。VB2008如何开辟一个很大的内存空间,然后把内存空间的地址传递过去?
我要调用的DLL文件的方法是这样说明的。
extern "C" DLLexport int _stdcall ReadVersion
(char *str_version,
char *strIPAddress,
unsigned int outtime,
unsigned int num);
功能: 计数器设置函数.
* 在 VC 里表示指针,需要采用参数的地址传递。
输入参数:strIPAddress:仪器的 IP地址,比如:”192.168.1.198”。
outtime:超时时间,单位 ms,一般设置 100ms 以上。
num:连接次数为 num+1,用于超时后再重新连接 num 次,取 1-255,一般设为 3。
输出参数:str_ version:保存返回的模块软件版本字符,该空间要求不少于 20 个字符。
返回值: 如果成功返回 1,不存在该 IP 返回-1,设置参数错误返回 0,连接 num+1 次后还超时返回 2。
我的VB代码是这么写的。
Declare Function ReadVersion Lib "AsmDLL" (ByRef str_version As String, ByRef strIPAddress As String, ByVal outtime As Long, ByVal num As Long) As Integer
Private Sub ButRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButRead.Click
Dim ip As String
ip = "192.168.1.198"
Dim strversion(0 To 100) As String
MsgBox(ReadVersion(strversion(0), ip, 100, 3))
End Sub
总是返回2.提示我超时,我该如何传参数?
我还参考了C#的代码,如下:
[DllImport("AsmDll.dll")]
public extern static int ReadVersion(StringBuilder str_version, string strIPAddress, int outtime, int num);
//ReadVersion
private void btnReadVersion_Click(object sender, EventArgs e)
{
StringBuilder str_name = new StringBuilder(32); //定义buff
string address = "192.168.1.198";
int u = ReadVersion(str_name, address, 100, 1);
MessageBox.Show(u.ToString());
}
返回1.证明可以正常使用。
我还参考了VB6.0的代码。如下:
Declare Function ReadVersion Lib "AsmDLL" (ByVal str_version As String, ByVal strIPAddress As String, ByVal outtime As Long, ByVal num As Long) As Integer
Private Sub Command6_Click()
Dim strversion As String * 20
Text6.Text = ReadVersion(strversion, "192.168.1.198", 100, 3)
Text6.Text = strversion
End Sub
也可以正常使用。
用VB2008总是超时。我要晕了。不知道如何传递参数!
在线求教!在线等!
我要调用的DLL文件的方法是这样说明的。
extern "C" DLLexport int _stdcall ReadVersion
(char *str_version,
char *strIPAddress,
unsigned int outtime,
unsigned int num);
功能: 计数器设置函数.
* 在 VC 里表示指针,需要采用参数的地址传递。
输入参数:strIPAddress:仪器的 IP地址,比如:”192.168.1.198”。
outtime:超时时间,单位 ms,一般设置 100ms 以上。
num:连接次数为 num+1,用于超时后再重新连接 num 次,取 1-255,一般设为 3。
输出参数:str_ version:保存返回的模块软件版本字符,该空间要求不少于 20 个字符。
返回值: 如果成功返回 1,不存在该 IP 返回-1,设置参数错误返回 0,连接 num+1 次后还超时返回 2。
我的VB代码是这么写的。
Declare Function ReadVersion Lib "AsmDLL" (ByRef str_version As String, ByRef strIPAddress As String, ByVal outtime As Long, ByVal num As Long) As Integer
Private Sub ButRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButRead.Click
Dim ip As String
ip = "192.168.1.198"
Dim strversion(0 To 100) As String
MsgBox(ReadVersion(strversion(0), ip, 100, 3))
End Sub
总是返回2.提示我超时,我该如何传参数?
我还参考了C#的代码,如下:
[DllImport("AsmDll.dll")]
public extern static int ReadVersion(StringBuilder str_version, string strIPAddress, int outtime, int num);
//ReadVersion
private void btnReadVersion_Click(object sender, EventArgs e)
{
StringBuilder str_name = new StringBuilder(32); //定义buff
string address = "192.168.1.198";
int u = ReadVersion(str_name, address, 100, 1);
MessageBox.Show(u.ToString());
}
返回1.证明可以正常使用。
我还参考了VB6.0的代码。如下:
Declare Function ReadVersion Lib "AsmDLL" (ByVal str_version As String, ByVal strIPAddress As String, ByVal outtime As Long, ByVal num As Long) As Integer
Private Sub Command6_Click()
Dim strversion As String * 20
Text6.Text = ReadVersion(strversion, "192.168.1.198", 100, 3)
Text6.Text = strversion
End Sub
也可以正常使用。
用VB2008总是超时。我要晕了。不知道如何传递参数!
在线求教!在线等!
...全文
相关推荐
BIEE_仪表盘传参数接收方法
BIEE_仪表盘传参数接收方法 比较好的文档
将VBA代码编译封装成为DLL动态链接库的方法.docx
将VBA代码编译封装成为DLL动态链接库的方法.docx
WinCC调用自定义DLL.rar
WinCC调用自定义DLL文件!可运行!采用C++搭建并编译好的框架!大家可以利用该框架写上自己需要的控制模型或算法!完成千奇百怪的控制!
biee 参数接收方法
biee 仪表盘参数接收参数接收方法。形象易于学习,里面含有实例。
ActionlessForm.dll,URLRewriter.dll实现URL重写组件
ActionlessForm.dll,URLRewriter.dll实现URL重写组件


