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 want to implement a openfiledialog using CFileDialog with custom filter,
where I can get list of files and choose one by one which one to be shown or not,

For this I have tried to hook with OPENFILENAME's HookProc, But it only gets callback for old style dialog I want to implement it for new style dialog,

Could anyone please explain me, how can I implement this type of filter with new style explorer dialog, using any possible way or workaround.
Hi, I'm writing a simple text editor as coding practice in C++ using the Win32 API
and I wanted to add line numbers to the left hand side of the RichEdit control. I
have created a margin by sending a EM_SETMARGINS message to the RichEdit then I
subclassed the RichEdit and responded to the WM_PAINT message. Here's the subclass code :

LRESULT CALLBACK WndEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	switch (message)
	case WM_PAINT:
		CallWindowProc((WNDPROC)OldWndProc, hWnd, message, wParam, lParam);
		HDC hdc = GetDC(hWnd);
		ReleaseDC(hWnd, hdc);
		return 0;
		SetWindowLong(hEdit, GWL_WNDPROC, (LONG)OldWndProc);

	return CallWindowProc((WNDPROC)OldWndProc, hWnd, message, wParam, lParam);

Open in new window

As you can see I called the old window procedure first and then called my DisplayLineNumbers
function coz it didn't work properly if DisplayLineNumbers was called then the old window
procedure was called. But I have a problem with my DisplayLineNumbers function and I'm
not sure how to fix it. It seems to work but when I open a big file then scroll to the end
of the file the line numbers don't line up to the line of the RichEdit and when I hit enter
at the bottom of the file the line numbers skip a few. I must stress that I am a novice
coder so don't expect the code to be perfect but here's the DisplayLineNumbers function
that I wrote (hEdit is the handle of the RichEdit and hFont is the handle of the font and
it accepts a DC for the RichEdit, szBuffer is a buffer for the line number text) :

Open in new window

I have a WizardPage that has been developed with MFC.  I don't have access to internal CTabCtrl structure or PropertySheet directly, but only can use following macros :

TabCtrl_SetItemSize or PropSheet_GetTabControl. When I switch between Wizard Pages, I see that the tab items gets out of boundingrectangle of the parent control.

I eventually want to run the following  :       GetTabControl()->ModifyStyle(0, TCS_VERTICAL);

But this does not work

How can I overcome this problem ?
Using vs2010 c++. Net class library project, how to fix unresolved external symbol when calling static class method which coming from static c++. Lib compiled in vs2003?
Doing a dotnet c++ \CLI wrapper on old static mfc c++. Lib.

More info:
1. I got these c++ header files and the associate compiled static *.lib files (Hidden method implementation) from 3rd party vendor software. These files were compiled with old vs2003 which I don't have the source files.
2. These header files show us the method signature that we can invoke in our own project once included them in the MFC C++ project setting (Include Additional Directories/Dependencies).
3. Among the methods provided, one of the method was declared as static method.
4. Now, I'm trying to make C++ .net wrapper class to wrap all the methods provided so that it can be turned out as .net class library and used on other CLR .net projects.
5. I've tried to make it as native C++ dll, but seems too complicated and involves a lot of data types marshalling / and unforeseen memory corruption / crashes.
6. While doing the .net wrapper class and try to invoke the static method, the vs2010 that I use now, said unresolved external symbol for this static method.
A staff SW engineer once told me a few years ago that if no exceptions occur in a C++ try/catch clause, there are still impacts  to real-time performance. He didn't explain the underlying reasons behind his statement. I would like to get an under-the-hood explanation, as well as reading the supportive C++ specs.  Is his statement universally true or platform dependent? Thanks.

(Please assume for this question that the deployed system never has an exception.  One could do a timing test with and without the try/catch, but this discussion was over the phone. Anyway, I am trying to understand the statement without experimentation, but just based on the C++ language specs.)
I have some issues with Linux and loading dynamic libraries. In my case I load a library out of my app. This library is inside the same folder as my app. But now I want to load into this loaded library some libraries (plugins). But the system always report that it cannot find the library.
I am really new into this Linux world and so I want to find out my options to deal with it. My primary target is to have all dynamic libraries in the same folder to avoid problems.
Is there a way to use a C++ code to tell the software to search new libraries in the same path as the app is? I remember that this was possible on windows.

If I load the plugin I also use the full path to the library as well as the library name only.  
Any hint to deal with it? Or any further information needed?

Some data:
Ubuntu 64bit
C++ App compiled with C11 and Unicode
Bass Library, loaded with an dynamic interface, not with a static linked lib.
Bass Ape Plugin to test loading a Plugin.
Bass and Bassplugin are also 64 bit, same as my app.

