LNK2019 无法解析的外部符号 WinMain,该符号在函数 "int __cdecl __scrt_common_main_seh(void)"

huaxiasky huaxiasky 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#define INITGUID
#include <windows.h>
#include <GPEdit.h>
#include <winnt.h>

using namespace std;
HRESULT ModifyUserPolicyForPreventAccessToCmdPrompt(BSTR bGPOPath, int iMode, DWORD lData)
{
HRESULT hr = S_OK;
//
// Use IGroupPolicyObject to retrieve and modify the registry settings.
// for the GPO represented by the gpoInfo.lpDsPath
//
IGroupPolicyObject* p = NULL;
hr = CoCreateInstance(CLSID_GroupPolicyObject,NULL,
CLSCTX_INPROC_SERVER,
IID_IGroupPolicyObject,
(LPVOID*)&p);
if (SUCCEEDED(hr))
{
//
// The GPO value we want to modify is the
//
// User Configuration
// +> Policies
// +>Administrative Templates
// +->System
// +->Prevent access to the command prompt
//
DWORD dwSection = GPO_SECTION_USER;
HKEY hGPOSectionKey = NULL;
DWORD dwData;
HKEY hSettingKey;
LSTATUS rStatus;
hr = 0;
//
//Open the GPO and load its registy values for both: Machine and user
//
hr = p->OpenDSGPO(bGPOPath, GPO_OPEN_LOAD_REGISTRY);
//
// Request the user Registy hive for the GPO
//
hr = p->GetRegistryKey(dwSection, &hGPOSectionKey);
//
// Determine if you want to set it to Not Congigure,
// Enabled or Disabled for the GPO itself.
//
// The second call, RequestSetting will provide the "Yes" or "No"
// value for setting
// the policy as shown by the GPO Editor
//
// iMode
// 0=Not Configured, 1=Enabled, 2=Disabled
//
switch (iMode)
{
case 0:
//
// We do not want to configure the GPO, but we don't want to
// affect other GPOs on the same key,
// so just delete values associated with this
// particular GPO setting.
//
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\DisableCMD"
);
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\**del.DisableCMD"
);
break;
case 1:
{
//
// To enable the policy, the DisableCMD value must
// exist and the **del.DisableCMD value must not.
//
// lData:
//
// Check to see if the key for this policy exists.
// If if it does, retrieve a handle
// If not, create it.
//
if (RegOpenKeyEx(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System", 0,
KEY_WRITE, &hSettingKey) != ERROR_SUCCESS)
{
rStatus = RegCreateKeyEx(
hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hSettingKey,
NULL);
}
//
// Set the value DisableCMD and allow, disallow
// script launching of CMD
//
rStatus = RegSetValueEx(hSettingKey, L"DisableCMD",
NULL, REG_DWORD, (BYTE *)(&lData),
sizeof(DWORD));
//
// Remove the not configured value indicator from the hive.
// It may not exist, so the RegDeleteValue may return
// and error, this can be ignored.
//
rStatus = RegDeleteValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System\\**del.DisableCMD"
);
rStatus = RegCloseKey(hSettingKey);
break;
}
case 2:
{
//
// Disable the policy.
// must remove the DisableCMD value and add the
// **del.DisableCMD value.
//
// Same stesp as before, check to see if the key for this
// policy exists,
// if not, create it.
//
BOOL bCreate = FALSE;
if (RegOpenKeyEx(hGPOSectionKey, L"Software\\Policies\\Microsoft\\Windows\\System", 0, KEY_WRITE, &hSettingKey) != ERROR_SUCCESS)
{
rStatus = RegCreateKeyEx(
hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hSettingKey,
NULL);
bCreate = TRUE;
}
DWORD dwType = 0;
DWORD cbType = sizeof(dwData);
if (!bCreate)
{
//
// If we did not create the key, then our value
// *may* exist.
// try to read it. If we succeed, write that value back
// to **del.DisableCMD
// if not, then set **del.DisableCMD to 0
//
rStatus = RegGetValue(hGPOSectionKey,
L"Software\\Policies\\Microsoft\\Windows\\System", L"DisableCMD", RRF_RT_ANY, &dwType, (BYTE *)(&dwData), &cbType);
if (rStatus != ERROR_SUCCESS) dwData = 0;
else RegDeleteValue(hSettingKey, L"DisableCMD");
rStatus = RegSetValueEx(hSettingKey, L"**del.DisableCMD", NULL, REG_DWORD, (BYTE *)(&dwData), sizeof(DWORD));
}
else
{
//
// The key was created, just set the **del.DisableCMD
// value to 0
//
dwData = 0;
rStatus = RegSetValueEx(hSettingKey, L"**del.DisableCMD", NULL, REG_DWORD, (BYTE *)(&dwData), sizeof(DWORD));
}
rStatus = RegCloseKey(hSettingKey);
}
}

