Load DLL exported data dynamically

2019-08-03 17:29发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-03 18:01

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)

查看更多
登录 后发表回答