The way I load the library, my app is cross platform, is working well on windows and on Mac, just on Linux I have the issue with the plugin.
I had this question after viewing How to use OpenRequest() of CHttpConnection?.

I need to send a POST to Google.Vision server, using MFC and c++. The code is the following:

        CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
      CString strFormData = "{'requests':[{'image':{'source':{'imageUri':'https://www.galileo2000.it/download/1.jpg'}},'features':[{'type':'FACE_DETECTION'}]}]}";

      CInternetSession session;
      CHttpConnection *pConnection = session.GetHttpConnection(_T("https://vision.googleapis.com/v1/images:annotate?key=MY_GOOGLE_API_KEY"));
      CHttpFile *pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,_T("https://vision.googleapis.com"));
      BOOL result = pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData,strFormData.GetLength());

Actually I am not very fond on these topics, so I got the above code in Internet. But I successfully wrote a WebService in C#, which works. The strFormData is the same I use in the WebService, so it should be correct. The main doubt is the second parameter of the OpenRequest. Of course I get an error "Impossible to resolve the server or the address". (Unluckily the message is in Italian and I translated back to English, so the actual error message could be slightly different).
Hey Guys, I have a doubt in c++ I am trying to develop a complex number matrix (a+bi) which takes 320k values in each row. Initially, we dump zeros into a matrix like this (0+0i).
Then during the execution of the program, we dump the data we have obtained.

  compiling xerces on solaris box.
  /usr/lib/sparcv9/ and /usr/lib/64 have libicu*54.  
  In another location, /icu_needs_to_build_with/libicu*44.
  Whenver I compile, it's always picking libicu*54 version. I do want to build xerces with libicu*44 libraries.
  Do we have any flags like LDFLAGS or xyz to configure specific version shared libs?
I have some Python code I need to translate into C++. I don't have a lot of experience with C++. Does anyone have suggestions on the best way to go about this?

Is there an app or anything I can use to do this process quickly?

I have a program in Delphi which i want to call it from C++QT;

So i want to make a (DLL) which contains a function in delphi to make an instance of the main form and launch the program...

I found many tutorial which all say that i have to do like this:

  frmDllForm :=TfrmDllForm.Create(nil);

** That does not work for the main window (Exception generated), but it does for a simple window from the same application...

The exception is: List Index is out-of-bounds...
Exception** Have you any idea which can help me please?

** Anybody know how to debug a dll in Embarcadero?
I am trying to generate .lib in Delphi (Embarcadero XE3). for using it in c++ program

I made a package project; and successfully, i could generate the .lib and the hpp headers... but, when i edit the .hpp, i found that it includes all files needed but has no fonctions...
namespace Spicecorelib
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
}      /* namespace Spicecorelib */

** What should i do to make functions exported, i have tried with ( cdecl, stdcall, export)....

thanks for your answers in advance
I already know some C++98 and am trying to familiarize myself with C++11. I am struggling to figure out how std::move works. My understanding, e.g. from here is that this works as a static_cast to an rvalue reference, in that it returns

static_cast<typename std::remove_reference<T>::type&&>(t) 

Open in new window

However, I find this puzzling since my understanding of std::remove_reference is that it actually does the opposite, i.e. it changes T& and T&& into T, since it can be implemented as

template <class T> struct remove_ref { typedef T type; };
template <class T> struct remove_ref<T&> { typedef T type; };
template <class T> struct remove_ref<T&&> { typedef T type; };

Open in new window

(see here). So how is it possible for std::move to act as a static_cast to an rvalue reference type?
Hi all,

  std map uses red-black or avl tree in C++?

  where can I find underlying implementation of std map? Is it depended on compilers?

