尽管
GetWindowText(spotify_window_handle, title, title_length)
输出包含替换字符。
Spotify - Philip Glass � Glassworks Opening
我需要用“-”替换“�”。我前段时间发布了这个问题,但没有粘贴我的代码,所以回答我假设我使用 wchar_t 作为标题,但我不是。标题是 char*。任何帮助将不胜感激,我是 C 编码的“新手”,有时我对一些基本/奇怪的行为有很大的困难。
这是我的代码:
char* spotify_title(int window_handle)
{
int title_length = GetWindowTextLength(window_handle);
if(title_length != 0)
{
char* title;
title = (char*)malloc((++title_length) * sizeof *title );
if(title != NULL)
{
GetWindowText(window_handle, title, title_length);
if(strcmp(title, "Spotify") != 0)
{
return title;
}
else
{
return "Spotify is not playing anything right now. Type !botnext command to restart playback.";
}
}
else
{
printf("PLUGIN: Unable to allocate memory for title\n");
}
free(title);
}
else
{
printf("PLUGIN: Unable to get Spotify window title\n");
}
}
// End of Spotify get title function