Hello gurus

Can anyone please provide be a complete example of writing large files fast using File Maping functions ?

Following code cause application level crash


Code:
char *out = "newfile.txt";
HANDLE fh_infile = CreateFile(out, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if(fh_infile==NULL) return false;

HANDLE h = CreateFileMapping(fh_infile, NULL, PAGE_READWRITE, 0, filesize,  NULL);
char *dat = (char*)MapViewOfFile(h, FILE_MAP_WRITE, 0, 0, filesize);

char *tempdata = "Here is the temporary data";
CopyMemory(dat, tempdata, strlen(tempdata)+1);
UnmapViewOfFile(dat);
CloseHandle(fh_infile);

Waiting or the kind reply.

regards