#include <windows.h>
#include <stdio.h>
#include <rtapi.h>
static PVOID vAddress; // virtual memory address returned by RtAllocateContiguousMemory
static LARGE_INTEGER pAddress; // physical memory address returned
by RtGetPhysicalAddress
void main(void) {
LARGE_INTEGER maxPhyAddr; //highest physical memory address
ULONG size=0; //bytes to allocate
maxPhyAddr.QuadPart = 0xFFFFFF;
size= 0x1000; // Size in KB.
// Allocate memory
vAddress = RtAllocateContiguousMemory( size, maxPhyAddr);
if (!vAddress) {
printf("\nFailure on RtAllocateContiguousMemory\t");
printf("Error=%d\n", GetLastError());
break;
}
else {
printf("\nSuccess on RtAllocateContiguousMemory\n");
printf("Virtual memory address = 0x%08X\n", vAddress);
// Get the physical address
pAddress = RtGetPhysicalAddress(vAddress);
if (!pAddress.QuadPart) {
printf("\nFailure on RtGetPhysicalAddress(0x%08X).\t, vAddress");
printf("Error=%d\n", GetLastError());
}
else {
printf("Success on RtGetPhysicalAddress(0x%08X).\n", vAddress);
}
// Free memory
if (!RtFreeContiguousMemory(vAddress)) {
printf("\nFailure on RtFreeContiguousMemory(0x%08X).\t", vAddress);
printf("Error Code = %d\n", GetLastError());
}
else {
printf("Success on RtFreeContiguousMemory(0x%X).\n", vAddress);
}
}
ExitProcess(0);
}