#include "codechange.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#include <locale.h>
wchar_t *ansitounicode (const char* str) {
int textlen = 0;
wchar_t *result = NULL;
Textlen = MultiByteToWideChar (cp_acp,0,str,-1,null,0);
result = (wchar_t*) malloc ((textlen+1) *sizeof (wchar_t));
Memset (result,0, (textlen+1) *sizeof (wchar_t));
MultiByteToWideChar (Cp_acp,0,str,-1, (LPWSTR) result,textlen);
return result;
}
Char *unicodetoansi (const wchar_t *STR) {
char *result = NULL;
int textlen = 0;
Textlen = WideCharToMultiByte (cp_acp,0,str,-1,null,0,null,null);
result = (char*) malloc ((textlen+1) *sizeof (char));
memset (result,0,sizeof (char) * (textlen+1));
WideCharToMultiByte (Cp_acp,0,str,-1,result,textlen,null,null);
return result;
}
wchar_t *utf8tounicode (const char* str) {
int textlen = 0;
wchar_t *result = NULL;
Textlen = MultiByteToWideChar (cp_utf8,0,str,-1,null,0);
result = (wchar_t *) malloc ((textlen+1) *sizeof (wchar_t));
Memset (result,0, (textlen+1) *sizeof (wchar_t));
MultiByteToWideChar (Cp_utf8,0,str,-1, (LPWSTR) result,textlen);
return result;
}
char* UnicodeToUTF8 (const wchar_t* str) {
char *result = NULL;
int textlen = 0;
Textlen = WideCharToMultiByte (cp_utf8,0,str,-1,null,0,null,null);
result = (char*) malloc ((textlen+1) *sizeof (char));
memset (result,0,sizeof (char) * (textlen+1));
WideCharToMultiByte (Cp_utf8,0,str,-1,result,textlen,null,null);
return result;
}
wchar_t* m2w (const char* MBS) {
int len = 0;
wchar_t* buf;
Len = mbstowcs (null,mbs,0);
if (len = = 0)
return NULL;
BUF = (wchar_t*) malloc (sizeof (wchar_t) * (len+1));
memset (buf,0,sizeof (wchar_t*) * (len+1));
Len = mbstowcs (buf,mbs,len+1);
return buf;
}
char* ANSIToUTF8 (const char* str) {
Return UnicodeToUTF8 (Ansitounicode (str));
}
char* utf8toansi (const char* str) {
Return Unicodetoansi (Utf8tounicode (str));
}
C Language Character Set conversion