0
#include "windows.h"
#include "stdafx.h"
#include "Winuser.h"

namespace clr {

    public ref class Class1
    {
    private:
    public:
        Class1()
        {
        }
        ~Class1()
        {
        }
        void   getcount(int number, char* out1, char* out2, int* out3)
        {
            DISPLAY_DEVICE mydevice;
            mydevice.cb = sizeof(DISPLAY_DEVICE);

            while (EnumDisplayDevices(NULL,0, &mydevice, EDD_GET_DEVICE_INTERFACE_NAME))
            {
            }
        };

        // TODO:  在此处添加此类的方法。
    };
}
严重性 代码  说明  项目  文件  行   禁止显示状态
错误  LNK2028 无法解析的标记(0A00002F) "extern "C" int __stdcall EnumDisplayDevicesA(char const *,unsigned long,struct _DISPLAY_DEVICEA *,unsigned long)" (?EnumDisplayDevicesA@@$$J216YGHPBDKPAU_DISPLAY_DEVICEA@@K@Z),该标记在函数 "public: void __clrcall clr::Class1::getcount(int,char *,char *,int *)" (?getcount@Class1@clr@@$$FQ$AAMXHPAD0PAH@Z) 中被引用  clr C:\Users\bamboo\Documents\Visual Studio 2015\Projects\clr\clr\clr.obj   1   

严重性 代码  说明  项目  文件  行   禁止显示状态
错误  LNK2019 无法解析的外部符号 "extern "C" int __stdcall EnumDisplayDevicesA(char const *,unsigned long,struct _DISPLAY_DEVICEA *,unsigned long)" (?EnumDisplayDevicesA@@$$J216YGHPBDKPAU_DISPLAY_DEVICEA@@K@Z),该符号在函数 "public: void __clrcall clr::Class1::getcount(int,char *,char *,int *)" (?getcount@Class1@clr@@$$FQ$AAMXHPAD0PAH@Z) 中被引用  clr C:\Users\bamboo\Documents\Visual Studio 2015\Projects\clr\clr\clr.obj   1   

严重性 代码  说明  项目  文件  行   禁止显示状态
错误  LNK1120 2 个无法解析的外部命令    clr C:\Users\bamboo\Documents\Visual Studio 2015\Projects\clr\Debug\clr.dll 1   
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – StoryTeller - Unslander Monica Aug 13 '17 at 07:49
  • Documentation is clear enough (https://msdn.microsoft.com/en-us/library/windows/desktop/dd162609(v=vs.85).aspx): link with user32.lib – stijn Aug 13 '17 at 08:30
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – stijn Aug 13 '17 at 08:30
  • i use this function in a normsl c++ project it,s ok, but when i use it in a c++ CLR project ,error pop up, is there any difference? – huaicheng pan Aug 13 '17 at 08:49
  • my purpose is to use winapi in c+ and make an dll use c++ CLR so that i can use winapi in a c# project by add reference not dllimport – huaicheng pan Aug 13 '17 at 08:57
  • @stijn I have use it in a normal c++ project just include the header file,it works ok,you mean i need to add a link to the lib file in an c++ CLR project so that it can work?thanks – huaicheng pan Aug 13 '17 at 09:02
  • yes as I said, it seems CLR projects do not automatically link with user32.lib so you have to add it as additional linker input – stijn Aug 13 '17 at 10:01
  • @stijn your thought is correct,afrer link the lib file,it,s ok. thanks – huaicheng pan Aug 13 '17 at 10:44

0 Answers0