Hey everybody,

I am currently having difficulty using GetOpenFileName() and GetSaveFileName(). The keeps returning the error " undefined reference to `_GetOpenFileNameA@4' ". I can't seem to find a fault in my code, so is it the compiler or is it the code? I am using CodeBlocks.

void DoFileOpen(HWND hwnd)
{
	OPENFILENAME ofn;
	char szFileName[MAX_PATH] = ""; // Buffer in which the filename will be placed

	ZeroMemory(&ofn, sizeof(ofn));

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
	ofn.lpstrFile = szFileName;
	ofn.nMaxFile = MAX_PATH;
	ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	ofn.lpstrDefExt = "txt";

	if(GetOpenFileName(&ofn))
	{
		HWND hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
		LoadTextFileToEdit(hEdit, szFileName);
	}
}

~G

I don't know WINAPI, so I can't help you with your syntax, but it sounds like you are missing a library file that the linker needs.

You're probably missing comdlg32.lib in your linker settings.

By the way, the Common File Dialog API has been superseded by the Common Item Dialog API.