#include Windows.h里面的DLL文件

时间:2023-01-21 15:04:57

I am trying to create a color dialog DLL inside of C++ using the ChooseColor. Although every time I build I get the issue

我正在尝试使用ChooseColor在C ++中创建一个颜色对话框DLL。虽然每次我建立我都会遇到问题

1>ChooseColorDLL.obj : error LNK2019: unresolved external symbol __imp_ChooseColorA referenced in function "void __cdecl ShowMyDialog(char *)" (?ShowMyDialog@@YAXPEAD@Z)

Here is my .cpp file inside my DLL:

这是我的DLL中的.cpp文件:

#include "stdafx.h"
#include "ChooseColorDLL.h"
#include <commdlg.h>
#include <fstream>
#include <iostream>

CHOOSECOLORDLL_API void ShowDialog(char* i)
{

    static COLORREF  colorrefCustomColours[16] = {0} ;
    CHOOSECOLOR cc;

    cc.hwndOwner = NULL;    //No Owner
    cc.hInstance = NULL;
    cc.rgbResult =    RGB(0,0,0);
    cc.lpfnHook =NULL;
    cc.Flags = CC_SOLIDCOLOR | CC_PREVENTFULLOPEN;
    cc.lpCustColors = colorrefCustomColours;
    cc.lpTemplateName = NULL;
    cc.lCustData = NULL;
    cc.lStructSize = sizeof(cc);
    // Seperate Colors
    ChooseColor(&cc);
}

ChooseColorDLL.h:

#ifdef CHOOSECOLORDLL_EXPORTS
#define CHOOSECOLORDLL_API __declspec(dllexport)
#else
#define CHOOSECOLORDLL_API __declspec(dllimport)
#endif

CHOOSECOLORDLL_API void ShowDialog(char* i);

2 个解决方案

#1


3  

I'm reasonably sure that the problem is that your build doesn't set the WINVER and _WIN32_WINNT versions are either not set, or not set correctly - see this

我有理由相信你的构建没有设置WINVER和_WIN32_WINNT版本没有设置,或者设置不正确 - 请参阅此内容

In other words, before #include <windows.h>, you should have:

换句话说,在#include 之前,您应该:

#define WINVER 0x0500
#define _WIN32_WINNT 0x0500

By default, so that apps work on "ANY" version of Windows, the windows.h only gives you functions that are available in EVERY version of windows from WinNT4 and onwards. Since this is introduced in Win2K, it isn't default. The above define gives you Win2K variants. Other values are documented here

默认情况下,以便应用程序在Windows的“任何”版本上运行,windows.h仅为您提供从WinNT4及其后的每个版本的Windows中可用的功能。由于这是在Win2K中引入的,因此它不是默认值。上面的定义为您提供了Win2K变体。其他值记录在此处

#2


1  

Look up ChooseColor in MSDN. In the "Requirements" section of that page it says you must link to ComDlg32.lib.

在MSDN中查找ChooseColor。在该页面的“要求”部分中,它表示您必须链接到ComDlg32.lib。

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646912(v=vs.85).aspx

Failing to link to the required lib typically produces the 'unresolved external symbol' error.

未能链接到所需的lib通常会产生“未解析的外部符号”错误。

#1


3  

I'm reasonably sure that the problem is that your build doesn't set the WINVER and _WIN32_WINNT versions are either not set, or not set correctly - see this

我有理由相信你的构建没有设置WINVER和_WIN32_WINNT版本没有设置,或者设置不正确 - 请参阅此内容

In other words, before #include <windows.h>, you should have:

换句话说,在#include 之前,您应该:

#define WINVER 0x0500
#define _WIN32_WINNT 0x0500

By default, so that apps work on "ANY" version of Windows, the windows.h only gives you functions that are available in EVERY version of windows from WinNT4 and onwards. Since this is introduced in Win2K, it isn't default. The above define gives you Win2K variants. Other values are documented here

默认情况下,以便应用程序在Windows的“任何”版本上运行,windows.h仅为您提供从WinNT4及其后的每个版本的Windows中可用的功能。由于这是在Win2K中引入的,因此它不是默认值。上面的定义为您提供了Win2K变体。其他值记录在此处

#2


1  

Look up ChooseColor in MSDN. In the "Requirements" section of that page it says you must link to ComDlg32.lib.

在MSDN中查找ChooseColor。在该页面的“要求”部分中,它表示您必须链接到ComDlg32.lib。

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646912(v=vs.85).aspx

Failing to link to the required lib typically produces the 'unresolved external symbol' error.

未能链接到所需的lib通常会产生“未解析的外部符号”错误。