我去调用一个别人开发的DLL文件中的一个函数,可以加载dll,调用函数返回的指针可以找到这个函数的地址,但是返回的值一直为空,难道是dll内部的问题吗?代码如下:
typedef int ( *MSI_CallNamePipe_Me)(LPVOID , DWORD ,LPVOID , DWORD );
char inbuf[80]= "root\\wmi:Q:MSI_CPU:CPU:1";
char outbuf[800];
int nData = 0;
HINSTANCE hLibrary = NULL;
MSI_CallNamePipe_Me pMsiWmiAcpi = NULL;hLibrary= LoadLibrary(TEXT("MSIWmiAcpi.dll"));
if(hLibrary!=NULL)
{
pMsiWmiAcpi = (MSI_CallNamePipe_Me)GetProcAddress(hLibrary,"?MSI_CallNamePipe@@YAHPAXK0K@Z");
if(pMsiWmiAcpi)
{
int nflag = 0;
if((nflag = pMsiWmiAcpi(inbuf,sizeof(inbuf),outbuf,sizeof(outbuf)))!= 0)//nflag 一直返回为空???
{
g_byCPUTemp = (BYTE)atoi(outbuf);
SetDlgItemText(hWnd,IDS_CPU_TEMP,outbuf);
}
else
{
sprintf_s(szTemp,"%08X",*pMsiWmiAcpi,0);
MessageBox(0,szTemp,0,0);
MessageBox(0,"pMsiWmiAcpi return NULL!","WCPUT-Read Dll",0); }
WriteToLogFile(szFileName,g_byCPUTemp);
}
else
{
MessageBox(0,"It cann't get the address of MSI_CallNamePipe!",0,0);
}
FreeLibrary(hLibrary);
}
else
{
MessageBox(0,(LPCTSTR)"It Cann't load MSIWmiAcpi.dll",(LPCTSTR)"Load Library Error",0);
}
typedef int ( *MSI_CallNamePipe_Me)(LPVOID , DWORD ,LPVOID , DWORD );
char inbuf[80]= "root\\wmi:Q:MSI_CPU:CPU:1";
char outbuf[800];
int nData = 0;
HINSTANCE hLibrary = NULL;
MSI_CallNamePipe_Me pMsiWmiAcpi = NULL;hLibrary= LoadLibrary(TEXT("MSIWmiAcpi.dll"));
if(hLibrary!=NULL)
{
pMsiWmiAcpi = (MSI_CallNamePipe_Me)GetProcAddress(hLibrary,"?MSI_CallNamePipe@@YAHPAXK0K@Z");
if(pMsiWmiAcpi)
{
int nflag = 0;
if((nflag = pMsiWmiAcpi(inbuf,sizeof(inbuf),outbuf,sizeof(outbuf)))!= 0)//nflag 一直返回为空???
{
g_byCPUTemp = (BYTE)atoi(outbuf);
SetDlgItemText(hWnd,IDS_CPU_TEMP,outbuf);
}
else
{
sprintf_s(szTemp,"%08X",*pMsiWmiAcpi,0);
MessageBox(0,szTemp,0,0);
MessageBox(0,"pMsiWmiAcpi return NULL!","WCPUT-Read Dll",0); }
WriteToLogFile(szFileName,g_byCPUTemp);
}
else
{
MessageBox(0,"It cann't get the address of MSI_CallNamePipe!",0,0);
}
FreeLibrary(hLibrary);
}
else
{
MessageBox(0,(LPCTSTR)"It Cann't load MSIWmiAcpi.dll",(LPCTSTR)"Load Library Error",0);
}
MSI_CallNamePipe @1感觉就是你这个函数地址根本没取到