I`m trying to play a mp3 file with c++ a console application.. so i need the exact path to it..
i figured out how to show the open file dialog .. but i still have some problems
CODE:
OPENFILENAME ofn;
char szFileName[MAX_PATH]="";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = GetActiveWindow();
ofn.nFileOffset=1;
ofn.Flags=OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
ofn.lpstrFilter = L"Text Files (*.mp3)\0*.mp3\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = (LPWSTR)szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = L"mp3";
if(GetOpenFileName(&ofn))
{
for(int i=0;i<256;i++)
{
cout<<szFileName
}
}
So this will return the path to the file.. but followed by white space untill end of buffer.. anyone any idea how can i retrive it exact

Open File Dialog
Clayton Marinho
Surely the string is null terminated
Either way, why is it a LPWSTR You're doing a Unicode build
abuzakour
jholetzeck
LPWSTR is a Unicode string. As you've discovered, every second character of an ANSI string is then NULL. You're getting these spaces because you're walking the entire array without looking for the end, which would be two nulls in a row. You'd do better to pass the array into a string class, and working with it there. I'm not sure if CString handles wide strings as you seem to be doing a unicode build.
Rick Byham
OPENFILENAME ofn;
ofn.lpstrFile is a LPWSTR type..
can you post some example and strange thing after the open file end and returns the path and when i cout<< the char array returned.. it is like this:
D : \ s o m e t h i n g . e x e (notice the space`s between characters)
I dont know.. this all LPWSTR LCWSTER w_tchar * .. string wstring type really gives me a head eak..
Please.. help ..
Oaklair
ryanflucas