gpt4 book ai didi

c++ - 对 _imp__CryptProtectData@28 的 undefined reference

转载 作者:可可西里 更新时间:2023-11-01 10:54:46 28 4
gpt4 key购买 nike

我正在尝试使用 windows.h 和 wincrypt.h 库构建一个简单的应用程序以加密一些字符串。

当我调用函数 CryptProtectData(&input, NULL, NULL, NULL, NULL, 0, &output); 时出现错误:

error: undefined reference to `_imp__CryptProtectData@28'

我在网上搜索了很多,但没有找到多少。我还意识到 Chromium 浏览器使用与我的类似的代码来加密和解密其登录,我并没有做不同的事情。

我正在使用 QtCreator IDE 来编译我的代码。

我的一些代码:

  std::string plaintext="Some plain text";
DATA_BLOB input;
input.pbData = const_cast<BYTE*>(
reinterpret_cast<const BYTE*>(plaintext.data()));
input.cbData = static_cast<DWORD>(plaintext.length());

DATA_BLOB output;
BOOL result = CryptProtectData(&input, NULL, NULL, NULL, NULL,
0, &output);

编辑:忘记提及我已经包括了 windows.h 和 wincrypt.h 库,当然。

最佳答案

这是一个链接器错误,因为您没有提供 CryptProtectData 函数所需的库文件。您需要将 Crypt32 库传递给链接器。

此信息包含在 MSDN documentation 中为功能。向下滚动到主题底部以查看信息。

作为一般规则,为了使用 API 函数,您需要查看函数文档中的要求部分。其中列出了以下信息:

  • 支持的最低 Windows 版本。
  • 您需要包含的头文件。
  • 您需要传递给链接器的库文件。

关于c++ - 对 _imp__CryptProtectData@28 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15614239/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com