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

Recommended Answers

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.

Jump to Post

All 3 Replies

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.

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

~G

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.