GUID RegistryId = REGISTRY_EXTENSION_GUID;
GUID ThisAdminToolGuid =
/*{ CLSID_PolicySnapinUser/* */
{
0x0F6B957E,
0x509E,
0x11D1,
{ 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
};
rStatus = RegCloseKey(hGPOSectionKey);
//
// Write the GPO back to the directory
//
hr = p->Save(
FALSE,
TRUE,
®istryId,
&ThisAdminToolGuid);

hr = p->Release();
}
return hr;
}

可以编译


但是一调试就出问题



运行环境 我本机的操作系统是win7 x64


请问这个要怎么解决呢?
...全文

相关推荐

VS2022+Qt5.15.2+OpenCV4.8.0图像处理工程落地实践

图像处理软件开发常面临环境配置混乱、跨模块兼容性差、部署即崩溃等工程化瓶颈。其本质是C++构建体系(编译器/标准库)、GUI框架(Qt ABI)与计算机视觉库(OpenCV二进制接口)三者间的耦合失配。掌握VS2022对C++17及std::filesystem的稳定支持、Qt5.15.2作为LTS版本与OpenCV4.x预编译包的ABI兼容性,是构建可维护图像应用的技术基石。该组合在工业检测、医疗影像和教学平台等真实场景中验证了编译确定性、运行稳定性与功能可扩展性。本文聚焦VS2022环境下Qt5.15.

天为我蓝

Windows 下用 CMake 生成 DLL:导出符号、运行库与跨语言调用

动态链接库(DLL)是 Windows PE 格式中的运行时组件,通过导出表暴露函数,由宿主进程按需加载,从而实现代码复用、独立升级和跨语言集成。其原理是链接期依赖导入库、运行期解析依赖并定位符号,一旦依赖缺失、位数不匹配或运行库冲突,就可能触发 WinError 1114 等加载失败。CMake 以声明式脚本屏蔽工程文件差异,支持 MSVC、MinGW、Ninja 等工具链,便于稳定生成 Windows DLL,并统一管理导出宏、安装与 find_package 规则。此类方案常用于算法模块解耦、C/C+

李弯湾

curl 64位二进制的本质:ABI兼容性与定制化构建指南

curl作为最广泛使用的C语言网络库,其‘64位二进制’常被误认为仅指x86_64架构可执行文件。实际上,它本质是受架构(x86_64/ARM64)、ABI(调用约定、CRT绑定、异常模型)和功能栈(OpenSSL/BoringSSL、zlib、HTTP/2)三重约束的编译产物。脱离构建环境直接复用预编译bin极易引发0xC000007B、LNK4098或SSL握手失败等典型故障。真正可靠的curl 64位bin必须基于目标平台工具链(如MSVC v142)、匹配版本依赖(OpenSSL 3.0.13+)及

weixin_30697239

Visual Studio C++ AddressSanitizer集成:原理、配置与调试实战

内存错误是C++开发中常见且难以定位的问题,如数组越界、使用已释放内存等。动态分析工具通过运行时检测技术,以较低性能开销捕获此类错误,其核心原理通常涉及内存布局监控与访问插桩。AddressSanitizer(ASan)作为此类工具的代表,通过编译时插桩和影子内存机制,高效检测地址错误,显著提升软件稳定性与安全性。在工程实践中,Visual Studio深度集成了ASan技术,为Windows平台的C++开发者提供了可视化调试支持。本文聚焦于AddressSanitizer在Visual Studio中的实

weixin_30333885

C++工程实践:从VC++6.0实验体系理解内存模型与面向对象本质

C++是一门以内存模型为根基、以抽象机制为桥梁的系统级编程语言。其核心原理在于指针与引用对内存地址的直接操控、类封装对数据与行为的统一组织、虚函数通过虚表实现运行时多态。这些机制共同构成现代软件架构的底层支撑,广泛应用于嵌入式开发、操作系统模块、高性能服务中间件等场景。掌握VC++6.0这一经典环境下的编译链接流程、堆栈内存布局、流操作符语义及结构体/类的内存对齐规则,能有效夯实对C++对象生命周期、资源管理责任和接口契约设计的理解。本文围绕高校《面向对象程序设计》实验体系,聚焦指针、引用、类、虚函数等热词

脑袋被门夹得好痛
评论 6
收藏 已收藏
分享
返回顶部
huaxiasky
VC/MFC 16,550 成员 421,606 内容