带有LPCTSTR类型参数API函数如何调用
DLL帮助文档中的函数说明如下
RC WINAPI LJIF_SaveEnvironmentFile(IN LPCTSTR szFilePath)
Description: Reads the environment setting file from the controller and saves it with the specified name.
Parameter:szFilePath (Setting file name *Specify the full path. )
Returned value :0x00 (Completed without errors
Other See "Return Code List" )
Remarks The controller must be set to communication mode.
现在准备用VB中的Commondialog 获取地址传递给 API函数
相应程序如下:
声明
Global sSourcePgm$
Global sDestFile$
Declare Function LJIF_LoadEnvironmentFile Lib "LJIF.dll" (ByVal szFilePath As Long) As Long
Declare Function LJIF_SaveEnvironmentFile Lib "LJIF.dll" (ByVal szFilePath As Long) As Long
调用过程
Private Sub LoadEnvironment_Click()
On Error Resume Next
With Dlg
.FileName = sSourcePgm
.CancelError = True
.DialogTitle = "请根据探头型号选择配置文件"
.Filter = "Lg environment setting file (*.env)|*.env|All files|*.*"
.Action = 1
If Err Then
Err.Clear
Exit Sub
End If
sSourcePgm = .FileName
szFilePath = VarPtr(sSourcePgm)
End With
Re = LJIF_LoadEnvironmentFile(szFilePath)
Call ReturnCode
If Re = 0 Then
StatusBar1.Panels(2).Text = "环境设置完成"
Else
StatusBar1.Panels(2).Text = "环境设置失败"
End If
End Sub
在调试中,发现返回参数不正常,不能确执行。请各位高手帮忙看看哪里错了,指点一二。
[解决办法]
dim sFilePath as stringsFilePath =string(255," ")Re = LJIF_SaveEnvironmentFile(sFilePath)
[解决办法]
直接用字符串调用
(ByVal szFilePath As String)
[解决办法]
LJIF_LoadEnvironmentFile StrPtr(.FileName)
或者
LJIF_LoadEnvironmentFile StrPtr(StrConv(.FileName, vbUnicode))
看看