为了测试,用C,C++分别做了两个同功能Non-MFC dll,都是接收父进程传入的FILE 指针来读写文件。但出错: Unhandled exception in test.exe(ntdll.dll):0xc0000005: Access Violation.
奇怪啊,不懂请各位指点一下。
OS: winxp Home 
Compiler: VC6.0

解决方案 »

  1.   

    会不会是 多个进程对同一个文件操作的问题??...怎么又有EXE了?
      

  2.   


    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;
    }
      

  3.   

    单进程,exe 是调用dll的父进程
      

  4.   

    def :
    LIBRARY TESTDLL
    DESCRIPTION This is a test dll which a C++ program call a C procdure
    EXPORTS
    testdll;
      

  5.   

    MSVCRT.dll 的版本问题!
    exe 和 dll 链接的 C 运行库的不同版本。
    用 depends 查一下
      

  6.   

    查看了一下MSVCRT.dll  都是6.00.8168.0,ExE 是 C++写的,dll是C写的。
      

  7.   

    fp = fopen("c:\\log.log","w"); // only w
    ……
    fscanf(fp,"%s",strTemp); // fp 没有以读方式打开,只能对它写。因此出错
      

  8.   

    笔误,fscanf(fp,"%s",strTemp); 应该注释掉。
    dll 中不读文件,只是写文件也会出错。
      

  9.   

    另外,以只写方式打开的文件,如果用fscanf去做读操作,只是一般的失败(返回-1),不会出现“Unhandled exception in test.exe(ntdll.dll):0xc0000005: Access Violation.”这种致命错误。