Load DLL exported data dynamically

2019-08-03 17:45发布

问题:

Is there a version of GetProcAddress for exported data?

I would like to do something like:

Mydll.cpp:

MyDataType::MyDataType(long, wchar_t*)
{
    //Dummy code
    this->temp = 3;
}
__declspec(dllexport) MyDataType Here(50, L"random text");

MyClient.cpp:

int main(void)
{
    HINSTANCE hData = LoadLibrary("MyDll.dll");
    reinterpret_cast<MyDataType*>(GetDataAddress(hData, "Here"))->DoSomething();
}

That is, define an exported data ("Here") of UDT ("MyDataType"), and them obtain its address when the DLL is dynamically loaded. Is this possible?

回答1:

the msdn page says "Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL)." - ie it should Just Work(tm)