高手进入,dll调用
以下是开发一款叫SCL2008的LED控制卡的VB源码(这个是厂商提供,可以正确实现所有方法),我将以下源码在c#里做了相应的编写,但是结果发现只有Private Declare Function SCL_ShowString Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByRef TextInfo As Integer, ByVal Str As String) As Boolean申明在c#返回结果总是false,没有实现成功。
API中此方法是这样定义的BOOL SCL_ShowString(WORD nDevID,short *info, char *str);
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1740
ClientLeft = 60
ClientTop = 345
ClientWidth = 4530
LinkTopic = "Form1"
ScaleHeight = 1740
ScaleWidth = 4530
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "发送文本,直接静止显示"
Height = 375
Left = 720
TabIndex = 1
Top = 960
Width = 3255
End
Begin VB.CommandButton Command1
Caption = "发送文本文件, 带移动效果"
Height = 375
Left = 720
TabIndex = 0
Top = 240
Width = 3255
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ---------------------------------------------------------
' Functions in DLL
Private Declare Function SCL_NetInitial Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal Password As String, ByVal IP As String, ByVal TimeOut As Long, ByVal Retry As Long, ByVal UDPPort As Integer, ByVal SCL2008 As Boolean) As Boolean
Private Declare Function SCL_ComInitial Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal ComPort As Long, ByVal Baudrate As Long, ByVal LedNum As Long, ByVal TimeOut As Long, ByVal Retry As Long, ByVal SCL2008 As Boolean) As Boolean
Private Declare Function SCL_ShowString Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByRef TextInfo As Integer, ByVal Str As String) As Boolean
Private Declare Function SCL_SendFile Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal DrvNo As Long, ByVal Path As String, ByVal FileName As String) As Boolean
Private Declare Function SCL_SendData Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal Offset As Long, ByVal SendBytes As Long, ByRef Buff As Byte) As Boolean
Private Declare Function SCL_SaveFile Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal DrvNo As Long, ByVal FileName As String, ByVal Length As Long, ByVal Da As Long, ByVal Ti As Long) As Boolean
Private Declare Function SCL_GetFileDosDateTime Lib "SCL_API_Stdcall" (ByVal FileName As String, ByRef Da As Long, ByRef Ti As Long) As Boolean
Private Declare Function SCL_RemoveFile Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal DrvNo As Long, ByVal FileName As String) As Boolean
Private Declare Function SCL_Replay Lib "SCL_API_Stdcall" (ByVal DevID As Integer, ByVal Drv As Long, ByVal Index As Long) As Boolean
Private Declare Function SCL_Close Lib "SCL_API_Stdcall" (ByVal DevID As Integer) As Boolean
' ---------------------------------------------------------
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' ---------------------------------------------------------
' Constant define
Const bSCL2008 = True 'TRUE: 控制器为SCL2008, FALSE: 控制器为SuperComm
Const IPAddr = "10.1.1.100" '网络通讯: 控制器 IP 地址
Const UDPPort = 1024 '网络通讯: UDP 端口号