G
Giuseppe
Hi all, I have a problem with this code...(overflow Exception)
I'd like to access to 0x80920000 register but this is out of range of
IntPtr. What type can I use instead IntPtr?
Thank You very much
code:
[DllImport("Coredll.dll")]
extern public static bool VirtualCopy (IntPtr lpvDest, IntPtr lpvSrc,
UInt32 cbSize, PageAccessFlags fdwProtect);
[DllImport("Coredll.dll")]
extern public static IntPtr VirtualAlloc(IntPtr lpAddress, UInt32
dwSize, MemUsageFlags flAllocationType, PageAccessFlags
flProtect);
[DllImport("Coredll.dll")]
extern public static bool VirtualFree(IntPtr lpAddress, UInt32 dwSize,
MemUsageFlags dwFreeType);
//Flags
[FlagsAttribute]
public enum PageAccessFlags : int
{
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE= 0x40,
PAGE_GUARD = 0x100,
PAGE_NOACCESS = 0x01,
PAGE_NOCACHE = 0x200,
PAGE_PHYSICAL = 0x400
}
public enum MemUsageFlags : int
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_DECOMMIT = 0x4000,
MEM_RELEASE = 0x8000
}
private void button1_Click(object sender, System.EventArgs e)
{
//*****************************
//
IntPtr PHYSADDR = (IntPtr)0x80920000;
//********************************
UInt32 SIZE = 4800*4; // Size to map
IntPtr lpv;
bool bRet;
lpv = VirtualAlloc(IntPtr.Zero,
SIZE,
MemUsageFlags.MEM_RESERVE,
PageAccessFlags.PAGE_NOACCESS);
bRet = VirtualCopy(lpv,
PHYSADDR,
SIZE,
PageAccessFlags.PAGE_READWRITE |
PageAccessFlags.PAGE_NOCACHE|PageAccessFlags.PAGE_PHYSICAL );
if (bRet==false)
{
label1.Text="Error";
VirtualFree(lpv,0,MemUsageFlags.MEM_RELEASE );
}else{ label1.Text="OK";}
}
I'd like to access to 0x80920000 register but this is out of range of
IntPtr. What type can I use instead IntPtr?
Thank You very much
code:
[DllImport("Coredll.dll")]
extern public static bool VirtualCopy (IntPtr lpvDest, IntPtr lpvSrc,
UInt32 cbSize, PageAccessFlags fdwProtect);
[DllImport("Coredll.dll")]
extern public static IntPtr VirtualAlloc(IntPtr lpAddress, UInt32
dwSize, MemUsageFlags flAllocationType, PageAccessFlags
flProtect);
[DllImport("Coredll.dll")]
extern public static bool VirtualFree(IntPtr lpAddress, UInt32 dwSize,
MemUsageFlags dwFreeType);
//Flags
[FlagsAttribute]
public enum PageAccessFlags : int
{
PAGE_READONLY = 0x02,
PAGE_READWRITE = 0x04,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE= 0x40,
PAGE_GUARD = 0x100,
PAGE_NOACCESS = 0x01,
PAGE_NOCACHE = 0x200,
PAGE_PHYSICAL = 0x400
}
public enum MemUsageFlags : int
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_DECOMMIT = 0x4000,
MEM_RELEASE = 0x8000
}
private void button1_Click(object sender, System.EventArgs e)
{
//*****************************
//
IntPtr PHYSADDR = (IntPtr)0x80920000;
//********************************
UInt32 SIZE = 4800*4; // Size to map
IntPtr lpv;
bool bRet;
lpv = VirtualAlloc(IntPtr.Zero,
SIZE,
MemUsageFlags.MEM_RESERVE,
PageAccessFlags.PAGE_NOACCESS);
bRet = VirtualCopy(lpv,
PHYSADDR,
SIZE,
PageAccessFlags.PAGE_READWRITE |
PageAccessFlags.PAGE_NOCACHE|PageAccessFlags.PAGE_PHYSICAL );
if (bRet==false)
{
label1.Text="Error";
VirtualFree(lpv,0,MemUsageFlags.MEM_RELEASE );
}else{ label1.Text="OK";}
}