困惑:在Non-MFC dll中使用fscanf, fprintf 操作调用进程打开的文件出错???!!!

phoenixandlinda 2004-11-12 11:12:38
为了测试,用C,C++分别做了两个同功能Non-MFC dll,都是接收父进程传入的FILE 指针来读写文件。但出错: Unhandled exception in test.exe(ntdll.dll):0xc0000005: Access Violation.
奇怪啊,不懂请各位指点一下。
OS: winxp Home
Compiler: VC6.0
...全文
140 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
keios 2004-11-15
  • 打赏
  • 举报
回复
fp = fopen("c:\\log.log","w"); // only w
……
fscanf(fp,"%s",strTemp); // fp 没有以读方式打开,只能对它写。因此出错
phoenixandlinda 2004-11-15
  • 打赏
  • 举报
回复
查看了一下MSVCRT.dll 都是6.00.8168.0,ExE 是 C++写的,dll是C写的。
phoenixandlinda 2004-11-15
  • 打赏
  • 举报
回复
另外,以只写方式打开的文件,如果用fscanf去做读操作,只是一般的失败(返回-1),不会出现“Unhandled exception in test.exe(ntdll.dll):0xc0000005: Access Violation.”这种致命错误。
phoenixandlinda 2004-11-15
  • 打赏
  • 举报
回复
笔误,fscanf(fp,"%s",strTemp); 应该注释掉。
dll 中不读文件,只是写文件也会出错。
flyelf 2004-11-12
  • 打赏
  • 举报
回复
代码
beyondtkl 2004-11-12
  • 打赏
  • 举报
回复
会不会是 多个进程对同一个文件操作的问题??...

怎么又有EXE了?
keios 2004-11-12
  • 打赏
  • 举报
回复
MSVCRT.dll 的版本问题!
exe 和 dll 链接的 C 运行库的不同版本。
用 depends 查一下
phoenixandlinda 2004-11-12
  • 打赏
  • 举报
回复
def :
LIBRARY TESTDLL
DESCRIPTION This is a test dll which a C++ program call a C procdure
EXPORTS
testdll;
oyljerry 2004-11-12
  • 打赏
  • 举报
回复
函数怎么导出
用共享数据段
phoenixandlinda 2004-11-12
  • 打赏
  • 举报
回复
单进程,exe 是调用dll的父进程
phoenixandlinda 2004-11-12
  • 打赏
  • 举报
回复

parent process code:
FILE *fp = NULL;
fp = fopen("c:\\log.log","w");
if(fp != NULL)
{

//Here call c functuon in the dll (testdll.dll)
int nTest = 10;
char pStr[] = "Now,I am run in the testdll";
PointAndInt TestStruct;
TestStruct.nData = 100;
ZeroMemory(&TestStruct.pStr,256);
memcpy(TestStruct.pStr,pStr,strlen(pStr));
testdll(fp,nTest,&TestStruct);

}

--------------------------------------------------------------------------------------
dll code:
void testdll(FILE* fp,int nTest,PPointAndInt pArg)
{
int nTemp = nTest;
char strTemp[256];
printf("This is a test data from argument: %d\n",nTemp);
printf("This is a string in the struct:%s\n",pArg->pStr);
printf("This is a data in the struct:%d\n",pArg->nData);

fscanf(fp,"%s",strTemp); <------ exception
fprintf(fp,"Now,it is in testdll");//,code:%d",nTemp); <------ exception

return;
}

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