掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
WriteFileの引数const Bufferとは何ですか? (ID:18773)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> 送信データのアドレスを渡せば良いのでしょうか? いいえ。値を渡せばよいのです。 たとえば、ファイルの場合ですが、こんな感じになります。 var hFile: THandle; bytValue: Byte; //8bit chValue: Char; //8bit intValue: Integer; //32bit lngValue: Longint; //32bit int64Value: Int64; //64bit strValue: String; intLen: Integer; dwDummy: DWORD; begin hFile := CreateFile('C:\test.dat', GENERIC_READ or GENERIC_WRITE, 0, nil, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0); bytValue := 1; chValue := 'A'; intValue := $1234; lngValue := $7FDCBA98; int64Value := $FFDDCCBBAA998877; strValue := 'abcde'; intLen := Length(strValue); WriteFile(hFile, bytValue, 1, dwDummy, nil); WriteFile(hFile, chValue, 1, dwDummy, nil); WriteFile(hFile, intValue, 4, dwDummy, nil); WriteFile(hFile, lngValue, 4, dwDummy, nil); WriteFile(hFile, int64Value, 8, dwDummy, nil); WriteFile(hFile, PCHAR(strValue)^, intLen, dwDummy, nil); //こっちでも可能 //WriteFile(hFile, strValue[1], intLen, dwDummy, nil); CloseHandle(hFile); end; > ヘルプにはstring型(長い文字列)は、文字列を指すポインタで > あると記載されているように思うのですが、どうなのでしょうか? いいえ、ちがいます。 長い文字列=AnsiStringは、文字列を指すポインタの前に、文字数および参照カウンタが存在します。 ただし、PCHARでキャストすると、文字列を指すポインタとなります。 > WriteFIle(hCom,PChar(str)^,Length(str),Len,nil); > と記述すると0x31,0x32,0x33,0x34が送信されました。 これが正解です(正解は1つとは限りませんが)。 他の型に関しては、上述の通りです。
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.