vba - how to solve UnmapViewOfFile error 487? -
not sure supposed this, i'm posting question save people time. found answer. please let me know can if not best place.
this creating error 487 after unmapviewoffile line:
option explicit private const page_readwrite long = &h4 private const file_map_write long = &h2 private const generic_read = &h80000000 private const generic_write = &h40000000 private const open_always = 4 private const file_attribute_normal = &h80 'http://www.cadsharp.com/docs/win32api_ptrsafe.txt declare function createfile lib "kernel32" alias "createfilea" (byval lpfilename string, _ byval dwdesiredaccess long, byval dwsharemode long, _ byval lpsecurityattributes long, byval dwcreationdisposition long, _ byval dwflagsandattributes long, byval htemplatefile long) long declare function createfilemapping lib "kernel32.dll" alias "createfilemappinga" ( _ byval hfile long, _ byval lpfilemappigattributes long, _ byval flprotect long, _ byval dwmaximumsizehigh long, _ byval dwmaximumsizelow long, _ byval lpname string) long declare function mapviewoffile lib "kernel32.dll" ( _ byval hfilemappingobject long, _ byval dwdesiredaccess long, _ byval dwfileoffsethigh long, _ byval dwfileoffsetlow long, _ byval dwnumberofbytestomap long) long declare sub copymemory lib "kernel32" alias _ "rtlmovememory" (destination any, source any, _ byval length long) declare function closehandle lib "kernel32.dll" ( _ byval hobject long) long declare function unmapviewoffile lib "kernel32.dll" ( _ byref lpbaseaddress any) long public hmmf long public pmemfile long sub intomemoryfileoutofmemoryfile() err.clear dim sfile string dim hfile long dim bbytes variant sfile = "c:\test1.txt" debug.print err.lastdllerror 'https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx hfile = createfile(sfile, generic_read or generic_write, 0, 0, open_always, file_attribute_normal, 0) debug.print err.lastdllerror 'https://msdn.microsoft.com/en-us/library/windows/desktop/aa366537%28v=vs.85%29.aspx hmmf = createfilemapping(hfile, 0, page_readwrite, 0, 1000000, "mymemorymappedfilex") debug.print err.lastdllerror 'https://msdn.microsoft.com/en-us/library/windows/desktop/aa366761%28v=vs.85%29.aspx pmemfile = mapviewoffile(hmmf, file_map_write, 0, 0, 1000000) debug.print err.lastdllerror unmapviewoffile pmemfile '< - produced error 487 debug.print err.lastdllerror closehandle hmmf debug.print err.lastdllerror closehandle hfile debug.print err.lastdllerror end sub
change line:
declare function unmapviewoffile lib "kernel32.dll" ( _ byref lpbaseaddress any) long
to...
declare function unmapviewoffile lib "kernel32.dll" ( _ byval lpbaseaddress any) long
just changed byref byval.
Comments
Post a Comment