
Linking error in calling a function exporting from a DLL
I take it that 'GetStructString' is a function in the DLL you're
attempting to load dynamically?
If so then you need to locate the 'GetStructString' function in the
DLL using the GetProcAddress() function. Then you call it using the
returned pointer.
For example (with error checking omitted):
typedef int (*PFNGETSTRUCSTRING)(int, int, char*);
int main()
{
int nRet;
char szTemp[100];
HINSTANCE hInstDll;
hInstDll = ::LoadLibrary("xxxxx.dll");
FARPROC fp = ::GetProcAddress(hInstDll, "GetStructString");
PFNGETSTRUCTSTRING pfn = (PFNGETSTRUCTSTRING)fp;
(*fp)(0, 0,strTemp);
return 0;
}
Note that if the 'GetStructString' function name is mangled in the DLL
(e.g. not exported using extern "C") then you'll have to adjust the
string name of the function you pass to GetProcAddress appropriately.
Joe O'
Quote:
> Dear all,
> I have some code as following:
> ===================================================
> #include <windows.h>
> #include <stdio.h>
> #include <winbase.h>
> __declspec(dllimport) int GetStructString(int,int,char *);
> void main()
> {
> int nRet;
> char strTemp[100];
> HINSTANCE hInstDll;
> hInstDll=LoadLibrary("xxxxx.dll");
> nRet=GetStructString(0,0,strTemp);
> if(nRet==1)
> printf("Retrieved data:%s",strTemp);
> if(hInstDll!=NULL) FreeLibrary(hInstDll);
> }
> ===================================================
> When compiling, something wrong....
> --------------------Configuration: SMBiosList - Win32
Release-----------
> Linking...
> SMBiosList.obj : error LNK2001: unresolved external symbol
> __imp__GetStructString
> Release/SMBiosList.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
> SMBiosList.exe - 2 error(s), 0 warning(s)
> Any idea?
> Thanks in advance.
> Regards,
> Eric Hsu
> Sent via Deja.com http://www.deja.com/
> Before you buy.