GetOpenFileName() works in release not debug

So i am following this(http://www.winprog.org/tutorial/app_two.html) tutorial as a beginner to windows programming, and so far i have been able to solve every problem iv come across, that is until i got to this one. when i call GetOpenFileName(insertmypointerhere) i get the error "193|undefined reference to `GetOpenFileNameA@4'|", i have included <windows.h>. Also as if that is not strange enough it only happens in debug not release.

I am using Codeblocks as my ide and gnu gcc compiler.
i have windows 7.

heres the function that GetOpenFileName is called in:


"
void DoFileOpen(HWND hwnd)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";

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);
}
}
"
Last edited on
libcomdlg32.a needs to be included in linker input.
#include <windows.h>
#include "resource.h"

those are my only two includes, i also added windows sdk include dir to compiler and linker and still get the same error do i need to include the file in my source as well?

also deserves mention that i dont have this problem with visual studio 2012
actually nevermind i figured it out.

in case of someone having same issue

you need to add the above mentioned file to your linker libraries.

to do this
settings->Compiler and Debugger->linker settings
then add "...Microsoft SDKs\Windows\v6.1\Lib\ComDlg32.Lib" to your linker libraries.

so pretty much just what modoran said.

thx modoran, now i can continue with my tutorial :-).
Last edited on
Topic archived. No new replies allowed.