Hey, I want to simulate mmap on windows ce. I've already written a code that works on Windows XP. I thought that there would be no problem on Windows CE, but it seems that CreateFileMapping() returns always an error.
Here is my complete test code : /* arm-wince-cegcc-gcc -O3 -Wall -mwin32 -o cegcc_test1.exe cegcc_test1.c -Wl,--enable-auto-import -Wl,-s */ #include <stdlib.h> #include <stdio.h> #include <windows.h> # include <wchar.h> wchar_t * evil_char_to_wchar(const char *text) { wchar_t *wtext; int wsize; wsize = MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, NULL, 0); if ((wsize == 0) || (wsize > (int)(ULONG_MAX/sizeof(wchar_t)))) return NULL; wtext = malloc(wsize * sizeof(wchar_t)); if (wtext) if (!MultiByteToWideChar(CP_ACP, 0, text, strlen(text) + 1, wtext, wsize)) return NULL; return wtext; } char * evil_wchar_to_char(const wchar_t *text) { char * atext; int size; int asize; size = wcslen(text) + 1; asize = WideCharToMultiByte(CP_ACP, 0, text, size, NULL, 0, NULL, NULL); if (asize == 0) return NULL; atext = (char*)malloc((asize + 1) * sizeof(char)); if (atext) if (!WideCharToMultiByte(CP_ACP, 0, text, size, atext, asize, NULL, NULL)) return NULL; atext[asize] = '\0'; return atext; } char * evil_last_error_get(void) { char str[206]; LPTSTR str1; char *str2; DWORD err; err = GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, // Default language (LPTSTR)&str1, 0, NULL); #ifdef UNICODE str2 = evil_wchar_to_char(str1); LocalFree(str1); #else str2 = str1; #endif /* ! UNICODE */ snprintf(str, 206, "(%ld) %s", err, str2); LocalFree(str2); return strdup(str); } int main (int argc, char *argv[]) { FILE *fp; int fd; HANDLE handle; HANDLE fm; wchar_t *file; fp = fopen (argv[1], "rb"); if (!fp) { printf (" * fopen failed\n"); return -1; } fd = fileno (fp); printf (" %p %d\n", fp, fd); handle = (HANDLE)get_osfhandle (fd); if (handle == INVALID_HANDLE_VALUE) { printf(" * get_osfhandle failed\n"); return -1; } fm = CreateFileMapping(handle, NULL, PAGE_READONLY, 0, 0, NULL); if (!fm) { printf (" * CreateFileMapping failed %s\n", evil_last_error_get()); return -1; } printf ("success\n"); return 0; } CreateFileMapping returns the error 6 "The handle is invalid." If I use PAGE_READWRITE, I get the error 5 "Access is denied." So I tried to create the handle with CreateFileForMapping(), using that code: file = evil_char_to_wchar(argv[1]); handle = CreateFileForMapping(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); but then, the error is 87 "The parameter is incorrect." Does someone know if CreateFileMapping() is working with cegcc ? And if it is working, what is wrong in my code ? thank you Vincent Torri ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Cegcc-devel mailing list Cegcc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cegcc-devel