我的Vba在本机通过Kernel32能正常的读写Ini配置文件,但在其他机子上就返回为0,我用Err.lastDllErr观察,返回也是0。
代码如下:
Option Explicit
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'获取当前路径
Function GetPath() As String
Dim path As String
path = Application.ActiveWorkbook.path
GetPath = path + "\"
End Function
'读INI文件
Function GetIniString(ByVal lpFileName As String, ByVal lpApplicationName As String, ByVal lpKeyName As String) As String
Dim szBuf As String
Dim ret As Integer
Dim path As String
Dim length As Integer
path = GetPath() + lpFileName
szBuf = Space$(1024)
length = Len(szBuf)
ret = GetPrivateProfileString(lpApplicationName, lpKeyName, "0", szBuf, length, path)
If ret Then
GetIniString = Left$(szBuf, ret)
Else
GetIniString = ""
End If
End Function
Private Sub CommandButton1_Click()
Label1.Caption = GetIniString("eareport.ini", TextBox1.Text, TextBox2.Text)
End Sub
Private Sub UserForm_Click()
End Sub
我估计我的请况时,更本没调用API.
我的系统是是Win2000 professional
是不是某个动态库、服务或组件有问题