6 Replies - 6734 Views - Last Post: 07 January 2013 - 11:23 PM Rate Topic: -----

#1 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Windows OpenFileName CDERR_INITIALIZATION error

Posted 06 January 2013 - 11:19 PM


                    OPENFILENAME of;
                    SecureZeroMemory(&of, sizeof(OPENFILENAME));

                    of.lStructSize  = sizeof(OPENFILENAME);
                    of.lpstrTitle   = "Open Image File";
                    of.hwndOwner    = window;
                    of.lpstrFilter  = "Image Files\0Bitmap(.bmp)\0*.bmp\0";
                    of.Flags        = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
                    of.nFilterIndex = 1;

                    of.lpstrFile    = new char[256];
                    SecureZeroMemory(of.lpstrFile, 256 * sizeof(char));

                    if(!GetOpenFileName(&of))
                    {

                        DWORD b = CommDlgExtendedError();

                        delete[] of.lpstrFile;

                        return TRUE;
                    }
                    
                    SetWindowText((HWND)Txt_Browse, of.lpstrFile);

                    delete[] of.lpstrFile;




GetOpenFileName returns 0, and CommDlgExtendedError returns CDERR_INITIALIZATION.

Any help will be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Windows OpenFileName CDERR_INITIALIZATION error

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 03:35 AM

A couple of things,


You are not initialising the full structure of openfilename

also .lpstrFile needs to be given a variable not initialised as a variable

something like CHAR File[256]; will do

full code listing that should solve your problems

OPENFILENAME ofn;
CHAR File[256];
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.hInstance = NULL;
	ofn.lpstrCustomFilter = NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 0;
	ofn.lpstrFile = File;
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof(File);
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrTitle = NULL;
	ofn.Flags = 0;
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = NULL;
	ofn.lCustData = 0L;
	ofn.lpfnHook = NULL;
	ofn.lpTemplateName = NULL;
	GetOpenFileName(&ofn);


SetWindowText(Txt_Browse, File);




Best Wishes

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,473
  • Joined: 05-May 12

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 06:26 AM

Actually, the ZeroMemory() is equivalent to all the setting to NULL and 0 for the structure. And the allocation of lpstrFile directly in fine. OpenFileDialog() doesn't care if the point points to the heap or to the stack. The problem was that nMaxFile was not initialized.
Was This Post Helpful? 2
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 06:32 AM

View PostSkydiver, on 07 January 2013 - 01:26 PM, said:

Actually, the ZeroMemory() is equivalent to all the setting to NULL and 0 for the structure. And the allocation of lpstrFile directly in fine. OpenFileDialog() doesn't care if the point points to the heap or to the stack. The problem was that nMaxFile was not initialized.



Is it ?

Well I never knew that thanks for sharing...

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#5 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 06:58 AM

View PostSkydiver, on 07 January 2013 - 06:26 AM, said:

Actually, the ZeroMemory() is equivalent to all the setting to NULL and 0 for the structure. And the allocation of lpstrFile directly in fine. OpenFileDialog() doesn't care if the point points to the heap or to the stack. The problem was that nMaxFile was not initialized.


Thanks, I've fixed that now and it's displaying, however none of the controls on the dialog are working and it won't let me close it at all.
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 01:43 PM

Hi again,

of.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

Try adding OFN_EXPLORER to that list in Flags...


Best Wishes

Snoopy.
Was This Post Helpful? 2
  • +
  • -

#7 kojima100  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 66
  • Joined: 10-November 10

Re: Windows OpenFileName CDERR_INITIALIZATION error

Posted 07 January 2013 - 11:23 PM

It works now. Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1