NO

Author Topic: Open File Dialog Example  (Read 2363 times)

Offline iwrbc

  • Member
  • *
  • Posts: 16
Open File Dialog Example
« on: October 01, 2020, 09:33:51 PM »
Hi,
I am experiencing a problem when I use the file dialog from the website smorgasbordet. I do not understand it.
What I first did: I used the program 'as is' and it worked. Then I copied the code my own program, line by line, and got an error very soon.
The code is:
Code: [Select]
HRESULT Simple_FileOpenDialog(HWND hwndParent)
{
    IFileOpenDialog *pfod = NULL;  /* (IFileSaveDialog is similar) */

    // Create the File Open Dialog COM object.
    HRESULT hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileDialog, (void **)&pfod);
The last line here gives two linker errors:
Unresolved external symbol 'CLSID_FileOpenDialog'
Unresolved external symbol 'IID_IFileDialog'
These symbols are in the file shobjidl.h which I included.
In fact, I included all headers as in the sample:
Code: [Select]
#include <windows.h>
#define COBJMACROS
#include <shobjidl.h>       /* for IFileDialog, IFileOpenDialog, IFileSaveDialog */
#include <knownfolders.h>   /* for known folder APIs and definitions */
#include <wchar.h>

I have no idea what I am doing wrong. Any suggestions? Would be appreciated...

Offline algernon_77

  • Member
  • *
  • Posts: 33
Re: Open File Dialog Example
« Reply #1 on: October 02, 2020, 02:35:13 AM »
Hi there!

Just including the headers is not enough, the linker should know where to find CLSID_FileOpenDialog and IID_IFileDialog (they're not exported from the default libraries).
Try adding ole32.lib and uuid.lib to the linker library list (Project Options->Linker->Library and object files), that should do the trick.

Regards!

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Open File Dialog Example
« Reply #2 on: October 02, 2020, 07:16:52 AM »
A tool for searching GUIDs from libs
https://forum.pellesc.de/index.php?topic=7293.msg27680#msg27680

const GUID CLSID_FileOpenDialog = {0xDC1C5A9C,0xE88A,0x4DDE,0xA5,0xA1,0x60,0xF8,0x2A,0x20,0xAE,0xF7};
const GUID IID_IFileDialog = {0x42F85136,0xDB7E,0x439C,0x85,0xF1,0xE4,0x07,0x5D,0x13,0x5F,0xC8};

May the source be with you

Offline iwrbc

  • Member
  • *
  • Posts: 16
Re: Open File Dialog Example
« Reply #3 on: October 02, 2020, 09:58:12 AM »
Thank you both.