//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; }
单进程,exe 是调用dll的父进程
def : LIBRARY TESTDLL DESCRIPTION This is a test dll which a C++ program call a C procdure EXPORTS testdll;
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;
}
LIBRARY TESTDLL
DESCRIPTION This is a test dll which a C++ program call a C procdure
EXPORTS
testdll;
exe 和 dll 链接的 C 运行库的不同版本。
用 depends 查一下
……
fscanf(fp,"%s",strTemp); // fp 没有以读方式打开,只能对它写。因此出错
dll 中不读文件,只是写文件也会出错。