C# C++ C++ CLI类的封装
我正在尝试从C调用一些Windows basic函数,特别是一个。 从我也想学习C++/CLI语言的那一刻起,我就写下了以下代码:C# C++ C++ CLI类的封装,c#,c++,C#,C++,我正在尝试从C调用一些Windows basic函数,特别是一个。 从我也想学习C++/CLI语言的那一刻起,我就写下了以下代码: #pragma once #include <string> #include <Windows.h> using namespace System; namespace InformazioniSchermo { public class Native_InformazioniDaSistema { pub
#pragma once
#include <string>
#include <Windows.h>
using namespace System;
namespace InformazioniSchermo {
public class Native_InformazioniDaSistema
{
public:
int m_nAltezzaPannello;
int m_nLarghezzaPannello;
Native_InformazioniDaSistema(void)
{
DISPLAY_DEVICE dd;
DWORD dev = 0;
dd.cb = sizeof(dd);
EnumDisplayDevices(0, dev, &dd, 0);
m_nAltezzaPannello = 100;
m_nLarghezzaPannello = 100;
}
};
public ref class InformazioniDaSistema
{
public:
InformazioniDaSistema();
~InformazioniDaSistema();
public:
int m_nHeight;
int m_nWidth;
};
InformazioniDaSistema::InformazioniDaSistema()
{
Native_InformazioniDaSistema foo;
m_nHeight = foo.m_nAltezzaPannello;
m_nWidth = foo.m_nLarghezzaPannello;
}
InformazioniDaSistema::~InformazioniDaSistema()
{
}
}
我哪里做错了?您需要针对user32.lib链接EnumDisplayDevices函数库,您将在链接到的MSDN页面中看到这一点
您可以通过转到project properties->Linker->Input并将user32.lib添加到附加依赖项列表来完成此操作
我注意到C++默认的VisualStudio项目设置不包括普通的Windows API库,默认的C++项目有Kaln33LIB,USER 32.LIB,shell32.lib和其他已添加到新项目中项目的库依赖项中,因此如果您正在使用这些库,则必须自己添加它们。
您需要针对user32.lib链接EnumDisplayDevices函数库,如链接到的MSDN页面所示 error LNK2028: ... (?EnumDisplayDevicesW@@$$J216YGHPB_WKPAU_DISPLAY_DEVICEW@@K@Z) ...
您可以通过转到project properties->Linker->Input并将user32.lib添加到附加依赖项列表来完成此操作
我注意到C++默认的VisualStudio项目设置不包括普通的Windows API库,默认的C++项目有内核32.LIB、USER 32.LIB、SHIL32.LIB和其他在新项目中添加到项目库依赖项中的东西,所以如果使用它们,你必须自己添加这些库。
error LNK2028: ... (?EnumDisplayDevicesW@@$$J216YGHPB_WKPAU_DISPLAY_DEVICEW@@K@Z) ...
这是链接器正在查找的名称。这不是它的名字,它是C函数,没有C++名字的修饰。很不清楚你是怎么做到的,尤其是因为你混淆了你的内容。但唯一合理的猜测是您自己声明了这个函数,而不是在SDK头中使用它的声明
永远不要那样做。而是使用:
#include <Windows.h>
#pragma comment(lib, "user32.lib")
使用pragma很有帮助,所以您不会忘记链接到user32
这是链接器正在查找的名称。这不是它的名字,它是C函数,没有C++名字的修饰。很不清楚你是怎么做到的,尤其是因为你混淆了你的内容。但唯一合理的猜测是您自己声明了这个函数,而不是在SDK头中使用它的声明
永远不要那样做。而是使用:
#include <Windows.h>
#pragma comment(lib, "user32.lib")
使用pragma很有帮助,所以您不会忘记链接到user32