KristjanLaane
asked on
vc++ unicode messagebox char issue
i need to pass path information from one event to another, but the char that i use for that gets 'garbled' in the process
i.e. for the code below, the first Messagebox shows me a file path as i need, whereas the second messagebox shows a lot of weird characters. ...
whats going on, is this to do with the fact that my project is compiled in unicode?
i.e. for the code below, the first Messagebox shows me a file path as i need, whereas the second messagebox shows a lot of weird characters. ...
whats going on, is this to do with the fact that my project is compiled in unicode?
char *currentSongPath;
LRESULT CALLBACK WinampWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
int ret = CallWindowProc(proc,hwnd,umsg,wParam,lParam);
if (umsg == WM_WA_IPC && lParam == IPC_PLAYING_FILE) {
// File Path and Name about to be played right now
currentSongPath = (char*)wParam;
MessageBoxA(NULL,currentSongPath,"This outputs a file path as it should", MB_OK);
}
if (umsg == WM_WA_IPC && lParam == IPC_GET_NEXT_PLITEM) {
// res will be millisecond into play when next is played or if song finishes
MessageBoxA(NULL, currentSongPath,"This same line outputs a garbled thing", MB_OK);
}
return ret;
}
ASKER
this does not work as wParam holds completely different values for the differnet events.
and the event where lParam == IPC_PLAYING_FILE always occurs before the event where lParam == IPC_GET_NEXT_PLITEM, so currentSongPath shoudl be initialised anyway when the event lParam == IPC_GET_NEXT_PLITEM is raised
and im not sure this is an initialisation problem, i think the garbage might be to do with character encoding ...
and the event where lParam == IPC_PLAYING_FILE always occurs before the event where lParam == IPC_GET_NEXT_PLITEM, so currentSongPath shoudl be initialised anyway when the event lParam == IPC_GET_NEXT_PLITEM is raised
and im not sure this is an initialisation problem, i think the garbage might be to do with character encoding ...
>>and im not sure this is an initialisation problem
It pretty certainly is, look at your code:
It pretty certainly is, look at your code:
char *currentSongPath;
LRESULT CALLBACK WinampWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
int ret = CallWindowProc(proc,hwnd,umsg,wParam,lParam);
if (umsg == WM_WA_IPC && lParam == IPC_PLAYING_FILE) {
// File Path and Name about to be played right now
currentSongPath = (char*)wParam;
MessageBoxA(NULL,currentSongPath,"This outputs a file path as it should", MB_OK);
}
if (umsg == WM_WA_IPC && lParam == IPC_GET_NEXT_PLITEM) {
// res will be millisecond into play when next is played or if song finishes
//
// here, 'currentSongPath' is not assigned a value
// and the last value from a previous call is no
// longer valid. You need to initialize this variable
// somehow or you'l get 'garbage'
//
MessageBoxA(NULL, currentSongPath,"This same line outputs a garbled thing", MB_OK);
}
return ret;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i got this error message when i tried to compile
Error 6 error C2664: 'strncpy' : cannot convert parameter 2 from 'size_t' to 'const char *' e:\Code\SoundCutPrototype\ SoundCut4W inamp\main .cpp 86 gen_blah
then realised the 8th line had a syntax error, and when i fixed it to below, it works ! thanks !!!
Error 6 error C2664: 'strncpy' : cannot convert parameter 2 from 'size_t' to 'const char *' e:\Code\SoundCutPrototype\
then realised the 8th line had a syntax error, and when i fixed it to below, it works ! thanks !!!
strncpy(currentSongPath, (char*)wParam, sizeof(currentSongPath) - 1);
Open in new window