visual-c++

how to define a good/perfect New function to init any class/struct in C++?

眉间皱痕 提交于 2020-04-17 21:48:06
问题 struct object { void Name() {} }; struct ABC:object { //Note:did not declare any constructor and base class is object std::byte a; const std::string* b; int c; } struct BCD { //Note:did not declare any constructor and none base class std::byte a; const std::string* b; int c; } i want the New function accept: New<ABC>({12,"first",123}); New<ABC>(a,b,c); New<BCD>({12,"first",123}); New<BCD>(a,b,c); this is my New function define: template <class _Ty, class... _Types, std::enable_if_t<!std::is

DLL : export as a C/C++ function?

一曲冷凌霜 提交于 2020-04-16 09:12:17
问题 I generated a DLL in Visual from a C++ code. Dependency Walker sees 3 functions exported as C functions. I made an SCons project to do the generate the DLL, and 2 of the 3 functions are not seen as C functions. What makes a function seen as a or C++ function, without modifying the code ? It must be in the compilation/linking options, but I didn't find any relevant thing. The function are prefixed by a macro : AM_LIB_EXPORT In the .h, I have : #ifdef _WIN32 #define AM_LIB_EXPORT __declspec

“'getenv': This function or variable may be unsafe.” - really?

被刻印的时光 ゝ 提交于 2020-04-12 19:46:13
问题 I'm using MSVC to compile some C code which uses standard-library functions, such as getenv() , sprintf and others, with /W3 set for warnings. I'm told by MSVC that: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS Questions: Why would this be unsafe, theoretically - as opposed to its use on other platforms? Is it unsafe on Windows in practice? Assuming I'm not writing security-oriented code - should I

Building a static version of OpenSSL library using /MD switch

限于喜欢 提交于 2020-04-10 06:48:30
问题 Building OpenSSL using its default configuration gives you a dynamic version of the library. According to OpenSSL Compilation and Installation document on its Wiki, there is a configuration option named no-shared which disables shared objects and only creates a static library. Visual C++ compiler links a binary (library or application) either to libcmt(d).lib (Statically links the native CRT startup into your code using /MT(d)) or msvcrt(d).lib (Static library for the native CRT startup for

How to send HTTPS request using WinInet?

拈花ヽ惹草 提交于 2020-04-08 09:27:29
问题 I want to send HTTPS GET request using WinInet. As far as i know, i should do it just like sending HTTP request except i have to use INTERNET_DEFAULT_HTTPS_PORT and INTERNET_FLAG_SECURE flag. So here is what i tried: #include "stdafx.h" #include <string> #include <windows.h> #include <WinInet.h> #pragma comment (lib, "Wininet.lib") using namespace std; // convert string wstring CharPToWstring(const char* _charP) { return wstring(_charP, _charP + strlen(_charP)); } // send https request

How to send HTTPS request using WinInet?

▼魔方 西西 提交于 2020-04-08 09:26:06
问题 I want to send HTTPS GET request using WinInet. As far as i know, i should do it just like sending HTTP request except i have to use INTERNET_DEFAULT_HTTPS_PORT and INTERNET_FLAG_SECURE flag. So here is what i tried: #include "stdafx.h" #include <string> #include <windows.h> #include <WinInet.h> #pragma comment (lib, "Wininet.lib") using namespace std; // convert string wstring CharPToWstring(const char* _charP) { return wstring(_charP, _charP + strlen(_charP)); } // send https request

Difference between char * and LPSTR in windows

拟墨画扇 提交于 2020-04-08 08:48:05
问题 I apologise if it is a basic or silly question. What is the difference between char* and LPSTR . where the sizeof both gives 4 bytes in my compiler. Can someone explain me in detail. thanks.. 回答1: LPSTR is a Windows type, meant to be be the same regardless of what platform you were compiling on. It's a long pointer to a string. Back in the days of segmented architecture (the old 64K segments, not the newer selector-based segmented memory), where you had tiny, small, medium, large and huge

Is it useless to use the `register` keyword with modern compilers, when optimizing?

﹥>﹥吖頭↗ 提交于 2020-04-06 21:50:12
问题 The C register keyword gives the compiler a hint to prefer storing a variable in a register rather than, say, on the stack. A compiler may ignore it if it likes. I understand that it's mostly-useless these days when you compile with optimization turned on, but is it entirely useless? More specifically: For any combination of { gcc, clang, msvc } x { -Og, -O, -O2, -O3 }: Is register ignored when deciding whether to actually assign a register? And if not, are there cases in which it's useful

Why can't I declare a string in my program: “string is undeclared identifier”

Deadly 提交于 2020-04-06 03:15:30
问题 I can't declare a string in my program: string MessageBoxText = CharNameTextBox->Text; it just doesn't work. It says string is undeclared identifier . What am I missing in the namespace or include or something like that? 回答1: Make sure you've included this header: #include <string> And then use std::string instead of string . It is because string is defined in std namespace. And don't write this at namespace scope: using namespace std; //bad practice if you write this at namespace scope

How-to use Clang Static Analyzer on Windows?

你离开我真会死。 提交于 2020-04-05 06:45:15
问题 I'm currently trying to integrate the Clang Static Analyzer v9.0.1 into my CMake v3.16.5 build system using the Microsoft Visual C++ Compiler (MSVC) v19.25.28610.4 on a Windows v10.0.18363.720 operating system. Everything is build for the architecture x86_64. LLVM and Clang have been build from source. After some reading on the World Wide Web (WWW), there seems to be multiple ways to use the Clang Static Analyzer. Sadly the documentation is horrible and there seems to be some special quirks