title: GetOpenFileName fails in 64 bit, but works in 32Bit?
body: <p>I have the following code, I use to Open a File Open Dialog using Win32 API. It works fine in 32bit, but fails when I use in a 64bit (In a DLL). What am I doing wrong?</p>
  
  <pre><code> char Filestring[256];
  Filter = "OBJ files\0*.obj\0\0";
  char* returnstring = NULL;
  
  
  
  OPENFILENAME opf;
  opf.hwndOwner = mainHWND;
  opf.lpstrFilter = Filter;
  opf.lpstrCustomFilter = 0;
  opf.nMaxCustFilter = 0L;
  opf.nFilterIndex = 1L;
  opf.lpstrFile = Filestring;
  opf.lpstrFile[0] = '\0';
  opf.nMaxFile = 256;
  opf.lpstrFileTitle = 0;
  opf.nMaxFileTitle=50;
  opf.lpstrInitialDir = Path;
  opf.lpstrTitle = "Open Obj File";
  opf.nFileOffset = 0;
  opf.nFileExtension = 0;
  opf.lpstrDefExt = "*.*";
  opf.lpfnHook = NULL;
  opf.lCustData = 0;
  opf.Flags = (OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT) &amp; ~OFN_ALLOWMULTISELECT;
  opf.lStructSize = sizeof(OPENFILENAME);
  
  if(GetOpenFileName(&amp;opf))
  {
      returnstring = opf.lpstrFile;
      if (returnstring) {
          result = returnstring;
      }
  
  }
  </code></pre>
  
  <p>EDIT: By failing, I meant that the Open File Dialog doesn't show up. The code still returns zero without any errors.</p>
  
  <p>EDIT 2: I have called CommDlgExtendedError() and it returned 1. From the MSDN reference, does it mean the dialog has invalid  lStructSize? I have checked the <code>sizeof(OPENFILENAME)</code> and it returned 140 bytes.</p>
  
  <p>UPDATE: In my Project Settings, Under Code Generation the "Struct Member Alignment" is set to 4 Bytes(/Zp4). I changed this to default and it magically worked. Look for the answers and their comments below for more information.</p>