Re: DLL function loading issue

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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 message
news:%23CQHmaL5GHA.3840@xxxxxxxxxxxxxxxxxxxx
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

.



Relevant Pages

  • Re: assembly functions ans c++ classes
    ... typedef structnum; ... // but it is not helpfull that num is accessed from extern ... fucntions and operators that use f0, ...
    (alt.lang.asm)
  • Re: Templates and typedef
    ... > typedef T Type; ... The main problem is that you have omitted the semicolon after 'a'. ... probably should write a const accessor method in addition to the ...
    (comp.lang.cpp)
  • Extending stl::list???
    ... What i invision is a large object that contains my iterators, ... iterators and any mutating methods that could produce memory error?... ... typedef list::iterator SI; ... class SafeList: private S { ...
    (comp.lang.cpp)
  • Extending stl::list???
    ... What i invision is a large object that contains my iterators, ... iterators and any mutating methods that could produce memory error?... ... typedef list::iterator SI; ... class SafeList: private S { ...
    (alt.comp.lang.learn.c-cpp)
  • Re: CString ... are they nuts?
    ... CString m_scTest; ... inline void TestSet: m_scTest; ... It is better to initialize everything you can outside ...
    (microsoft.public.vc.mfc)