Undefined reference to 'GetOpenFileNameA@4'

So as the title suggests, when I try building & running my program using Code::Blocks (not that it may have anything to do with this problem, just thought it would be essential to add in), I get that error.

What I did was copy this piece of code from this website:
http://www.winprog.org/tutorial/app_two.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
OPENFILENAME ofn;
    char szFileName[MAX_PATH] = "";

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
    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))
    {
        // Do something usefull with the filename stored in szFileName 
    }


And well, of course, it didn't work :(.

Will someone explain to me why I get this error? Thanks!
Did you #include <Windows.h> and linked against Comdlg32.lib? Don't ask me how to configure the linker in Code::Blocks, though. I only use Visual Studio.
As webjose said, you must link against comdlg32.lib (if you use Microsoft compiler) or libcomdlg32.a if you use MinGW.

Project -> Build options -> Linker settings -> Add and either write manually library name or browse for the file.
Topic archived. No new replies allowed.