VB.NETでメモリーマップトファイルを使ってスレッド間で巨大ファイル
を共有したいのですが、どうしてもハンドルが帰ってきません
0=CreateFileMapping()
となってしまいます。
よろしくご教授ください。
=======================================================
Dim hFileMap, hFile As Integer
Dim filename As String
filename = "new.txt"
hFile = CreateFile(filename, GENERIC_WRITE \ GENERIC_READ, _
0, 0, OPEN_EXISTING, 0, 0)<==成功(3592等の値)
hFileMap = CreateFileMapping(hFile, 0, PAGE_READWRITE, _
0, 0, "test")<==常に”0”失敗
=============================
Public Const GENERIC_READ As Integer = &H80000000 '読み込み
Public Const GENERIC_WRITE As Integer = &H40000000 '書き込み
Public Const GENERIC_WRITECOPY As Integer = &H10000000 '書き込み
Public Const OPEN_EXISTING As Short = 3 'ファイルをオープンする。
Public Const OPEN_ALWAYS As Short = 4
Declare Function CreateFile Lib "KERNEL32" Alias "CreateFileA"_
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer,_
ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Declare Function CreateFileMapping Lib "KERNEL32" Alias "CreateFileMappingA"
(ByVal hFile As Integer, _
ByVal lpFileMappigAttributes As Integer, _
ByVal flProtect As Integer, _
ByVal dwMaximumSizeHigh As Integer, _
ByVal dwMaximumSizeLow As Integer, _
ByVal lpName As String) As Integer
とりあえず気になった点。
> GENERIC_WRITE \ GENERIC_READ
は"GENERIC_WRITE OR GENERIC_READ"(または"GENERIC_WRITE + GENERIC_READ")かも。
とりあえず、このあたりとか。
http://www.gdncom.jp/general/bbs/ShowPost.aspx?PostID=29298
ガッさん魔界の仮面弁士さんありがとうございました。
無事に動きました。
それにしてもやっぱり「VBむずかし」ですね。
ツイート | ![]() |