Hi,
I'm just wondering if this approach may solve the issue.
I'm maybe totally wrong but there's no harm in trying...
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define STRERR(a,b) { printf("line %d: "a" %s\n",__LINE__,strerror(errno)); return b; }
extern int wmain(int,wchar_t**);
wchar_t* convert( const char* cstr )
{
size_t wl, wl2;
wchar_t *wstr = NULL;
mbstate_t status;
if ( !cstr )
return NULL;
/* get length of the string once converted */
memset( &status, 0, sizeof(mbstate_t) );
wl = mbsrtowcs( NULL, &cstr, 0, &status );
if( wl == -1)
STRERR("mbsrtowcs(NULL,...) ",NULL)
/* allocate space for the converted string + \0 */
wstr = (wchar_t *)malloc( (wl+1)*sizeof(wchar_t) );
if( !wstr )
STRERR("malloc(wstr) ",NULL)
/* copy the buffer */
memset( &status, 0, sizeof(mbstate_t) );
wl2 = mbsrtowcs( wstr, &cstr, wl+1, &status );
if( wl2 == -1 )
STRERR("mbsrtowcs ",NULL)
/* check that all went right */
if( wl != wl2 )
{
printf("We've not converted the whole string...");
return NULL;
}
return wstr;
}
int convert_args(int argc, char** argv, wchar_t ***args)
{
int i;
wchar_t **wargs;
wargs = (wchar_t **)malloc( argc*sizeof(wchar_t*) );
if( !wargs )
STRERR("malloc(wargs) ",-1)
*args = wargs;
for(i=0; i<argc; i++)
{
wargs[i] = NULL;
wargs[i] = convert( argv[i] );
if( !wargs[i] )
return -2;
}
return 0;
}
int main(int argc, char **argv)
{
int i, err;
wchar_t **wargs;
/* convert what we need */
err = convert_args(argc, argv, &wargs);
if( err )
return -1;
err = winmain(argc, wargs);
/* free all the stuff */
for(i=0; i<argc; i++)
free( wargs[i] );
free( wargs );
return err;
}