需要使用CFileDialog,产生一个文件多选的对话框。但是默认的lpstrFile缓冲区只有200多,当打开比较多的文件时容易超过缓冲区返回错误:FNERR_BUFFERTOOSMALL 由CommDlgExtendedError()返回。
查看MSDN解释:
| Value | Meaning |
|---|---|
| FNERR_BUFFERTOOSMALL | The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the filename specified by the user. The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in bytes (ANSI version) or 16-bit characters (Unicode version), required to receive the full name. |
那就手动将缓冲区设置大一点即可。缓冲区的上限是2562。看下面示例:
还可以参考codeproject上的实例代码:
链接:http://www.codeproject.com/KB/dialog/pja_multiselect.aspx
本文介绍如何通过调整CFileDialog的lpstrFile缓冲区大小来实现文件多选功能,避免因缓冲区过小而导致的错误。同时提供了一个具体的示例代码。

150

被折叠的 条评论
为什么被折叠?



