hello,
I am new to these boards but I am not new to cprogramming.com.
anyways I am trying to add a GetOpenFileName() function to my application and compiler is giving an error for ZeroMemory(). I honestly don't know what is wrong here, error message doesn't help much, and I look at open source code that compiles fine and are doing it the same way I am. here is the error it is giving me:
fatal error C1057: unexpected end of file in macro expansion
I am not using any macros or preprocessor directives (other than #include of course). When I comment out the ZeroMemory() I get:
error C2039: 'hWndOwner' : is not a member of 'tagOFNA'
error C2360: initialization of 'szFileName1' is skipped by 'case' label
error C2146: syntax error : missing ';' before identifier 'ofn'
fatal error C1057: unexpected end of file in macro expansion
here is my code:
Code:
HWND ADDDlg = NULL;
BOOL CALLBACK ADDDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(wParam) {
case IDC_BROWSE_1:
OPENFILENAME ofn;
char szFileName1[MAX_PATH] = "";
ZeroMemory(&ofn, (sizeof(ofn)); // error is here??? O_o
ofn.lStructSize = sizeof(ofn);
ofn.hWndOwner = hWnd;
ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "Browse for file path 1\0";
ofn.lpstrFile = szFileName1;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn) == TRUE) {
SetWindowText(GetDlgItem(hWnd, IDC_PATH_1), szFileName1);
}
break;
case IDC_BROWSE_2:
char OPENFILENAME ofn;
char szFileName2[MAX_PATH] = "";
ZeroMemory(&ofn, (sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hWndOwner = hWnd;
ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "Browse for file path 2\0";
ofn.lpstrFile = szFileName2;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn) == TRUE) {
SetWindowText(GetDlgItem(hWnd, IDC_PATH_2), szFileName2);
}
break;
case WM_CLOSE:
EndDialog(hWnd, 0);
break;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_ADD_DLG), NULL, ADDDlgProc);
}
that is full code from below includes including main. can someone please tell me what is going wrong here? also any tips to improve code size/efficiency are always appreciated.
thanks alot!
-piecer