C++

57K

Solutions

24K

Contributors

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 had this question after viewing Delphi and static libraries.

What if i want to use delphi functions (.lib) from C++. I try to do this; i found .hpp generated in Delphi has no functions!
namespace Spicecorelib
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
}      /* namespace Spicecorelib */
0
Exploring ASP.NET Core: Fundamentals
LVL 13
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Hi;
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
0
Good morning....

 We have an old accounting System (Sales, Purchases, ledgers, receivables, inventory, etc) called RTS-ADVANTAGE.  
To get specific and customized reports from that system, we have to Export the information via TXT files.   After we have the TXT files we LINK those files to MS-ACCESS, where we can build queries and reports.
The Export process is done using Macros in RTS-Advantage, which runs every 2, 5, 6 hours (let's say).
The process of exporting the information is sometimes slow and is not live.   The users needs real live information (the most possible) and running the macros to export is tedious.

Our need:
We are looking a solution to CONNECT (at least READ) the information DIRECTLY from the RTS-ADVANTAGE tables or files, so no exportation is needed and we can build queries and reports in MS-ACCESS (Preferably).  It might be ODBC for instance.  
NOTE:  RTS-ADVANTAGE was built using C++ and it uses ISAM files.
Please find attached Data Files and Pictures (Power Point) showing the program and Explorer structure.

Looking forward...
Dat-files.zip
ADVANTAGE-PICS.pptx
0
Hi all,

In C,

crypt(userpassword, etc-password) always returning NULL in other application.

In my simple test application, working fine.

 What could be the reason?  How to fix this?

Thanks,
Bvm
0
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?
0
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?

TIA,
Bvm
0
We like to computerize the billing system of a hospital. Turn in a UML diagram for the patientType class developed in part E, below. You can use any tools you like for your UML diagram. You can even take a picture of a printed copy and turn in. The picture must be legible for grading. The textbook has many examples on proper forms of the UML diagram.
student.txt
bill smith 2.8
mary jones 3.5

Open in new window

struct_exampleFile.cpp
#include <iostream> 
#include <fstream>
  
using namespace std;

struct student{
       string fname;
       string lname;
       double gpa;
       };  //defines the type
//struct within structs
struct employee{
       student s;
       double salary;
       };

void displayStudent(student);
void displayStudentData(student[], int);
int getStudentData(student []);

int main()
{
    int numstudents = 0;
    student csn[10];
/*
    student s1;

    s1.fname = "joe";
    s1.lname = "smith";
    s1.gpa = 2.5;
    
    csn[0].fname = "bill";
    student s2;
    s2 = s1; 
    s2.gpa = 4.0;

//can't do this cout<<s1<<endl;
    cout<<s1.fname<<", "<<s1.lname<<", "<<s1.gpa<<endl;
   
    displayStudent(s1);
    
    cout<<"\n\nsecond student\n";
    displayStudent(s2);
     
    employee e;
    e.s.fname = "empfirst";
    e.s.lname = "emplast";
    e.s.gpa = 999;
    e.salary = 25000;
    
    cout<<e.s.lname<<"  "<<e.salary<<endl;
*/    
    
    numstudents = getStudentData(csn);
    
    cout<<"all students\n";
    displayStudentData(csn, 

Open in new window

0
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
0
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…
0
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.
0
CompTIA Cloud+
LVL 13
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.
0
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
0
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;

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

   return;
}

// in the main code
console_back();
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.

Thanks

Ze
Console_done_problem.PNG
Console_done_problem.PNG
0
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.
0
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:

Services
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.
COSERVERINFO cSI = {0};

Open in new window

0
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

0
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....
0
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.println("");
  Serial.print("Encrypted: ");
  Serial.println(encrypted);

  Serial.println(length);
  Serial.println(strlen(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: ");
  Serial.println(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?
0
Hey all I am trying my best to fixed these few errors below. The C++ code is from an Arduino library that i wanted to convert to Visual C++ dll for use in one of my C# applications.

These are the areas that have the errors:

void AES::do_aes_encrypt(BYTE *plain,int size_p,BYTE *cipher,BYTE *key, int bits, BYTE ivl [N_BLOCK]){
  calc_size_n_pad(size_p);
  BYTE plain_p[get_size()];
  padPlaintext(plain,plain_p);
  int blocks = get_size() / N_BLOCK;
  set_key(key, bits) ;
  cbc_encrypt(plain_p, cipher, blocks, ivl);
}

Open in new window


The "BYTE plain_p[get_size()];" has the error of "'this' cannot be used in a constant expression".

string AES::letsDecrypt(BYTE *key, string msg, AES aes) {
  char data_decoded[200];
  char iv_decoded[200];
  char temp[200];
  BYTE out[200];
   
  aes.set_key(key, sizeof(key));
  msg.toCharArray(temp, 200);
  int b64len = base64_decode(data_decoded, temp, msg.length());
  string(iv_Encoded).toCharArray(temp, 200);
  
  base64_decode(iv_decoded, temp, string(iv_Encoded).length());  
  aes.do_aes_decrypt((BYTE *)data_decoded, b64len, out, key, 128, (BYTE *)iv_decoded);
  char message[msg.length()];
  char* msgBase64 = (char *)out;
    
  base64_decode(message, (char *)out, msg.length());

  return std::string(message);
}

Open in new window


The "msg.toCharArray(temp, 200);" has the error of "class "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" has no member "toCharArray"".

Another error on the same code above "char message[msg.length()];" has the error of "expression must have a constant value".

And lastly i get this error: "unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?" Which when i try to include it-it says it cant be found.

Help would be great!
0
Why Diversity in Tech Matters
LVL 13
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Best tool to generate uml diagrams from c++ project on RHEL.  Tried with Bouml. Failed to generate. Deleveloped cross platform compatible code between Linux/Windows.  Compiled on Windows with the help of Cygwin.

What is the easiest method to generate diagrams for every module.  Don't have solution file on Windows.

Please suggest.

Thanks,
Bvm
0
In a code part of a software that I got to update I found a the line

TypeAndTimeZone = UINT16( 1 << 12 | uint16(timeDiff/60));

timeDiff has the negative value -7200.0000

TypeAndTimeZone will get the value: 65416
What kind of numeric value is this because I expected -120.
If I will do
TypeAndTimeZone = TypeAndTimeZone * -1 I will get 120 instead of 65416.

Is 65416 a negative numeric value? Or is there an error to get this as a negative value?
0
CWinThread wont exit in Release mode but will in Debug mode visual studio 2017.

Here is what I am doing
CWinThread *ptrDecode = AfxGetThread();
CCriticalSection c_sDecode;
static UINT mDecode(void*);
ptrDecode = NULL;

void myfuction::startThread()
{
      if (ptrDecode == NULL) {
	  ptrDecode = AfxBeginThread(mDecode, this);
	  WaitForSingleObject(ptrDecode, INFINITE);
	}
}

UINT /*WINAPI*/  mDecode(void* pParam)
{
	myfuction* pThis = (myfuction*)pParam;
	CSingleLock lock(&c_sDecode);

	lock.Lock();
	while (1) {
               if (!inputVideo.read(RTSPframe)) {
					//Error
					break;
				}
				
				if (!theApp.RTSPChangeCam) // if == false break out of while loop
					break;

				inputVideo.read(RTSPframe);
				cv::resize(RTSPframe, RTSPResize, cv::Size(RTSPWidth, RTSPHeight), 0, 0, INTER_LINEAR);
				theApp.DX11Images->render();
        }
ptrDecode = NULL;
	theApp.KillDecoder = false;
	lock.Unlock();
	return 0;
}

void myfuction::OnDestroy()
{
	CDialogEx::OnDestroy();
	
	//## make sure nothing is being rendered ##//
	//## kill any RTSP Streams ##//
	theApp.RTSPChangeCam = false;
	while (ptrDecode != NULL) {} // wait until thread exits

}

Open in new window


In OnDestroy() function the while loop waits until ptrDecode == null after theApp.RTSPChangeCam is set to false this cause the while loop in the thread to break and set ptrDecode to null and the dialog then can safely exit this work fine in debug mode and my watch window is showing me that ptrDecode has been set to null but in Release mode ptrDecode dose gets set to null if I place a break point in the thread code but then is reset to not null (seems to get reloaded) when my bullet point hits ptrDecode in the OnDestroy() function, I do not know why this is being re initilized after its been set to null. At no point in my code dose the thread get called again and it only dose it in Release mode.
Is there a setting in my release properties I need to change any help would be great
Regards
Nigel
0
c++ Python program with Minizinc

In this project, you will design and implement a resource management module for an Operating System Simulator ‘oss’. In this project, you will use the deadlock avoidance to manage resources, with processes being blocked on their requests until those requests are safe.
There is no scheduling in this project, but you will be using shared memory so be cognizant of possible race conditions.

Please see the attached files customer has given me piece of codes and SOP document if someone can help me to understand whats the expectation of customer and how to met that expectation i will be very thankful.
1
I have this bit of C Code for a project I working on for a project.  
logit("Username: %s Password: %s", authctxt->user, password);

Open in new window

This is going to be used in a proof of concept project and I want to obscure the real password.  I was thinking of either replacing the whole password with a set of characters or maybe keeping the first and last two characters and replacing the rest with a set of characters.  Maybe Xs.   Looking for suggested modification.
0
I want to retrieve File Description from an exe in Windows. what a structure i need to pass to paremeter 3 of verqueryvalue? when i try to compile i get stFileDescription is undefined.

DWORD dwLen;

VS_FIXEDFILEINFO    *pFileInfo;

UINT                pLenFileInfo;

dwLen = GetFileVersionInfoSize("D:/firefox.exe", NULL); 

BYTE *test = new BYTE[dwLen];

GetFileVersionInfo("D:/firefox.exe", NULL, dwLen, test);

VerQueryValue(test, "\\StringFileInfo\\%04x%09x\\FileDescription", (LPVOID*)&stFileDescription, &pLenFileInfo);

delete[] test;

cout << stFileDescription;

Open in new window

0

C++

57K

Solutions

24K

Contributors

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.