【问题标题】:How to create multiple typedefs of similar format?如何创建多个相似格式的 typedef?
【发布时间】:2021-09-22 20:50:19
【问题描述】:

我正在动态加载一个包含很多方法的 DLL,并且我有一个处理多个 DLL 方法的 typedef:

typedef int32_t (__cdecl *MYPROC)(const char *url, const char *options, const char *body, int32_t length); // GET, POST, HTTP test

每当我创建另一个 typedef 来处理单独的函数时:

typedef int32_t (__cdecl *MYPROC)(const char *json_blob, const char *response, int32_t length); // ParseVal

我遇到了关于声明冲突的错误:

conflicting declaration 'typedef int32_t (__attribute__((cdecl)) * MYPROC)(const char*, const char*, int32_t)'
 typedef int32_t (__cdecl *MYPROC)(const char *json_blob, const char *response, int32_t length); // ParseVal
                                                                                              ^
note: previous declaration as 'typedef int32_t (__attribute__((cdecl)) * MYPROC)(const char*, const char*, const char*, int32_t)'
 typedef int32_t (__cdecl *MYPROC)(const char *url, const char *options, const char *body, int32_t length); // GET, POST, HTTP test

我不确定这是否是处理 DLL 方法的正确方法,因此我愿意接受建议。我是 C++ 的这个特性的新手,并且很长一段时间没有使用过这种语言,如果这很明显,请道歉。

【问题讨论】:

  • 你为什么将两个类型别名都命名为MYPROC?这与尝试 typedef int T; typedef float T; 相同 - 显然 type T 不能声明为引用两种不同的类型。
  • 啊。我现在明白了。我将其视为 MYPROC 是系统定义的类型而不是名称..这将破坏使用 typedef 的全部目的。谢谢你的澄清。

标签: c++ winapi dll typedef


【解决方案1】:

StoryTeller - Unslander Monica 回答。我在想 MYPROC 是 WinAPI 定义的,而不是出于某种原因的名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 2017-12-16
    相关资源
    最近更新 更多