Re: DLL function loading issue
- From: --== Alain ==-- <nospam@xxxxxxxxxxx>
- Date: Sat, 30 Sep 2006 20:21:59 +0200
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@xxxxxxxx> wrote in message.
news:uXlvNeL5GHA.1200@xxxxxxxxxxxxxxxxxxxxxxx
"Abdo Haji-Ali" <ahali@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in messageWow, it's amazing how blind I can be sometimes...
news:%23CQHmaL5GHA.3840@xxxxxxxxxxxxxxxxxxxx
This is how LocGetString is declared:LocGetString = (LPTSTR)GetProcAddress(m_hlibLoc,And why are you assigning a value to a type (LocGetString) in the
TEXT("GetString"));
first place!! LocGetString is a function pointer "type" (notice the
typedef).
static LPTSTR (*LocGetString)(long);
Notice an _absense_ of typedef. In fact, the word 'typedef' does not
occur anywhere in the OP's code.
Good point :pI suggest you look further into typedef.I suggest you read the code more carefully before making your
suggestions.
- Follow-Ups:
- Re: DLL function loading issue
- From: Abdo Haji-Ali
- Re: DLL function loading issue
- References:
- DLL function loading issue
- From: --== Alain ==--
- Re: DLL function loading issue
- From: Abdo Haji-Ali
- Re: DLL function loading issue
- From: Igor Tandetnik
- Re: DLL function loading issue
- From: Abdo Haji-Ali
- DLL function loading issue
- Prev by Date: Re: DLL function loading issue
- Next by Date: Re: DLL function loading issue
- Previous by thread: Re: DLL function loading issue
- Next by thread: Re: DLL function loading issue
- Index(es):
Relevant Pages
|