What's Here?
- Members: 340,149
- Replies: 920,517
- Topics: 154,948
- Snippets: 4,855
- Tutorials: 1,257
- Total Online: 3,872
- Members: 121
- Guests: 3,751
|
Welcome to Dream.In.Code |
|
|
Become an Expert!
Join 340,149 Programmers for FREE! Get instant access to thousands  of experts, tutorials, code snippets, and more! There are 3,872 people online right now. Registration is fast and FREE... Join Now!
Chat LIVE With a Expert
|
Common Dialog Boxes
Common Dialog Boxes
i haz errors
Rate Topic:
   
Posted 22 February 2009 - 06:35 PM
I'm trying to use an open file common dialog box, but I'm getting a "|47|undefined reference to `_GetOpenFileNameA@4'|".
Here's the function GetOpenFileName is called in:
void FileOpen(HWND hwnd)
{
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
}
(Yeah, I pretty much just copy/pasted from MSDN  .)
I'm using Code::Blocks on Vista, and I'd be grateful if anyone who's in the same boat would try to compile the code and let me know what errors (if any) they get.
My main question is this: is there a library i'm missing? I've included windows.h, but could one of the libraries it #include s be missing?
Posted 22 February 2009 - 06:45 PM
Did you see this?
Quote Note Starting with Windows Vista, the Common File Dialog has been superseded by the Common Item Dialog when used to open a file. We recommended that you use the Common Item Dialog API instead of the Common File Dialog API in this case. For more information, please see Common Item Dialog.
Posted 22 February 2009 - 06:48 PM
I kind of assumed it'd be backward compatible with the rest of NT...
Soo, will common item dialog work on XP?
Posted 22 February 2009 - 06:53 PM
I would think that starting with Vista means that it will still work for XP. I've used the File Open Common Dialog Box from the Windows API on XP before. It wouldn't hurt to detect the Windows version in your code, that way assuring the API will work correctly.
Posted 22 February 2009 - 06:55 PM
Yeah. Barebone code on XP I can compile:
#include <windows.h>
void FileOpen(HWND);
int WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd;
FileOpen(hwnd);
return 0;
}
void FileOpen(HWND hwnd)
{
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
}
Posted 22 February 2009 - 07:04 PM
Quote I would think that starting with Vista means that it will still work for XP.
I sure hope so.
I like the version checking idea, but that only means it'll decide whether or not to execute the code. Although that may be helpful, my problem is with compiling, not executing.
Thanks for the help KYA/no2.
This post has been edited by lanec42: 22 February 2009 - 07:05 PM
Posted 22 February 2009 - 07:05 PM
Did you include commdlg.h?
Posted 22 February 2009 - 07:06 PM
No. Do I need to? I'll go try it.
EDIT: Doesn't help. I was under the impression that windows.h included commdlg.h, though.
MORE EDIT: I'm reading the common item dialog stuff. Once i get a good compile, i'll go try it on an XP box.
This post has been edited by lanec42: 22 February 2009 - 07:09 PM
Posted 22 February 2009 - 07:09 PM
lanec42, on 22 Feb, 2009 - 08:06 PM, said:
I was under the impression that windows.h included commdlg.h, though.
It does. The actual info for this call is in commdlg.h, but including windows.h covers that:
Quote Declared in Commdlg.h, include Windows.h
This post has been edited by KYA: 22 February 2009 - 07:10 PM
Posted 22 February 2009 - 07:11 PM
Do your linker settings include comdlg32.lib?
Posted 22 February 2009 - 07:11 PM
Schweet. Maybe I should just spend a year as a hermit windows monk, reading header files from dawn to dusk.
Quote Do your linker settings include comdlg32.lib?
Good question. I'll check.
Wait, does that matter if it's included in windows.h anyway?
This post has been edited by lanec42: 22 February 2009 - 07:14 PM
Posted 22 February 2009 - 07:14 PM
 Sorry, i wasn't suggesting that. I was merely relating some information readily and easily available. Can you get the snippet I showed to compile on Vista? That's as small as you can get before adding other stuff.
Posted 22 February 2009 - 07:19 PM
No, it won't compile, but I think that's cause it still uses "Common File Dialog" stuff. At least that means it (probably) wasn't just my code
Posted 22 February 2009 - 07:24 PM
That's good, at least the problem is somewhat isolated. How 'bout this?
HRESULT SimpleInvoke(HWND hwnd)
{
IFileDialog *pfd;
// CoCreate the dialog object.
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARG(IFileDialog, &pfd));
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(hwnd);
if (SUCCEEDED(hr))
{
// Obtain the result of the user's interaction with the dialog.
IShellItem *psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
// Do something with the result.
psiResult->Release();
}
}
pfd->Release();
}
return hr;
Why the hell did they make opening a file dialog more complicated then it needs to be? URGH
This post has been edited by KYA: 22 February 2009 - 07:29 PM
Posted 22 February 2009 - 07:29 PM
D:\Users\lanec42\Desktop\Balance1\file.cpp||In function `void FileOpen(HWND__*)':|
D:\Users\lanec42\Desktop\Balance1\file.cpp|8|error: `CLSID_FileOpenDialog' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|11|error: `IFileDialog' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|11|error: `pfd' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|11|error: `IID_PPV_ARG' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|21|error: `IShellItem' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|21|error: `psiResult' was not declared in this scope|
D:\Users\lanec42\Desktop\Balance1\file.cpp|21|warning: unused variable 'IShellItem'|
||=== Build finished: 7 errors, 4 warnings ===|
Still not happening.
Where was "pfd" and "psiResult" declared, anyway?  rawr m$.
EDIT: this "Minimum operating systems Windows Vista" was here. Will this be Vista-only if (ever) i get it working? That's what they seem to suggest...
This post has been edited by lanec42: 22 February 2009 - 07:34 PM
Posted 22 February 2009 - 07:41 PM
Are you using Dev-C++?
If so, in the Project Options dialog box ( Project->Project Options, or Alt+P), make sure in the Type group that Win32 GUI is selected, and not Win32 Console.
This post has been edited by bsaunders: 22 February 2009 - 08:58 PM
Posted 23 February 2009 - 06:32 AM
I'm using Code::Blocks, but it's similar. I'll try rebuilding from scratch, maybe that'll help.
1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|