C ++ / CLI如何将整数指针传递给C ++ API(C++/CLI how to pass integer pointer to C++ API)

看起来我在这里犯了一个基本错误。 我有一个3方C ++库(test.dll),其中有一个API定义如下。 我通过加载库,获取API并调用来调用此APi。 我是C ++ CLI的新手,任何解决问题的指针都会有所帮助。 提前致谢。

第三部分库导出API FUNCTION_EXPORT void STDCALL GetVersion(UINT16&version); typedef void(STDCALL * GETVERSION)(UINT16);

我需要从C ++ Cli调用它

头文件

MyTest.h namespace MyTest { public ref class TestClass { public: HMODULE module; String^ version; void TestMethod() }; }

Cpp文件

MyTest.cpp namespace MyTest { TestClass::TestMethod() { this->module = LoadLibrary(engineDllPath); if (!this->module) { return String::Format("LoadLibrary failed"); }; // Get engine version GETVERSION GetVersionApi = (GETVERSION)GetProcAddress(module, "GetVersion"); if (!GetVersionApi) { return; } UINT16 major; GetVersionApi(&uiMajor); } }

编译错误错误C2664:'void(UINT16&)':无法将参数1从'UINT16 *'转换为'UINT16&'

代码片段是为了让我知道我在尝试什么。 主要问题是UINT16专业; GetVersionApi(&uiMajor);

什么是正确的称呼方式。 请帮忙。

Looks like I am doing a basic mistake here. I have a 3 party C++ library(test.dll) in which there is a API defined as follows. And I am invoking this APi by loading the library, getting the API and invoke. I am new to C++ CLI, any pointers to solve the issue will be helpful. Thanks in advance.

3rd part library exported API FUNCTION_EXPORT void STDCALL GetVersion(UINT16& version); typedef void (STDCALL *GETVERSION)(UINT16);

I need to call it from C++ Cli

Header file

MyTest.h namespace MyTest { public ref class TestClass { public: HMODULE module; String^ version; void TestMethod() }; }

Cpp file

MyTest.cpp namespace MyTest { TestClass::TestMethod() { this->module = LoadLibrary(engineDllPath); if (!this->module) { return String::Format("LoadLibrary failed"); }; // Get engine version GETVERSION GetVersionApi = (GETVERSION)GetProcAddress(module, "GetVersion"); if (!GetVersionApi) { return; } UINT16 major; GetVersionApi(&uiMajor); } }

Getting compilation error error C2664: 'void (UINT16 &)' : cannot convert parameter 1 from 'UINT16 *' to 'UINT16 &'

Code snippet is to give an idea what I am trying. The main issue is here UINT16 major; GetVersionApi(&uiMajor);

what will be the correct way of calling it. Please help.

最满意答案

GetVersion(UINT16& version);

那不是整数指针,这是一个整数引用。 您无需键入任何额外字符即可传递引用。

GetVersionApi(uiMajor); // ^ no "&" GetVersion(UINT16& version);

That's not an integer pointer, that's an integer reference. You don't need to type any extra characters to pass a reference.

GetVersionApi(uiMajor); // ^ no "&"

更多推荐