Search code examples
c++windowsvisual-studio-2010user-interfacegetopenfilename

Is there a workaround for the character limit on the Windows API function GetOpenFileName() when OFN_ALLOWMULTISELECT?


According to the MSDN documentation, the function GetOpenFileName() has no character limit with option OFN_ALLOWMULTISELECT when compiled for Unicode with Windows 2000 and greater. However, on Windows XP x64 SP2, I'm finding that the 32k ANSI limit is still in effect, despite the use of Unicode. I've seen other complaints of this problem on the web, but no solutions. Does anyone know a simple work-around for this?

To be complete, I'm using Visual Studio 2010, and coding in C++.


Solution

  • The documentation might be wrong. GetOpenFileName() is somewhat deprecated, and it no longer supports the latest Vista/Windows 7 features. What's even worse is that GetOpenFileName() pops up an Open dialog that looks like the one in Windows 95, at least when you try to customize the dialog with the LPOFNHOOKPROC feature on Vista or Windows 7.

    Beginning with Vista and Windows Server 2008, the new recommended API is the IFileDialog interface: http://www.codeproject.com/KB/vista/VGFileDialogs.aspx?msg=2368264. Unfortunately this isn't available on XP, therefore you need to implement both APIs depending on the OS version. If you need to add a few custom controls to your Open dialog, you have no choice at all but to use IFileDialogCustomize anyway.

    I realize that your question was regarding Windows XP, and my suggested workaround won't help you, but unfortunately IFileDialog is the only alternative to GetOpenFileName().