In effect , I lost an entire morning not realizing the fact that I 
didn't initialize the lpstrfile buffer to "" ..... now it works ....
Thank you so much .




--- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>
> spudgun0 wrote:
> > Ok this is what I do in my WinMain ():
> > 
> >     ZeroMemory(&OfnSts, sizeof(OPENFILENAME));
> > 
> >     OfnSts.lStructSize      = sizeof(OPENFILENAME);
> >     OfnSts.lpstrFile        = (char *)malloc(MAX_FILENAME_LEN);
> >     OfnSts.nMaxFile         = MAX_FILENAME_LEN;
> >     OfnSts.Flags            = OFN_FILEMUSTEXIST | 
> > OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER /*| OFN_EXPLORER 
*/ ;
> >     OfnSts.hInstance                = hMainInstance;
> >     OfnSts.lpfnHook                 = NULL;
> >     OfnSts.hwndOwner                = GetActiveWindow();
> >     OfnSts.lpTemplateName   = NULL;
> >     OfnSts.lpstrFilter              = filter;
> >     OfnSts.lpstrInitialDir  = NULL;
> >     OfnSts.lpstrCustomFilter= NULL;
> >     OfnSts.nFilterIndex     = 1;
> >     OfnSts.lpstrFileTitle   = NULL;
> >     OfnSts.lpstrDefExt      = NULL;
> > 
> > The structure OfnSts is declared as a global OPENFILENAME .
> > In a subsequent call to a DialogBox , I just call
> > 
> > the GetOpenFileName (&ofnSts) .
> > 
> > This call always fails with a  CDERR_INITIALIZATION error, no 
matter 
> > what parameters I set in OfnSts.
> > Any idea ?
> > thanx
> 
>  From MSDN Library on 'lpstrFile':
> "Pointer to a buffer that contains a file name used to initialize 
the 
> File Name edit control. The first character of this buffer must be 
NULL 
> if initialization is not necessary."
> 
> You got the first sentence correct.  Not so hot on the second one.  
When 
> reading MSDN Library, you have to _stare_ at it for hours on end to 
be 
> absolutely certain you are doing it right before writing even one 
line 
> of code...and not missing anything critical.  Microsoft buries 
important 
> information in multiple locations - cross-check each line with the 
> documentation for proper use.  When I'm messing with APIs, I have 
30-40 
> browser windows open...and even then I can still miss something 
> important.  I always assume any example I see is wrong in some 
fashion.
> 
> Also, the 'hInstance' parameter should be NULL - you aren't 
supplying a 
> dialog box resource.
> 
> Those are the only obvious things that stick out.  You don't really 
need 
> to be assigning NULLs everywhere,..you did a ZeroMemory() call, 
which is 
> good enough.
> 
> -- 
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
> 
> *NEW* VerifyMyPC 2.4
> Change tracking and management tool.
> Reduce tech. support times from 2 hours to 5 minutes.
> 
> http://www.CubicleSoft.com/VerifyMyPC/
>


Reply via email to