我結束了一個簡單的程序發送和接收RS-232消息。我的參數(波特率,COM端口)存儲在INI文件中(如果不存在,文件將自動創建)。程序運行時沒有錯誤,但我不知道爲什麼當路徑長度超過限制時(路徑字符串中有Unicode日文字符),它會切斷指向INI文件的路徑VB.NET字符串路徑自動中斷
我在新函數中的路徑字符串(建築)是這樣的:"D:\通信プログラム20120709\新しいフォルダー\新しいフォルダー\新しいフォルダー\新しいフォルダー\Debug\Config.ini"
,並在事件的功能,它將成爲:D:\通信プログラム20120709\新しいフォルダー\新しいフォルダー\新しいフォ・
在互聯網上諮詢了一些源後,他們告訴我,一個.NET字符串將有一個非常巨大的產能,所以我猜測我的問題不關心VB.NET字符串。
任何幫助,將不勝感激。
從評論
我發現路徑的代碼如下
RS232TransPort = IniRoutine.GetString(IniSectionName, ConfigName.COMPort, "COM3")
RS232Baudrate = IniRoutine.GetInteger(IniSectionName, ConfigName.Baudrate, 9600)
這第一行後,改變的是函數得到一個字符串:
Public Function GetString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String) As String
Dim intCharCount As Integer
Dim objResult As New System.Text.StringBuilder(256)
intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, strFilename)
GetString = String.Empty
If intCharCount > 0 Then GetString = Left(objResult.ToString, intCharCount)
End Function
其中strFilename是此類的局部變量。
這是API declaire:
Private Declare Ansi Function GetPrivateProfileString _
Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As System.Text.StringBuilder, _
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
你能發佈加載INI文件的代碼嗎? – SSS 2012-07-17 06:20:04
另外,你是否使用GetPrivateProfileStringW()(不是GetPrivateProfileStringA)? – SSS 2012-07-17 06:35:14
我發現在RS232TransPort = IniRoutine.GetString(IniSectionName,ConfigName.COMPort,「COM3」)下面的第一行代碼後,路徑被改變了。RS232Baudrate = IniRoutine.GetInteger(IniSectionName,ConfigName.Baudrate,9600)' – 2012-07-17 06:39:27