Hi,
I'm trying to write some code which will deal with unicode filenames but I'm having a bit of difficulty. The final object of the exercise is to create an application which will build a VFAT disk image for use in an embedded system which can be compiled on windows, linux and OSX. Using some sample code found on msdn at http://msdn2.microsoft.com/en-us/library/aa365200.aspx I've put together some basic test code but unfortunately this fails to link. The code in question is as follows #define _UNICODE #define _WIN32_WINNT 0x0501 #include <Windows.h> #include <stdio.h> #include <malloc.h> #include <tchar.h> #include <wchar.h> #define BUFSIZE MAX_PATH //----------------------------------------------------------------------------- int _tmain(int argc, TCHAR *argv[]) { //----------------------------------------------------------------------------- WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError; LPTSTR DirSpec; size_t length_of_arg; INT retval; DirSpec = (LPTSTR) malloc (BUFSIZE); if( DirSpec == NULL ) { printf( "Insufficient memory available\n" ); retval = 1; } _tprintf (TEXT("Target directory is %s.\n"), argv[0]); printf("sizeof TCHAR is %d\n", sizeof(_TCHAR)); unsigned char *tempBuffer = (unsigned char *)argv[0]; for ( int i=0; i<10; i++ ) { printf("%02X",tempBuffer[i]); } printf("\n"); return 0; } The link error is /mingw/lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16' Does anyone know what I'm doing wrong? Is there a simpler way to do this and avoid the win32 specific code? I'm intending to work with UTF8 on linux & OSX and convert that into the VFAT UTF16 format. Dave ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ MinGW-users mailing list [hidden email] You may change your MinGW Account Options or unsubscribe at: https://lists.sourceforge.net/lists/listinfo/mingw-users |
Dave Murphy writes:
> I'm trying to write some code which will deal with unicode > filenames > #define _UNICODE > #define _WIN32_WINNT 0x0501 > #include <tchar.h> > int _tmain(int argc, TCHAR *argv[]) { No need to use that _UNICODE, <tchar.h>, _tmain and TCHAR stuff just because you want to handle Unicode filenames. (Especially not if you come from a Unix background and find it weird. It just makes Windows programming seem more obscure than it actually is.) Also, as you notice, the #define _UNICODE and then _tmain(int,TCHAR**) approach apparently isn't implemented on mingw. Just write a normal C program with main(int argc, char **argv), and then for full Unicode file names use wchar_t strings and the wide char versions of the Win32 API explicitly. If you want to be able to accept full Unicode command-line arguments, I suggest you fetch the wide character command line separately with GetCommandLineW() and split it into a wide character string array with CommandLineToArgvW(). > #include <Windows.h> Just spell it <windows.h> like everybody else. > The link error is > > /mingw/lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined > reference to `WinMain@16' If you look in mingw's <tchar.h> you see: #if 0 /* no wide startup module */ #define _tmain wmain #define _tWinMain wWinMain #define _tenviron _wenviron #define __targv __wargv #endif I.e. mingw doesn't implement a wide character startup module, so using a wmain() (which _tmain is supposed map to when _UNICODE is defined) won't work. > Is there a simpler way to do this and avoid the win32 specific > code? I'm intending to work with UTF8 on linux & OSX and convert > that into the VFAT UTF16 format. If you can accept a 3rd-party LGPL library dependency, GLib contains directory reading functions and uses UTF-8 for file names on Windows. See http://developer.gnome.org/doc/API/2.0/glib/glib-File-Utilities.html#GDir --tml ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ MinGW-users mailing list [hidden email] You may change your MinGW Account Options or unsubscribe at: https://lists.sourceforge.net/lists/listinfo/mingw-users |
Free forum by Nabble | Edit this page |