您的位置:首页 > 其它

解决exe和DLL直接传递FILE 指针崩溃的问题

2017-02-15 18:24 661 查看
EXE程序和DLL之间可能传递FILE指针,但是可能会造成程序崩溃。这是由于_lock_file引起的

[cpp] view plain copy print?void __cdecl _lock_file (
FILE *pf
)
{
/*
* The way the FILE (pointed to by pf) is locked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= _iob) && (pf <= (&_iob[_IOB_ENTRIES-1])) )
{
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
*/
_lock( _STREAM_LOCKS + (int)(pf - _iob) );
/* We set _IOLOCKED to indicate we locked the stream */
pf->_flag |= _IOLOCKED;
}
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
EnterCriticalSection( &(((_FILEX *)pf)->lock) );
}



if ( (pf >= _iob) && (pf <= (&_iob[_IOB_ENTRIES-1])) ) 把fp和一个全局变量_iob比较,exe和DLL可能会有不同的全局变量,这导致fp不在_iob数组的范围内,导致出现错误。

解决的颁发是exe和DLL都动态连接到CRT,或者把DLL编译成静态库。

转自:http://blog.csdn.net/leechiyang/article/details/6873952
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dll exe file lock-file 崩溃
相关文章推荐