I am trying to select a file and place the file path in an edit box. When i do so i get a garbled string like 穨< when the actual path is something like c:\config\333.conf
I have two other edit boxes that i am using to select a folder path that work correctly.
I have a wchar_t* holding the path that i want to write to the editbox.
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
SendMessage(hDlg, WM_CLOSE, 0, 0);
return TRUE;
case IDOK:
DoTune();
return TRUE;
case IDC_IMAGE_A_FOLDER_SELECT_BUTTON:
str = OpenFolder();
SetDlgItemText(hDlg, IDC_IMAGE_A_EDIT, str); return TRUE;
case IDC_IMAGE_B_FOLDER_SELECT_BUTTON:
str = OpenFolder();
SetDlgItemText(hDlg, IDC_IMAGE_B_EDIT, str); return TRUE;
case IDC_CONF_FILE_SELECT_BUTTON:
wchar_t* filter = L"CONF Files (*.conf)\0*.conf\0";
str = OpenFileName(filter, NULL);
SetDlgItemTextW(hDlg, IDC_CONF_EDIT, str); return TRUE;
}
break;
case WM_CLOSE:
if(MessageBox(hDlg, TEXT("Close the program?"), TEXT("Close"),
MB_ICONQUESTION | MB_YESNO) == IDYES)
{
DestroyWindow(hDlg);
}
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#include "resource.h"
#include <string>
#include <commdlg.h>
#include <shlobj.h>
#include <stdio.h>
#include <strsafe.h>
#include <comdef.h>
#include <string.h>
wchar_t* str;
char* CONFIG_PATH_ANALYSIS;
int numFiles;
void DoTune();
void DisplayErrorBox(LPTSTR lpszFunction);
wchar_t* OpenFolder();
void RunAnalysis(wchar_t* Folder);
wchar_t* ConvertCharArrayToLPCWSTR(const char* charArray);
wchar_t* OpenFileName(wchar_t *filter, HWND owner);
typedef int (__cdecl *ANALYZE_PROC)(char *, char *, char *,char *, bool, bool);
typedef int (__cdecl *GETAVERAGE_PROC)(char *, char *);
typedef int (__cdecl *VERIFY_PROC)(char *, char *);
HINSTANCE hFoo;
HWND hDlg;
GETAVERAGE_PROC getAverageProcess;
ANALYZE_PROC analyzeProcess;
VERIFY_PROC verifyProcess;
wchar_t* OpenFileName(wchar_t *filter, HWND owner) {
OPENFILENAME ofn;
wchar_t fileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = NULL;
wchar_t* fileNameStr;
if ( GetOpenFileName(&ofn) )
fileNameStr = fileName;
return fileNameStr;
}
as you can see it's pretty straightforward and i am not new to C++ so i figure i am missing something simple. Also, i have verified that str has the correct path before it gets passed to the SetDlgItemText function.
As always, i appreciate any input.