MFC调用FORTRAN动态链接库
最近开发一个软件,要求有可视化界面,于是想到用MFC,而源程序用FORTRAN写好了,便将fortran代码打包为dll文件,供MFC调用,可是出现了如下问题:在我的编译的电脑上整个程序调用fortran的dll没问题,但是一将程序换到另外一个电脑上就始终出现加载dll文件失败的提示,导致程序的部分功能也就失效了,这是什么原因了,以下是我调用的代码:
FORTRAN接口:
SUBROUTINE MONOPROPELLANT(molC,molH,molO,molN,Propellantname,NameLength,PropellantDensity,PropellantHf,Tc,Te,Isp,Cm,MolecularAvgMass,Qp,xc,xe)
!DEC$ ATTRIBUTES DLLEXPORT::MONOPROPELLANT
!DEC$ ATTRIBUTES REFERENCE::molC,molH,molO,molN,Propellantname,PropellantDensity,PropellantHf,Tc,Te,Isp,Cm,MolecularAvgMass,Qp,xc,xe
USE Constant
USE thermo
....
END SUBROUTINE MONOPROPELLANT
MFC中的C++代码:
void CMonopropellant::OnBnClickedOk()
{
UpdateData(TRUE);
typedef void ( _cdecl* wndProc)(double& ,double& ,double& ,double& ,
char* ,int& ,double& ,double& ,
double& ,double& ,double& ,double& ,double& ,double&,
double[],double[]);
HINSTANCE hIns;
hIns = LoadLibraryEx(_T("Monopropellant_dll.dll"),NULL,NULL);
if(!hIns)
{
MessageBox(L"加载动态链接库:Monopropellant_dll.dll失败",L"ERROR",MB_OK);
return;
}
wndProc propellant= (wndProc)GetProcAddress(hIns,"MONOPROPELLANT");
if(!propellant)
{
MessageBox(L"加载函数失败",L"ERROR",MB_OK);
::FreeLibrary(hIns);
return;
}
CString txt=_T(".txt");
CString outputfilename;
outputfilename.Format(_T("%s %s"),propellant_name,txt);
wchar_t *p=outputfilename.GetBuffer(outputfilename.GetLength());
outputfilename.ReleaseBuffer();
int iSize;
char *pName;
iSize=WideCharToMultiByte(CP_ACP,0,p,-1,NULL,0,NULL,NULL);
pName=(char*)malloc((iSize+1));
WideCharToMultiByte(CP_ACP,0,p,-1,pName,iSize,NULL,NULL);
int len=strlen(pName);
double Tc,Te,Isp,Cm,MolecularAvgMass,Qp;
double xc[25],xe[25];
propellant(NumC,NumH,NumO,NumN,pName,len,propellant_density,propellant_Hf,Tc,Te,Isp,Cm,MolecularAvgMass,Qp,xc,xe);
::FreeLibrary(hIns);
...
}