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)
	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.lpstrDefExt = "txt";

		HWND hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
		LoadTextFileToEdit(hEdit, szFileName);


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.

I found the solution as I was searching using Google. The C::B GCC compiler does not support this, so you need to install Open Watcom, as set this as your compiler for your project. You can download it at http://www.openwatcom.org/index.php/Download (click one of the mirror links and then go to the Watcom directory and download the .exe file that corresponds with your OS) and installation guide is at http://www.openwatcom.org/index.php/Configuring_Code::Blocks


This article has been dead for over six months. Start a new discussion instead.