Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: how convert string8 to ansi? (Read 5870 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

how convert string8 to ansi?

how convert string8 to ansi?

pfc::string8 text;
char *ch;
...
pc->playback_format_title_ex(handle, NULL, text, formatobj, NULL, playback_control::display_level_all);

I want convert "text" to "ch"?
I use "text = string_os_from_utf8(text.get_ptr())" before foobar0.8,but in foobar0.9,how convert?

how convert string8 to ansi?

Reply #1
maybe?
pfc::stringcvt::convert_utf8_to_wide
pfc::stringcvt::convert_wide_to_ansi
M-Audio Audiophile 24/96
Nad C350
B&W DM602S2

how convert string8 to ansi?

Reply #2
sprintf()


how convert string8 to ansi?

Reply #4
maybe?
pfc::stringcvt::convert_utf8_to_wide
pfc::stringcvt::convert_wide_to_ansi
Correct, but not the most straightforward thing to do. You can use pfc::stringcvt::string_*_from_utf8, for example pfc::stringcvt::string_ansi_from_utf8. Also, is there a particular reason why you need ANSI instead of UTF-16?


sprintf()
That function does not convert string encodings.

how convert string8 to ansi?

Reply #5
Correct, but not the most straightforward thing to do. You can use pfc::stringcvt::string_*_from_utf8, for example pfc::stringcvt::string_ansi_from_utf8. Also, is there a particular reason why you need ANSI instead of UTF-16?


I use pfc::stringcvt::string_ansi_from_utf8 but failured;
I want send strings from myplugs to another program,and those strings have some chinese,eg:"c:\\??",but the progam receive strings are disorderly strings,my codes as follows:
//send message
pfc::string8 text;
......
pc->playback_format_title_ex(handle, NULL, text, formatobj, NULL, playback_control::display_level_all);
pfc::stringcvt::string_os_from_utf8 os_class_name(text);
HWND hWnd;
COPYDATASTRUCT Cds;
hWnd=FindWindow(NULL,_T("another progame"));
if(hWnd!=NULL)
{
    memset(&Cds,0x00,sizeof(COPYDATASTRUCT));
    Cds.dwData =CmdSongFileName;
    Cds.cbData =os_class_name.length()+1;
    Cds.lpData =(LPVOID)os_class_name.get_ptr();
    SendMessage(hWnd,WM_COPYDATA,0,(LPARAM)&Cds);
}

//receive message
COPYDATASTRUCT * pcds = (COPYDATASTRUCT *)Message.CopyDataStruct;
switch(pcds->dwData)
{
  case CmdSongFileName:
    wchar_t *tt=new wchar_t[pcds->cbData];
    CopyMemory(tt,pcds->lpData,pcds->cbData);
    delete []tt;
    break;
}

Finally variable "tt" result are disorderly strings!why?how to solve?

how convert string8 to ansi?

Reply #6
Probably because you are taking an ANSI string and reading it as unicode (wchar_t).
Try string_wide_from_utf8 instead, or read the string as char* in the 'recieve message' part. However i don't think ANSI supports asian characters so i'd recommend using unicode.

how convert string8 to ansi?

Reply #7
Probably because you are taking an ANSI string and reading it as unicode (wchar_t).
No, that is not the problem, since string_os_from_utf8 is just a typedef for string_wide_from_utf8 as long as your are compiling for a Unicode target (which would always be the case for a foobar2000 0.9 component). Nonetheless, it would be a good idea to explicitly use either ANSI or Unicode encoding.

The real problem is here:
Cds.cbData =os_class_name.length()+1;
cbData contains the number of bytes you pass using WM_COPYDATA. However os_class_name.length() is the length in characters. You also have to pay attention in the reveicing code to allocate and copy the correct number of bytes.

how convert string8 to ansi?

Reply #8
The real problem is here:

    Cds.cbData =os_class_name.length()+1;
cbData contains the number of bytes you pass using WM_COPYDATA. However os_class_name.length() is the length in characters. You also have to pay attention in the reveicing code to allocate and copy the correct number of bytes.


Foosion?thank you very much!
I 'm going to test!