Re: DLL function loading issue
Here is an updated version of my code with typedef and the relative errors :
// --- myclass.h
typedef LPTSTR (__stdcall *FUNCT_LocGetString)(long);
class CARDLLWrapper
{
private:
static FUNCT_LocGetString LocGetString;
static HINSTANCE m_hlibLoc;
CString GetResStr(long Index);
public:
HINSTANCE InitializeLoc(CString DLLName);
void TerminateLoc();
CString STR(long);
};
// --- myclass.cpp
HINSTANCE CARDLLWrapper::InitializeLoc(CString DLLName)
{
m_hlibLoc=LoadLibrary(DLLName);
if (m_hlibLoc != NULL)
{
(FUNCT_LocGetString)LocGetString =
(FUNCT_LocGetString)GetProcAddress(m_hlibLoc, TEXT("GetString"));
return m_hlibLoc;
}
else
{
return 0;
}
}
CString CARDLLWrapper::GetResStr(long Index)
{
CString strRes("");
if (LocGetString!=NULL)
{
strRes = this->LocGetString(Index);
}
else
{
strRes = "No such function";
}
return strRes;
}
//------------------------------------------------------------------------------
CString CARDLLWrapper::STR(long Index)
{
return (CString)(GetResStr(Index));
}
when i compile this code, i do not have any error or warning.
However, when i use this DLL wrapper class, as following i have some
mistakes :
CARDLLWrapper *dw = new CARDLLWrapper();
dw->InitializeLoc("frmwrk_lc.dll");
dw->STR(IDS_FW_MNU_FILE);
dw->TerminateLoc();
delete dw;
VC raises following errors :
CARDLLWrapper.obj : error LNK2001: unresolved external symbol "private:
static char * (__stdcall* CARDLLWrapper::LocGetString)(long)"
(?LocGetString@CARDLLWrapper@@0P6GPADJ@ZA)
CARDLLWrapper.obj : error LNK2001: unresolved external symbol "private:
static struct HINSTANCE__ * CARDLLWrapper::m_hlibLoc"
(?m_hlibLoc@CARDLLWrapper@@0PAUHINSTANCE__@@A)
it's true that they are declared as private, but public functions have
access to them... :-(
Al.
Abdo Haji-Ali wrote:
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:uXlvNeL5GHA.1200@TK2MSFTNGP02.phx.gbl...
"Abdo Haji-Ali" <ahali@inframez.org_use_com_instead> wrote in message
news:%23CQHmaL5GHA.3840@TK2MSFTNGP06.phx.gbl
LocGetString = (LPTSTR)GetProcAddress(m_hlibLoc,
TEXT("GetString"));
And why are you assigning a value to a type (LocGetString) in the
first place!! LocGetString is a function pointer "type" (notice the
typedef).
This is how LocGetString is declared:
static LPTSTR (*LocGetString)(long);
Notice an _absense_ of typedef. In fact, the word 'typedef' does not
occur anywhere in the OP's code.
Wow, it's amazing how blind I can be sometimes...
I suggest you look further into typedef.
I suggest you read the code more carefully before making your
suggestions.
Good point :p