User`s manual

V460 Series WinXP Embedded User’s Manual Getting Started
2-9
Reading Data from SRAM
// Persisted_SRAM_Read.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwBackSize = 0;
HANDLE hSRAM = NULL;
// open the SRAM device driver
hSRAM = CreateFile(L"\\\\.\\Sram", GENERIC_READ | GENERIC_WRITE,
0, // exclusive access, until the handle is closed
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, // no overlapped I/O
NULL); // null template
if (hSRAM == INVALID_HANDLE_VALUE)
{
printf("Can't open SRAM\n");
return 1;
}
char recvBuf[100];
memset( recvBuf, 0, sizeof(recvBuf));
// read data from SRAM
ReadFile( hSRAM, recvBuf, sizeof(recvBuf), &dwBackSize, NULL);
printf("read from SRAM: %s\n", recvBuf);
// close device driver handle
CloseHandle(hSRAM);
return 0;
}