Sorry for being so dense, I guess I'm not understanding that. Maybe I just
am unclear on what you mean by "my class".
Here's a little more detail. There is a target dll that exports a class and
all its methods as CTarget. I don't want to link with the .lib file for
this dll, since each version requires a different .lib (the authors of the
dll add or alter sequence of the methods inside the dll with each new
version). So I would like to use LoadLibrary and GetProcAddress to get at
the few functions I really need.
Then I have my own class defined as CProxy. It has a placeholder method for
every method in the CTarget class. In my constructor I grab an instance of
the target class, though I'm not sure how to use it after that. Then my app
calls my LoadLib method to get the function addresses. So for example the
"fcn1" method I define in my class as:
CTarget *m_pTarget;
HMODULE m_lib;
int (*m_pFcn1) (int test);
CProxy::CProxy()
{
m_pTarget = new CProxy();
}
CProxy::LoadLib()
{
m_lib = LoadLibrary(_T("target.dll"));
m_pFcn1 = GetProcAddress(m_lib, _T("fcn1")); //I actually use a
decorated name for fcn1 from dumpbin
}
int CProxy::fcn1(int test)
{
return (*m_pFcn1) (test);
//Also tried these which fail:
return m_pFcn1(test);
return m_pFcn1(m_pTarget, test); // doesn't compile - wrong num args
}
--
Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
"Joćo Paulo Figueira [eMVP]" <joao.figueira.RemoveThis@primeworks.takethisout.pt> wrote
in message news:%23musePfLFHA.1884@TK2MSFTNGP15.phx.gbl...
> Generally you should do this by calling a function that returns an intance
> of your class. This function is a regular C exported function and works
> like a class factory of sorts. This way, your app only has to know what
> function to get for each DLL and you will have access to your classes.
>
> --
> Joćo Paulo Figueira
> Embedded MVP
> "Tim Johnson" <tjohnson.RemoveThis@high-point.com> wrote in message
> news:uutUNBeLFHA.2468@tk2msftngp13.phx.gbl...
>> I've got an evc4.0 C++ program that needs to access functions in a
>> class-library dll. This dll has several different versions, with
>> differing numbers of functions in different sequence, so I don't want to
>> rely on its various .lib files. Instead I want to use LoadLibrary and
>> get the addresses of the few functions I need that happen to live in all
>> versions of the dll.
>>
>> However, the functions I need are methods in a class. Normally I'd do
>> this:
>>
>> myApi = new CTarget;
>> myApi->fcn1();
>>
>> But when I use LoadLibrary and then GetProcAddress on just the (decorated
>> C++) method names I get a DataMisalignment first-chance exception. I'm
>> thinking it's because I can't really just invoke the class methods
>> directly like that. I think I need to somehow:
>>
>> a) call the constructor first as though it's a regular method, and
>> b) pass the equivalent of the "this" pointer as a first argument to every
>> method of the class I invoke.
>>
>> Can anyone shed some light on how to do these things?
>>
>> --
>>
>> Tim Johnson
>> High Point Software, Inc.
>> www.high-point.com
>> (503) 312-8625
>>
>>
>>
>
>