C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

I'm developing a game guard. And in the process, I want to read a packet and check its contents ... how should I do?

*(PDWORD)&OrigRecv = APIHook((DWORD)GetProcAddress(GetModuleHandle("Ws2_32.dll"), "recv"), (DWORD)MyRecv, (DWORD)OrigRecv);

Open in new window

my function recv

int WINAPI __stdcall MyRecv(SOCKET s, const char* buf, int len, int flags)
	int RecvedBytes = OrigRecv(s, buf, len, flags);
	if(RecvedBytes == SOCKET_ERROR) return RecvedBytes;

	eikasia_process_recv(s, (char *)buf, &RecvedBytes, flags); // Process the recived buffer
	return RecvedBytes;

Open in new window

My function process

void eikasia_process_recv(SOCKET s, char* buf, int *len, int flags) {
	unsigned int command = (*(unsigned short*)buf);

	if(command == 0x0363 ) {
     //reader buf data ...? read char* buf.... ?? help-me!


Open in new window

When I find the packet I want to process, I want to read the contents of it to find the value I want. How to proceed?

my github: https://github.com/AsiaGenius/ring-0
I was trying to use wcstombs_s to convert my Japanese wstring into multibyte char but am getting empty string . Here's what i was doing my first approach using wcstombs_s -

wstring str = "ス";
char * outputString;
size_t outputSize = str.length() + 1; // +1 for null terminator
outputString = new char[outputSize];
size_t charsConverted = 0;
const wchar_t * inputW = str.c_str();
wcstombs_s(&charsConverted, outputString, outputSize, inputW, str.length());
i receive empty string in inputW,
Hi Experts,

I am using VB.Net, C#, VS 2015 along with various other com components written in C++ language plus various third-party DLL's. This is a window based application having a client-server architecture.

I know this seems like subjective question itself but appreciate if you could provide some guidance, challenges faced that one should take care while moving from 32-bit code base to 64-bit.

Looking forward to hearing from you guys.

I'm doing a C++ compiler project where I need to flag warnings at places where assignment operator (`=`) can be used wrongly instead of the comparison operator (`==`)...e.g
while doing comparison in `if` statement , to check variable `a` as `10` sometimes we wrongly type if(`a`= `10`), which will result in `if` statement always `true` whereas I wanted to be `true` only if `a` is `10`. Some of the cases I can think of are :
1. `if(var = a)`, logically it should be `if( var==a )`
2. `while(var = a )`
3. `for(;var=a;)`
4. `do{}while(var=a)`
5. `var=a? "some XYZ": "some ABC"`

Can you please help me with the more cases where this logical error can occur, where the user was supposed to use `==` and by mistake `=` was used?
I am trying to do a cryptography, but to no avail .... the code does not compile. How do I convert const char * buf to BYTE? Or is there another way?

#include <cstdio>
typedef unsigned char BYTE;
BYTE server_keys[2][256] = {
		0xFC, 0x77, 0xA1, 0x85, 0x1F, 0x30, 0x51, 0x20, 0x93, 0x4A, 0xE3, 0x10, 0x0E, 0x32, 0x58,
		0x64, 0x36, 0x8C, 0x19, 0xF0, 0x61, 0xE0, 0xDF, 0x9E, 0x9F, 0x90, 0xD0, 0x05, 0xFA, 0xEB,
		0x3D, 0x4B, 0xA5, 0xF1, 0x72, 0x73, 0xD4, 0xB5, 0x70, 0xD7, 0xCD, 0x9A, 0x95, 0x2B, 0xC9,
		0x00, 0x8E, 0xAC, 0x35, 0x1B, 0xE7, 0x7B, 0xC3, 0x15, 0x11, 0xF6, 0xAD, 0x5B, 0x87, 0x86,
		0xB4, 0x9B, 0x26, 0xDB, 0xDE, 0x1C, 0x66, 0x24, 0xD8, 0x27, 0x6A, 0xBD, 0x5D, 0x8D, 0x7D,
		0x0D, 0xAE, 0x8B, 0xA9, 0x62, 0x6B, 0x0B, 0xE2, 0x5C, 0x6C, 0xBE, 0x54, 0x55, 0x6E, 0xBF,
		0x3F, 0x88, 0x99, 0xB0, 0x48, 0x16, 0x5A, 0x34, 0xA6, 0xE8, 0xFD, 0xD3, 0xE4, 0x82, 0xD6,
		0x8A, 0x3B, 0xFE, 0xA4, 0x94, 0xF8, 0x06, 0x97, 0xCB, 0xF5, 0x33, 0x79, 0xD9, 0x83, 0x4F,
		0xB1, 0xAB, 0xA2, 0x69, 0x91, 0xFF, 0xC6, 0x2C, 0x68, 0xC1, 0xAA, 0xC4, 0x1D, 0x18, 0x3A,
		0xBC, 0x04, 0x2F, 0xA3, 0xFB, 0x17, 0x89, 0x25, 0x02, 0xCF, 0xDD, 0x2D, 0x6D, 0xC5, 0xC2,
		0x46, 0x01, 0xE5, 0xED, 0x2E, 0xDA, 0x31, 0x37, 0x40, 0xC8, 0xB6, 0xE9, 0x7C, 0x45, 0xF3,
		0x47, 0x22, 0xF9, 0x63, 0xB9, 0x13, 0x38, 0x78, 0x2A, 0xC0, 0xEC, 0xEF, 0x28, 0x12, 0x6F,
		0x75, 0xEA, 0x29, 0x84, 0x9C, 0x44, 0x96, 0x0A, 0x59, 0x76, 0x92, 0x41, 0xF2, 0x67, 0x08,
		0xB8, 0x43, 0xCA, 0x1E, 0xE1, 0x52, 0x3C, 0x42, 0xEE, 0xA8,

Open in new window

Hello! I am intercepting packets and want to encrypt them using a simple XOR. The packets are not being encrypted, where am I going wrong?

void process_send(SOCKET s, const char* buf, int *len, int flags) {

			char* q;
			char j = 0;
			int l = sizeof(buf);
			char k;
			int i;
			q = (char *)buf;
			k = q[4];			

			q[4] ^= 0x76;
			for(i = 5; i < l; i++)
			j = q[i];
			q[i] ^= k;
			k = j;

Open in new window

Help-me :/
Hello everybody!
I`m looking for a good and EASY library that works with sending and getting a .wav file voice message, can you please share your experience with me which library to choose as there are plenty of them out there
Thank you in advance!
Maybe a dumb question, but here goes: So, my C++ application uses GDI calls to draw pretty simple lines, arc, etc. overlaid on images.  I'd like to upgrade the look of those graphics -- maybe with something a bit more powerful than GDI that can maybe do anti-aliasing, or other things to make the overlaid lines and circles look better and cute.  So, I see talk of GDI+.  And I saw a post of a GDI+ example, and the calls look exactly like the calls that I have been referring to as "GDI" for years.   So, my application is MS VC++  and using IDS VS2015.   Its not .NET -- just C++ code, often quite close to C code actually.  So my questions:

1) Do I have to do something (link something or load something) to get GDI+?  Or is it just there, ready for me to start calling?
2) I believe I can call things in GDI+ from my non-.NET C++ code, correct?
3) Will I find some things in GDI+ that were not in GDI that will help me make my graphics (overlaid on images) look better, cuter?
4) Where do I find doc so I can look thru what is available in GDI+ ?

This jovial programmer is Paul Kent.  I just published his new course on C++.  Great job, Paul!


Note: This is a paid course.

In C++, what is the most elegant way to check if an argv[i] is an integer? I prefer a short inbuilt check instead of writing a function that does something like traverse the char* and check if each element is a digit.

Any suggestions? thank you
So i have a program which filters a file containing "emails" in a single line, i link you to the exercise (it is a pdf) https://training.olinfo.it/#/task/ioit_spam/statement so my problem is that it doesn't accomplish all of the 4 tasks but from my tests (i've created a file with 1000 emails) it should correctly and pass all of its cases. i don't know if it's a problem of the corrector on the site (you need to register to test the program) but i link here the scoring (it should score 100 in theory) it might be a problem of the corrector? https://imgur.com/a/QmeY5 and the source file is this https://pastebin.com/iVPXUjxb
Thanks to everyone answering i hope i've made the question clear, the program works in my machine, it can even scan 10000 emails if i'd want to, infact i've tried filtering a 8mb file containing 1000 emails with 1000 words each.
this is the link for the 1000 emails input file https://drive.google.com/file/d/1f9OWkzZ_i9T8s6BcNIq5hXqBogCR2Dcj/view?usp=sharing
I have been trying to pass a string to fetch the node and am successful for string with only single quote (') and only double quotes ("). But am unable to parse it when string contains both singe and double quotes. I have my string in CString as-

CString str=L("H'el"lo");
and all other combinations of these. Can you please tell me how to do in C++, i have seen the examples are in C# but that are not helping me out.

Here's the link for C# Encoding XPath Expressions with both single and double quotes

XmlNode n = doc.SelectSingleNode(“/root/emp[lname=" + str + "]“);
How should i make my str work for string containing both single and double quotes in any order.
Constraint: Cannot change from C++03 or C-88.

After some online search, I wrote the following program to see how to run a class non-static member function in a pthread via a static member helper. But I got the wrong answer. According to breakpoints, the DoSomething constructor is called once; yet on the 2nd call to doSomething, the initial values of val1 and val2 are set to 100, 200.0, respectively. Granted, I set the members of an internal struct to those values, but not to the class data members.

So, how did that happen; how do I get the args.retval return value from the pthread to end in 5 + 16 = 21 + a multiple of 100.
// header
class DoSomething
	DoSomething(int v1, float v2)
		: val1(v1), val2(v2) {
	retval = val2 - val1;

	float* doSomething(int v1, float v2) 
		val1 += v1;
		val2 += v2;
		retval = val1 + val2;
		return &retval;

	struct v1v2_s
		int v1;
		float v2;
		float retval;

    void* DS_helper(void* args)
		int v1 = ((v1v2_s*)args)->v1;
		float v2 = ((v1v2_s*)args)->v2;
		((v1v2_s*)args)->retval = *((DoSomething*)args)->doSomething(v1, v2);
		return args;

	int val1;
	float val2;
	float retval;

Open in new window

#include "DoSomething.h"

int main()
	DoSomething DS(2, 9);

	DS.doSomething(3, 7);

	DoSomething::v1v2_s args = {100, 200.0};

	pthread_t t;
	pthread_create(&t, NULL, DS.DS_helper, &args);
	pthread_join(t, (void**)&args);
	float res = args.retval;
	return 0;

Open in new window

If you could correct the existing code w/o trying to revamp the whole approach, I would appreciate that. (After this is done, then, sure, revamp the whole approach.)
Thanks in advance.
I was going to send a struct from a client to a server using boost::asio::async_write_some, in this case boost::serialization and boost::property_tree come to help,
struct blank
    int m_id;
    std::string m_message;

    template<typename archive>
    void serialize(archive& ar, const short version)
        ar & m_id;
        ar & m_message;

blank info;

info.m_id = 1;
info.m_name = "Rasul";

std::stringstream ss;
boost::archive::binary_oarchive out_archive(ss);

out_archive << info;

Open in new window

So, now how can I send/receive out_archive using boost::asio asynchronously .. or
boost::property_tree::ptree root;
root.put("id", 2);
root.put("name", "Rasul");

Open in new window

How can I send/receive root using boost::asio asynchronously??? (If you have some other ideas please share them)
#include <iostream.h>
#include <bits/stdc++.h>

using namespace std;
	   struct Node
	       int data;
		   struct Node* next;
		   int small(struct Node* head)
		   int min = INT_MAX;
		   while (head != NULL)
		      if ( min > head->data)
			       min = head->data;
				   head = head->next;
				   return min;
				   void push (struct Node ** head ,int data)
				   	struct Node * newNode ;
					newNode->next = (*head);
					(*head) = newNode;
				   void display(struct Node* head)
				    while ( head != NULL ) 
					   printf("%d -> ", head->data);
                          head = head->next;
					cout << "NULL" << endl;
			int main()
			   int x;
			  struct Node* head = NULL;
			   cout << "Linked list is:"<<endl;
			   cout <<"The minimum element in linked list :"<<endl;
			   cout << small(head) <<endl;
			   return 0;

Open in new window

This isn't really a question; rather, it is a puzzle!!!

Please note, this is NOT an assignment of any kind (check my profile if you are unsure as to my tenure on the site). The idea is to spark some activity in the C/C++ topic areas and to have a little fun. Points will be awarded to the expert(s) who provide the most interesting solution. The idea is to have a little fun, promote discussion and have something interesting to think/talk about.

If this goes well, I plan on doing one of these types of puzzle questions on a regular(ish) basis. I would like to see expert colaboration, rather than experts just going gun-ho to get points. I will consider colaboration between experts when I finally award points. I will close this question once I believe it has reached a natural conclusion (ie. no futher productive activity).

So, let's start with the first puzzle. It's one that has been set many times before and I'd be interested in seeing different approaches to solving it. Please don't just search Google and copy/paste. I promise I will check and any plaigirised answers will be ignored (and probably deleted).

Let's go...

Your job is to write a program that, when run, outputs it's own source code (including comments) such that if the output was fed back into a compiler, built and run it would do exactly the same thing as the original program. The output must be word for word identical to the original source code, such that performing a diff between the original source …
I had this question after viewing Overlay a dialog box from a dll.
Will C++ and VB6 continue to work in newest versions of Windows?
We have some old program written in  C++ and VB6 and want to prioritise upgrading them to .NET.
If a new version of Windows will make them obsolete overnight then upgrading them is a high priority.  Otherwise not.
A similar question arises if processors move from 64 bit to 128 bit.
I have a program created using C++ that runs fine on all Windows 7 computers. But the application crashes on Windows 10 computers unless they select "Run as Administrator". This is a serious issue when distributing my software. Is there any way programmatically to allow the program to run in this hostile environment?
I will be given a set of X/Y points and their corresponding Z values. Z = f(X, Y), but I do not know the function f. The points will be clustered together and I don't expect pathological conditions. The local maximums and minimums will have extra sample points to help make the interpolation better. The goal is to come up with a smooth surface that represents the function f as close as possible.

The analyst providing me with the set of points of known XYZ points will also give me an XY rectangular grid; and at all the intersection points of horizontal and vertical lines, I need to provide a z-value.

One thought I had was to consider a point and look at 4 quadrants, and take the closest point in each quadrant, and using those 4 points or more to try to interpolate. Prefer to be able to use a curved surface to get the results rather than linear planes. One rule is that the final results will match the given XYZ points . The given points are known as anchor points or knots.

I am just looking for something functional. I am not interested in speed.

 I am not allowed to use binaries, so I will have to build from source code in Linux or Windows.

Thanks in advance.
I first started out trying to learn C# but found out that in order to code the trading strategies and functions that we want, we would have to use this package called Sierra Charts

The developer I am working with is very familiar with SC and pointed me to this C++ Tutorial https://www.sierrachart.com/index.php?page=doc/AdvancedCustomStudyInterfaceAndLanguage.php#CPlusPlusReferences

This software looks rather dated in comparison to something like MultiCharts https://www.multicharts.com/net/ which uses .NET.

I might consider switching at some point to another platform like MC .net version, but in all my research, I see that C++ is the most prevalent among traders.  It is fast, which is the main consideration, and lots of pre-written functions already exist for it.

So I have switched my focus, since I am developing in C++ currently with SC, to learning the basics of C++ over C#.

I have been through the tutorial above and think I have absorbed just enough of it to barely understand what it is, but I am determined and now want to find a better tutorial that won't take me too far off base from what I am trying to do which is to code trading strategies.

I'd still like to learn the basics of C++ a little bit better before really getting my feet wet with Sierra Charts as I am currently letting my developer work on developing the function, which he is much better off doing, without my interference.

I'd like a tutorial for C++ that is much more interactive, lets me …
i want to create one dialog control with three buttons dynamically and  same dialog to created dynamically again 12 dialog s with the same content and size  but 12 dialogs control  should appear tile in format.
Due to security concerns related to updates not being applied to third-party software libraries, we are trying to replace as many of these as possible with functionality provided by the operating systems and are looking into options with compression. Are there any common compression formats that both Linux and Windows understand and provide C or C++-callable functions to programs to compress to and decompress from using only the APIs provided by the operating systems as installed? Thanks for any information!
Background: i work in a red hat and Windows 10 environment. We have models written in Matlab and Simulink that the developers will convert to C++ in order to get higher speed simulations. We do not like the C++ code that can be generated from these two products. We have a simulation proprietary framework which provides us with many math APIs for C++.

We currently use C++03 with Visual Studio 2010 and g++. Lead developer has no experience with C++11 but he would like to convince a large community of divisions to upgrade to C++11 . I asked him what skill levels of developers would he be bringing in . He said his group cannot afford the best, and he believes that C++ 11 is more complicated than C++ 03. Recently I've been doing this survey of multithreading capabilities in C++11, boost, Pthreads, WIN APIs , and while I can see that C++11 features are rich , they are also complicated to use correctly . For example if you want to squeeze performance out of a program that uses many cores , then you have to learn about the C++11 memory model, and be aware of all the tricky race conditions that can occur when the high-level code is done out of order as result of compiler optimization .

 Could someone give me a list of C++11 features that an average C++ developer could use and explain how it is beneficial with a strong argument that we convince a large community of divisions to agree to upgrade to C++11 .

 Two items that come to mind are multithreading and dimensional …
Below is a snippet from a REST server application that I have written in Embarcadero C++ builder XE10.1 Berlin

void TWebModule1::Action1Get(TWebRequest *Request,TWebResponse *Response)
  Code here generates some JSON response based on the Request.....

// send the response
Response->ContentType 	= u"application/json";
Response->Content       = ... some JSON text


Open in new window

I wish to modify the REST server so as to return some html text in another Action handler but I need to know the value to assign to the Response->ContentType instead of "application/json"
Also what other values are valid Response->ContentTypes ?






C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.