very slow behavior when open IE with twebbrowser (borland) - i have a page that open in a c++ program on the cloud - but the all  behavior is slow and evan the images and progress-bar  are stack and not moving- i have image that spin - but trow this way it not spin
In my program I have many dynamically allocated C-style struct arrays that are connected via pointers. I have to do a deep copy to an external buffer. I have a corresponding number of write function for each struct array (e.g., writeA(), ... , writeZ().

Here is a little example that I made (it compiles, builds, and runs w/o crashing; and a spot check in gdb shows some good results). Notice that I copied the writeB() function to writeE() function, and then made the changes to types, data member, and function name. We all know that copy and paste is usually a bad thing; and the remedy is often dynamic polymorphism or templates.

Here are my goals: I would appreciate a simpler approach than copy/pasting which is tedious and error prone when making changes to the pasting. I would like the function to have as small number of args as possible. If I have a source and destination pointer, and then also have to refer to a source and destination data member, that is four arguments - would like to be able to reduce that to three arguments since the data member name is the same for both pointers.

I am leaning towards templates and would like to have one template function, write(), that deduces the type. Uh oh... If we do that, then in this template write(), we have a recursive write, but now with a different data type - ouch. The different data member (a pointer) also gives me some grief in trying to be elegant (i.e., minimum number of arguments…
Does anyone know the best way to debug a COM exe Service ATL project built in Visual Studio 2010?
I have tried registering the service as a plan exe (using /regserver flag for registering), to debug it as an exe, but still no luck
to enable debug mode. Thanks in advance.
I have a memory leak in a windows service (ATL COM exe Service),  built using Visual Studio 2010, running on a Windows Server 2003.
Does anyone know of any memory leak detector tools than I can use to detect the leaks down to a variable level (e.g. show the pointer variable causing the leaks).
Is a critical production issue , any help will be greatly appreciated.  I know googling will help me, but I'm running against time, and I don't have the luxury of time to try
all the tools out there, before choosing the best, so if anyone has had to perform similar diagnosis, please let me know.
Can some help me convert this C++ code to either java or C#
uint32 SN2ID(const string &szTermSN, string &szTermID)
       if(szTermSN.length() == 8 )
              int f1,f2,f3,f4;
              sscanf(szTermSN.c_str(), "%02d%02d%02d%02d", &f1, &f2, &f3, &f4);
              f2 += 128;
              f3 += 128;
              char tmp[10] = "";
              _snprintf(tmp, sizeof(tmp), "%02X%02X%02X%02X", f1, f2, f3, f4);
              szTermID = tmp;
       return 0;

Open in new window

if  for example  szTermSN=23D39449 szTermID=35832073
I am using Visual Studio Community 2017/C++ and AGK Trial 2 to develop GUI apps. The Console output nor the VS output don't show any debug messages, whereas the exact same code worked fine with Visual Studio 2010.  To start with I  used an AGK template VS2015 project and inserted my old working AGK code to it. It builds and runs perfectly in VS2017, but the Console doesn't show any debugging messages printed with "cout", as it did when using VS2010.   The following code  is the function I used to pop up the Console:

// for the console to display "cout" outputs, all these must be included
// And later these should be removed when you program is fully debugge
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>

void console_back()

int hCrt;
     FILE *hf;

   hCrt = _open_osfhandle(
             (long) GetStdHandle(STD_OUTPUT_HANDLE),
   hf = _fdopen( hCrt, "w" );
   *stdout = *hf;
   int i = setvbuf( stdout, NULL, _IONBF, 0 );


// in the main code
cout << "Hi, Hello World";	

Open in new window

As is see in the attached snapshot, the Console pops up but stays blank, though the is no runtime complains from the
system about the cout << "Hi ..".  

Experts, any ideas why this happens?  I hope there is a workaround for this problem, sample code is highly appreciated.

A side note, I am using a trial version of AGK package, where I don't have a debug version of AGKWindows.lib so I can't
build VS2017  in debug mode.  This makes debugging with console messages the only option for right now.
After all as long as I have a way to debug, I will be happy. But I don't know if the retail version of AGK  has the debug version of the AGKWindows.lib in C++.  Any comments or suggestions along this avenue are also appreciated.


When opening or creating a key in the Windows Registry using the WIN32 C API it is possible to specify the REGSAM as one of the arguments. This details the access rights to the key, but can also be used to set the "view", be it 32 bit or 64 bit. This is achieved by passing either KEY_WOW64_64KEY or KEY_WOW64_32KEY.

My question is this: given just a HKEY, is it possible to identify the original REGSAM value that was used to open that key? The program I am writing needs to be able to make this distinction and whilst I could "cache" the original REGSAM, it would be smarter and cleaner if there was a way (using WIN32 C API) to get these details.
CoCreateInstance returns E_NOINTERFACE from COM service (service restart fixes it)

Once in a while, my COM ATL server service will get into a state whereby my C++ client application (also a windows COM ATL service) will start failing to create a COM object due to a E_NOINTERFACE error. But when I connect to this same COM server via a C++ client application (console) it is able to connect to it. Also, when I restart my COM ATL server service, my COM ATL service (client) is able to connect to the server.

I've have attached a file (sensitive information), explaining the problem more in depth.COMATLServiceIssue.docx

edit by Scott Fell. EE Moderator - adding content from word file
Once in a while, my COM ATL server service will get into a state whereby my C++ client application (also a windows COM ATL service) will start failing to create a COM object due to a E_NOINTERFACE error. But when I connect to this same COM server via a C++ client application (console) it is able to connect to it. Also, when I restart my COM ATL server service, my COM ATL service (client) is able to connect to the server.

This is an out-of-process setup.

The Server, is, namely, VafDbService:

The Client, is, namely, VacDocAutoSetup:

Setup in production as below:

Capture.JPGCode in VacDocAuto Service whereby I get the E_NOINTERFACE error, after being able to obtain a COM handle to VafDBService for most of the day.

Open in new window

I have been trying to solve the problem for a month with googling. But Now I have to ask for help here.

I want to render using ffmpeg decoded frame. and using frame, I try to render frame with DX2D texture.

ZeroMemory(&TextureDesc, sizeof(TextureDesc));

TextureDesc.Height = pFrame->height;
TextureDesc.Width = pFrame->width;
TextureDesc.MipLevels = 1;
TextureDesc.ArraySize = 1;
TextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;            //size 16
TextureDesc.SampleDesc.Count = 1;
TextureDesc.SampleDesc.Quality = 0;
TextureDesc.Usage = D3D11_USAGE_DYNAMIC;
TextureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
TextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
TextureDesc.MiscFlags = 0;

result = m_device->CreateTexture2D(&TextureDesc, NULL, &m_2DTex);
if (FAILED(result))     return false;

ShaderResourceViewDesc.Format = TextureDesc.Format;
ShaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
ShaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
ShaderResourceViewDesc.Texture2D.MipLevels = 1;

    D3D11_MAPPED_SUBRESOURCE S_mappedResource_tt = { 0, };

ZeroMemory(&S_mappedResource_tt, sizeof(D3D11_MAPPED_SUBRESOURCE));

result = m_deviceContext->Map(m_2DTex, 0, D3D11_MAP_WRITE_DISCARD, 0, &S_mappedResource_tt);
if (FAILED(result)) return false;
BYTE* mappedData = reinterpret_cast<BYTE *>(S_mappedResource_tt.pData);
for (auto i = 0; i < pFrame->height; ++i) {
    memcpy(mappedData, pFrame->data, pFrame->linesize[0]);
    mappedData += 

Open in new window

I have a native C++ application that uses SQL Server 2012 with filestream.  It uses win32 API calls for streaming access e.g. OpenFileStream() to Save/Load the data from the database(s)/filestream.  In the past we have granted sysadmin privileges to SQL logins as we control the SQL instance.  
I would now like to restrict the SQL privileges given to the SQL logins to the least possible.  I have tried SQL Authentication and also Application Roles but neither allow the use of the Win32 API calls to filestream.  Can anyone suggest how I can continue to use the API streaming calls and restrict the SQL access?  My users need to be able a read/write to the application databases and also create, delete, backup, restore user databases.  Many thanks for any help on this....
I am using arduino-crypto for my ESP8266. I'm not running into any errors but I do have an issue that I hope you can solve for me.

This code:
#define BLOCK_SIZE 16

uint8_t key[BLOCK_SIZE] = { 0x1C,0x3E,0x4B,0xAF,0x13,0x4A,0x89,0xC3,0xF3,0x87,0x4F,0xBC,0xD7,0xF3, 0x31, 0x31 };
uint8_t iv[BLOCK_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

char plain_text[] = "1234567890ABCDEF1234567890ABCDEF";

  // encrypt
  int length = 0;
  bufferSize(plain_text, length);
  char encrypted[length];
  encrypt(plain_text, encrypted, length);

  Serial.print("Encrypted: ");


Open in new window

Works just fine and gives me an encryption value of:

Encrypted: y3QzsGi6cYiy3GGs31jXvTY8VI2OrlxsohOasiw4pgP+54gWXtUZPrjuRvOfyRTz

Open in new window

Now if i do both encrypt and decrypt then it decodes it just fine.

However, when i just run the decryption and copy the encrypted value and then run this:

// decrypt
  char* encrypted = "y3QzsGi6cYiy3GGs31jXvTY8VI2OrlxsohOasiw4pgP+54gWXtUZPrjuRvOfyRTz";
  int length = strlen(encrypted);
  char decrypted[length];
  decrypt(encrypted, decrypted, length);
  Serial.print("Decrypted: ");

Open in new window

It outputs this in the console:

Decrypted: ⸮⸮⸮⸮⸮j⸮Ҏ⸮R|;⸮⸮1234567890ABCDEF

Open in new window

It has a few original message letters/numbers in there but not sure why its not decrpting it like it does when you run both back-to-back.

What can be done in order to fix this?






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.