我正在为我的 Now Playing 插件获取 Spotify 的窗口标题,其中包含以下功能:
GetWindowText(spotify_window_handle, title, title_length)
但输出包含替换字符 \uFFFD。
Ex. Spotify - Killswitch Engage � One Last Sunset
如何在 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