windows c : failed to create mmap of a file -


i need create mmap of file. since windows not support mmap, tried mapviewoffile() method. fails.

here's code :

char template[1024]; snprintf(template, sizeof(template) / sizeof(char), "%s", "c:\\users\\ijas\\downloads\\ijas.txt");  handle  hfile = createfile(template, generic_read | generic_write, 0, null, open_existing, file_flag_random_access, null);  if (hfile == invalid_handle_value) {     fprintf(stderr, "createfile() error 0x%08x \n", getlasterror());     return null; }  handle map_handle = createfilemapping(hfile, null, page_readwrite | sec_reserve, 0, 0, 0); if (map_handle == null) {     fprintf(stderr, "createfilemapping() error 0x%08x\n", getlasterror());     closehandle(hfile);     return null;  }  sp = (char*)mapviewoffile(map_handle, file_map_write | file_map_read, 0, 0, 0);  if (sp->buffer == null) {     fprintf(stderr, "mapviewoffile() error 0x%08x\n", getlasterror());     closehandle(hmapfile);     closehandle(hfile);     return null; } 

output :

createfile() error 0x00000003 

hint : template existing file.

anything wrong in code? please me out?

as discussed in comments, various possibilities of try-and-hit, problem seems unicode , ansi. template declared char* passed createfile default calls createfilew. if op have compiled code c++ compiler, compiler have complained c compiler, relied on coder's intellect.

createfilea expects const char* whereas createfilew expects const wchar_t*