我现在做的一个文件接口模块,做成DLL文件。
当程序打开的文件较小时,运行正常,
但是当文件较大(几兆)的时候,
程序直接运行会出现非法操作。
而程序在调试模式下时。
当一个动态链接库中的函数返回时出现 “无法找到动态链接库GDI32.DLL于指定路径”的对话框。
我知道这时一个系统的动态链接库,可是我没有调用它啊,
而且当我从系统目录(winnt\system32)下把这个文件复制到我的程序目录下,
再调试出现“无法找到动态链接库OLE32.DLL于指定路径”的对话框。
神啊,救救我吧!!!
注:我用是vc6。
当程序打开的文件较小时,运行正常,
但是当文件较大(几兆)的时候,
程序直接运行会出现非法操作。
而程序在调试模式下时。
当一个动态链接库中的函数返回时出现 “无法找到动态链接库GDI32.DLL于指定路径”的对话框。
我知道这时一个系统的动态链接库,可是我没有调用它啊,
而且当我从系统目录(winnt\system32)下把这个文件复制到我的程序目录下,
再调试出现“无法找到动态链接库OLE32.DLL于指定路径”的对话框。
神啊,救救我吧!!!
注:我用是vc6。
CFile::ReadHuge
DWORD ReadHuge( void* lpBuffer, DWORD dwCount );
throw( CFileException );Return ValueThe number of bytes transferred to the buffer. Note that for all CFile objects, the return value can be less than dwCount if the end of file was reached. ParameterslpBufPointer to the user-supplied buffer that is to receive the data read from the file.dwCountThe maximum number of bytes to be read from the file. For text-mode files, carriage return–linefeed pairs are counted as single characters.ResReads data into a buffer from the file associated with the CFile object.This function differs from Read in that more than 64K–1 bytes of data can be read by ReadHuge. This function can be used by any object derived from CFile.Note ReadHuge is provided only for backward compatibility. ReadHuge and Read have the same semantics under Win32.
ReadHuge is obsolete and is no longer supported.
Res
Use Read instead.See Also
CFile Overview | Class Members | Hierarchy ChartReadHuge(...)在vc7.0中已经没有了.
建议:判断文件大小,如果太大的话,分多次读写.
但是我没有用到CFile的相关操作
最好用CreateFile,ReadFile/WriteFile
可以一次读写DWORD2^32(4G吧)这么多字节
Win32的函数可以一口气吧整个文件都读进来
你用的什么函数?
“你应该在主程序中开辟一个足够大的共享区,否则的文件是读到dll的数据区的,当你的文件过大的时候就会出错了。将你的文件读入共享区而不使用dll自己的数据区。”可是我不知道怎么在主程序中开辟共享区啊,能不能扩大DLL的数据区呢?
这里的DLL应该指的是C Runtime的DLL,如果你使用了动态连接的话你可以让C Runtime(就是所有C的函数的集合以及一些初始化和卸载的处理)
要使用你自己的缓冲区
使用下面的c函数:(最好还是推荐使用Windows的API)
让buffer指向一块很大的内存
int setvbuf(
FILE *stream,
char *buffer,
int mode,
size_t size
);
Parameters
stream
Pointer to FILE structure.
buffer
User-allocated buffer.
mode
Mode of buffering.
size
Buffer size in bytes. Allowable range: 2 <= size <= INT_MAX (2147483647). Internally, the value supplied for size is rounded down to the nearest multiple of 2.
Return Value
Returns 0 if successful, or a nonzero value if an illegal type or buffer size is specified.