- 題名: null区切りされた文字配列について
- 日時: 2005/08/29 16:45:17
- ID: 12417
- この記事の返信元:
- (なし)
- この記事への返信:
- [12421] Re[1]: null区切りされた文字配列について2005/08/29 16:58:55
- [12422] Re[1]: null区切りされた文字配列について2005/08/29 17:06:19
- [12427] Re[1]: null区切りされた文字配列について2005/08/29 17:38:16
- ツリーを表示
あれ。Stringでいけませんでしたか?
C++には詳しくないので、DLL側の話は良く分かりませんが……少なくとも、
GetPrivateProfileSectionNames APIは問題なく呼べるみたいですし。
'=====================================
Imports System
Imports Microsoft.VisualBasic
Module A
Private Declare Auto Function GetPrivateProfileSectionNames Lib "kernel32" _
(ByVal Buf As String, ByVal Size As Integer, ByVal File As String) As Integer
Sub Main()
Dim S As New String(" "c, 1000)
Dim F As String = "C:\Windows\WIN.INI"
GetPrivateProfileSectionNames(S, S.Length, F)
'終端の二連nullを以降を取り除く
Dim Term As New String(ChrW(0), 2)
S = Split(S & Term, Term)(0)
'nullで区切りで表示
For Each X As String In Split(S, ChrW(0))
Console.WriteLine("[" & X & "]")
Next
End Sub
End Module
分類:[.NET]
こんにちは。
アンマネージコード(C++)で書かれたDLLを呼び出し、
返却された文字配列データを取得したいのですが、
null区切りされている為、String型やStringBuilderで
取得できず困っています。
どなたか、良い方法がないものか教えてください。
<開発言語>
VisualBasic2005
<DLLインターフェース>
TEST_RESULT TEST_APICALL TEST_StrGet(
//IN :ディレクトリ名
char[10] DirName,
//OUT :0ターミネートしたファイル名リスト(ASCIZ文字列:SJIS)
char[100] FileList
);
<作成中のプログラムコード>
Public Declare Function TEST_StrGet Lib "test.dll" ( _
ByVal DirName As String, _
ByVal FileList As StringBuilder, _
) As Integer
Public Function TEST( _
ByVal strDirName As String, _
ByVal strFileList() As String, _
) As Integer
Dim i, rc As Integer
Dim DirName As String = "C:\"
Dim FileList As New StringBuilder(100)
rc = TEST_StrGet(DirName, FileList)
For i = 0 to FileList.length
★StringBuilderはnullターミネイトされてしまう為、「FileList(0)」
しか返却されない
strFileList = FileList(i)
Next
・
・
・
End Function