c# - Generating IntPtr using Convert.ToInt64 failing on x64 applications -
i'm trying use code popular answer question: using c#, how 1 figure out process locked file?
i'm testing code in windows 7 x64 using vs2010 , .net v4.
i'm finding code excerpt...
var batemp = new byte[nlength]; try { marshal.copy(iptemp, batemp, 0, nlength); strobjectname = marshal.ptrtostringuni(is64bits() ? new intptr(iptemp.toint64()) : new intptr(iptemp.toint32())); } catch (accessviolationexception) { return null; } { marshal.freehglobal(ipobjectname); win32api.closehandle(iphandle); } is causing problems. marshal.copy can fail when address created earlier not valid. code creating address in x64 systems...
if (is64bits()) { iptemp = new intptr(convert.toint64(objobjectname.name.buffer.tostring(), 10) >> 32); } in 1 instance of noted failures starts buffer string representation of 20588995036390572032 translates x1c92aa2089e00000. code appears strip low order word leaving x1c92aa20 usaable address.
question 1: why not use 64bit address provided buffer object rather shift out low order word , use high order word in 64bit app running on 64bit os?
question 2: should try/catch/finally block include more accessviolationexception?
read comments on article. unworkable code. doesn't work. don't use. "suggested" corrected version broken (and doesn't work on win8 64bits) , in words of author:
the following produced based on iain ballard's code dump. broken: lock when retrieve handle name. code doesn't contain work-arounds issue, , .net leaves few options: thread.abort can no longer abort thread that's in native method.
Comments
Post a Comment