我有一个 VC++ HttpPOST 方法,它适用于 80 和 443 端口。(在 google.com 等热门网站上)
现在,当我连接到具有 cgi 脚本的安全主机(172.17.9.93)时,现在当我使用fiddler连接时,我收到证书无效的警告,接受警告后我就可以连接。

我必须在 C++ 中执行相同的行为,即使用下面的 flags 和函数 HttpOpenRequest() 中的一些组合来忽略证书,SECURITY_FLAG_IGNORE_UNKNOWN_CA但它INTERNET_FLAG_IGNORE_CERT_CN_INVALID失败并给出以下输出。
C++ 控制台输出
172.17.9.93 : 443 data base-bin/hello.cgi
Error 12045 has occurred while HttpSendRequest
INVALID CA request received (12045)
Run Code Online (Sandbox Code Playgroud)
源代码 VC++
#define _WIN32_WINNT 0x600
#include <windows.h>
#include <stdio.h>
#include <string>
#include <wininet.h>
#pragma comment(lib,"Wininet.lib")
using namespace std;
int doPost(std::string send, std::string &receive, LPCTSTR host, int port, LPCTSTR url)
{
char szData[1024];
int winret = …Run Code Online (Sandbox Code Playgroud) 我正在尝试定义函数“getCurSize”,但由于某种原因,即使我在其下面定义它,它也无法识别该定义并以绿色下划线显示。(这里是初学者,请耐心等待)
template<class ItemType>
class FDHPolynomial
{
private:
FDHNode<ItemType>* headPtr;
int itemcount;
FDHNode<ItemType>* getPointedTo(const ItemType& nodenum) const;
public:
FDHPolynomial();
FDHPolynomial(const FDHPolynomial <ItemType>& aPoly);
virtual ~FDHPolynomial();
int getCurSize() const;
bool isEmpty() const;
bool add(const ItemType& newCoeffi, const ItemType& newExpon);
bool remove(const ItemType& anExpon);
void clear();
bool contains(const ItemType& aExpon) const;
ItemType degree() const;
ItemType coefficient(const ItemType& power) const;
void changeCoefficient(const ItemType& newCoeffi, const ItemType&power);
std::vector<ItemType> toVector() const;
void print();
};
template<class ItemType>
int Polynomial<ItemType>::getCurSize() const
{
return itemCount;
}
Run Code Online (Sandbox Code Playgroud) 我无法找到在 Windows 下使用 cmake、Qt5 和 Visual C++ 构建非控制台应用程序的最新方法。看起来在 Qt4 时代,将 QT_USE_QTMAIN 设置为 true 就足够了。现在据说链接 Qt5::WinMain 就足够了。但是,这些都不适合我 - 我的应用程序继续打开控制台窗口。我在 cmake 或 Qt 文档中也找不到任何内容。
让应用程序停止打开控制台窗口的已记录/经过验证的方法是什么?
如果我直接使用ios::out打开一个文件,那么如果该文件存在,它将覆盖它或修改它。
但如果我用 来检查是否存在名为“XXX”的文件ios::in,如果不存在则用 来创建ios::out,则在此期间文件“XXX”可能被其他程序创建,那么文件“XXX”将被覆盖或被删除。和第一种情况一样修改。
如何fstream在 C++ 中安全地创建文件?
我知道__FUNC__是预定义的宏,但是当进入vscode时它无法识别__FUNC__。
https://learn.microsoft.com/zh-tw/cpp/preprocessor/predefined-macros?view=vs-2019
我应该更改或修改哪些设置?
DISK_PERFORMANCE DiskPerformance = {0};
DWORD dwDiskInfoSize = 0;
for (int i = 0; i < 10; i++)
{
std::printf("Try %d th Open \\\\.\\c:\n", i);
HANDLE hDevice = CreateFile(L"\\\\.\\c:",
0,
FILE_SHARE_READ | FILE_SHARE_WRITE,
//SYNCHRONIZE | FILE_READ_ATTRIBUTES,
NULL,
OPEN_EXISTING,
0,
NULL);
std::printf("hDevice = %p\n", hDevice);
if (hDevice == INVALID_HANDLE_VALUE)
{
std::printf("CreateFile failed = %d \n", GetLastError());
continue;
}
if (!DeviceIoControl(hDevice,
IOCTL_DISK_PERFORMANCE,
NULL,
0,
&DiskPerformance,
sizeof(DiskPerformance),
&dwDiskInfoSize,
NULL))
{
CloseHandle(hDevice);
std::printf("DeviceIoControl failed = %d \n", GetLastError());
continue;
}
std::printf("QuDeviceIoControlery Success\n");
CloseHandle(hDevice);
Sleep(1000);
std::printf("\n\n"); …Run Code Online (Sandbox Code Playgroud) 采取这个示例代码:
void CChristianLifeMinistryDiscussionsDlg::SetControlStates()
{
if (m_pEntry == nullptr)
return;
bool bClass1 = false, bClass2 = false;
m_pEntry->GetAuxiliaryClasses(bClass1, bClass2);
m_cbBrothersC1.EnableWindow(bClass1 ? TRUE : FALSE);
m_cbBrothersC2.EnableWindow(bClass2 ? TRUE : FALSE);
}
Run Code Online (Sandbox Code Playgroud)
EnableWindow需要一个类型为 的参数BOOL。我永远不清楚bool在这种情况下仅传递变量的值是否可以接受。
CArchive如果我们不知道文件中存储什么类型的对象,有什么方法可以从CArchive文件中检索信息吗?
我想知道信息以什么格式存储在CArchive文件中。
请帮我解决这个问题。
我是 C++ 编程新手。我正在对我的代码执行 SAST 违规检查,扫描会抛出警告:
_tcscpy(destination_array,Source);
Run Code Online (Sandbox Code Playgroud)
在 Source.cpp 文件的第 58 行中发现使用了危险函数 _tcscpy。此类功能可能会暴露信息并允许攻击者完全控制主机
因此,现在我必须使用它来使警告消失:
_tcscpy_s(destination_array,_countof(destination_array),Source);
Run Code Online (Sandbox Code Playgroud)
_tcscpy和之间的实际区别是什么?_tcscpy_s它如何使代码安全?
注意:这个问题的编辑方式从一开始就与问题的意图更相关。
这是代码:
class SmallClass
{
public:
std::function<void(SmallClass*)> function;
};
class BigClass
{
public:
SmallClass smallClass;
void SomeFunction(SmallClass* smallClassP)
{
return;
}
BigClass()
{
smallClass.function = SomeFunction; // error
}
};
Run Code Online (Sandbox Code Playgroud)
这是行不通的。使用 Visual Studio 会显示“没有运算符与这些操作数匹配 | 操作数类型为:std::function<void (SmallClass*)> = void (SmallClass*)”。通过写入std::bind(&BigClass::SomeFunction, this, &smallClass),它会奇怪地损坏smallClass并将其设置为 NULL。有办法解决这个问题吗?