下面的函数,我可以链接到xx.dll文件,但是就是在函数GetProcAddress那里获取到的指针为空,是怎么回事?xx.dll里面存在这样的函数:
int Sub(int a,int b ).{
CString str;
int x;
HINSTANCE dllHandle = NULL;
FindArtistType FindArtistPtr = NULL; dllHandle = LoadLibrary("xx.dll");
if (NULL != dllHandle)
{
FindArtistPtr = (FindArtistType)GetProcAddress
(dllHandle,"Sub");
if (NULL != FindArtistPtr)
{
x = FindArtistPtr(1,2);
str = x + '0';
AfxMessageBox( str,NULL,NULL );
}
else
{
AfxMessageBox("Can't find funtion",NULL,NULL);
} //Free the library:
FreeLibrary(dllHandle); }
else
{
AfxMessageBox("can't open dll file",NULL,NULL);
}
int Sub(int a,int b ).{
CString str;
int x;
HINSTANCE dllHandle = NULL;
FindArtistType FindArtistPtr = NULL; dllHandle = LoadLibrary("xx.dll");
if (NULL != dllHandle)
{
FindArtistPtr = (FindArtistType)GetProcAddress
(dllHandle,"Sub");
if (NULL != FindArtistPtr)
{
x = FindArtistPtr(1,2);
str = x + '0';
AfxMessageBox( str,NULL,NULL );
}
else
{
AfxMessageBox("Can't find funtion",NULL,NULL);
} //Free the library:
FreeLibrary(dllHandle); }
else
{
AfxMessageBox("can't open dll file",NULL,NULL);
}
百尺竿头,卧薪尝胆
是因为我写的那个Dll文件的 .def 文件里面没有声明EXPORTS的相应函数。