提问人:lechrizzle 提问时间:10/21/2020 更新时间:10/21/2020 访问量:130
从 C++ 运行时加载的 DLL 访问结构的成员
Accessing members of a structure from a DLL, loaded at runtime in C++
问:
我有以下问题:在运行时,我加载了 Matlab 生成的 Simulink 模型的 DLL,其中包含模型输出和输入的结构以及一些方法。
生成的结构和方法示例(模型的名称为“Test_Scalar”):
typedef struct {
real_T Input_1; /* '<Root>/Input_1' */
real_T Input_2; /* '<Root>/Input_2' */
} ExtU_Test_Scalar_T;
/* External outputs (root outports fed by signals with default storage) */
typedef struct {
real_T Output; /* '<Root>/Output' */
} ExtY_Test_Scalar_T;
/* Real-time Model Data Structure */
struct tag_RTM_Test_Scalar_T {
const char_T * volatile errorStatus;
};
/* External inputs (root inport signals with default storage) */
extern ExtU_Test_Scalar_T Test_Scalar_*;
/* External outputs (root outports fed by signals with default storage) */
extern ExtY_Test_Scalar_T Test_Scalar_Y;
/* Model entry point functions */
extern void Test_Scalar_initialize(void);
extern void Test_Scalar_step(void);
extern void Test_Scalar_terminate(void);
在我的 C++ 程序中,我可以加载和执行 init 函数,并且我还获得了指向结构的指针。 但是,我不知道如何访问结构的成员。这里有人有想法吗?
int main() {
HMODULE hModule = LoadLibraryA("C:\\....\\Test_Scalar_win64.dll");
assert(hModule);
FARPROC initialize = GetProcAddress(hModule, "Test_Scalar_initialize");
assert(initialize);
initialize();
FARPROC inputs= GetProcAddress(hModule, "Test_Scalar_U");
assert(inputs);
//accessing members of input struct here
}
诚挚的问候
克里斯
答: 暂无答案
评论
ExtU_Test_Scalar_T*