C++

56K

Solutions

46

Articles & Videos

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 want to write an application that can read/query Windows Explorer and list multiple files that are selected. My program will launch from the right-click context menu.

I have tried by reading the command line using GetCommandLine(), and that works fine. Except it launches a new instance of the program for each file selected.

Some guidance would be appreciated.
0
Free Tool: Port Scanner
LVL 9
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.  

Consider stack starting address 0x5000 0000.  The stack size is 0x2000.  

If I take current stack pointer minus 0x2000, will that create stack exception?  If yes, what might be 'C' or assembly language code that will achieve this?

My thought is if I subtract negative 0x2000 from current stack pointer or add 0x2000 to current stack pointer, I'll be outside stack and stack exception will occur ?

 I need to set program counter to illegal address, i.e. 0x00FF FFFC.  Can this be done with assembly language instructions?
 If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running.
0
The below code is translated from C++ to C# but the row,  mask = -(crc & 1);  will not be compiled. Cannot implicitly convert type  'long' to 'uint'. If I change from uint to long I get the wrong result.  How can this be solved?

private uint crc32(byte[] message, int len)
{
      int i;
      int j;
      uint @byte;
      uint crc;
      uint mask;

            crc = 0xFFFFFFFF;
            for (i = 0; i < len; i++)
            {
                  @byte = message[i];
                  crc = crc ^ @byte;
                  for (j = 7; j >= 0; j--)
                  {
                        mask = -(crc & 1);
                        crc = (crc >> 1) ^ (0xEDB88320 & mask);
                  }
            }
            return ~crc;
}
0
Hi Experts,

I have a base class that has a virtual method named Call as follow:
template<typename A, typename B>
class BaseFunc
{
public:
	virtual B Call(A in1)
	{
		B b;
		return b;
	}
};

Open in new window


Then I create a new class derived from the base class as follow:
class AnimalName :
	public BaseFunc<Animal, std::string>
{
public:
	virtual std::string Call(
		const std::shared_ptr<Animal> &customer);
};

Open in new window


The class Animal is created in two files; Animal.h and Animal.cpp. The Animal.h file content is as follow:
class Animal
{
public:
	static std::vector<Animal> animals;
	int id = 0;
	std::string name = "";

	Animal();

	static std::vector<std::string> GetAnimalNames();

	template<typename T>
	static std::vector<T> GetAnimalByFunction(
		const std::shared_ptr<BaseFunc<Animal, T>> &funct);
};

Open in new window


And the Animal.cpp file content is as follow:
#include "Animal.h"

using namespace std;

vector<Animal> Animal::animals;

Animal::Animal()
{
}

string AnimalName::Call(
	const shared_ptr<Animal> &animal)
{
	return animal->name;
}

vector<string> Animal::GetAnimalNames()
{
	return Animal::GetAnimalByFunction<string>(
		make_shared<AnimalName>());
}

template<typename T>
vector<T> Animal::GetAnimalByFunction(
	const shared_ptr<BaseFunc<Animal, T>> &funct)
{
	vector<T> returnList;
	for (auto customer : Animal::animals)
	{
		returnList.push_back(
			funct->Call(customer));
	}
	return returnList;
}

Open in new window


Now, I  have a main.cpp file as follow:
#include <iostream>
#include "Animal.h"

using namespace std;

void SetAnimals()
{
	int i = 0;

	vector<string> animalNames;
	animalNames = {
		"Peanut",
		"Coco",
		"Rocky",
		"Harley",
		"Pepper",
		"Roxy"
	};

	for (auto name : animalNames)
	{
		Animal a;
		a.id = i++;
		a.name = name;
		Animal::animals.push_back(a);
	}
}

int main()
{
	Animal a;

	SetAnimals();

	cout << "Animal names:" << endl;
	vector<string> animals =
		a.GetAnimalNames();
	for (auto name : animals)
	{
		cout << name << endl;
	}

	return 0;
}

Open in new window


When I run the code, I get no animal names since the Call() method is invoked from the base class (BaseFunc) instead of the derived class (AnimalName).

The following is my console snapshot:The result
How can I override the Call method in BaseFunc class?
override.zip
0
I have Visual Studio 2012, and Sql server 2012. I need to create a simple C++ application with a GUI that will access a Sql server database.

I created an MFC application and it has a simple dialog box with buttons on it. One of the buttons is named "Connect". When the Connect button is pressed I need to connect to a sql server database and pull back data. So how can I access sql server from an MFC application?

Can someone with C++ experience on Windows help me out, because I have googled for an answer and still do not know how to connect to a sql server database from an MVC application.
0
Is it a good practice to specify the thread size at the time of the thread creation ?

I thought that this is better handled by the OS.
Any reference to this ?

Thanks
0
Hi there,
I am trying to update a Windows 10 laptop and am getting this error:
Security update for Microsoft visual c++ 2008 redistributable package (KB973924) – Error 0x80246003
I have tried downloading it manually and installing it.
I have tried deleting the windows update software cache
does anyone have any ideas?
Thanks for your help,
Shaun
0
I need to write a C++ program that will run on MS Windows. So it will need a graphical user interface and it will not be web based.

So will this be an MFC application, since it needs a GUI? Or is there an alternate way of creating a project that does not rely upon an MFC based application?
0
Hello Experts,

Todays issue :)

I app APP_SERVER and APP_CLIENT.  APP_SERVER has an ATL-COM server that APP_CLIENT uses.  I use VS2013. If I run both apps from separate VS2013 IDE's, everything works. If I run  APP_SERVER from double clicking the executable and then run APP_CLIENT from the IDE, it throws an exception when trying to use (after it creates) the COM object. If I run  APP_SERVER  from the IDE and run APP_CLIENT by double clicking on it, the same exception is thrown. So the only condition that works is running both APP_SERVER and APP_CLIENT from the IDE.

I do not understand what it causing this.

Thanks, Brian

I've attached the exception message as a JPGexception mesage
0
Hello experts,

I have a TLB that exposes the interface IA.

I have a class CA that looks like this
//----------------MyCA.h
class CA
{
    CA();
    IA* my_ia;  ////compiler does not knowtype IA
}

//--------------MyCA.cpp

#Import "myia.tlb" named_guids no_namespace
#include "MYCA.h"

CA::CA()
{
    my_ia->somefunction();
}

here is my problem. In the CPP file for class CA, I import the TLB, but my header does not know the type IA. Can someone explain to me how to declare a variable of type IA inside my class CA?

using : VS2013 Pro
            Windows 7 Pro

Thanks, Brian
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

My work Environment : Qt 5.8 MSVC2015 64bit, QT GraphicsView, Windows 7 64 bit

I am loading red image from buffer (a demon process is going send a image buffer),
but it failed to create image from buffer.

QFile file("D:\\2.png");
if (!file.open(QFile::ReadOnly))
    qDebug() << "Error failed to Open file";

QByteArray array = file.readAll();  ///data is recived here.

array = array.toBase64();
QImage tempimage((uchar *)array.data(), 250, 250, QImage::Format_RGBX8888);
if (tempimage.isNull()) {
    qDebug() << "Error!!! failed to create a image!"; 
}

Open in new window


Refer below  red image is original image &  other is distorted image.

It always print distorted image. Any idea what I am missing here ?
distorted imageOriginal Image
1
Hello

In the CMakeLists.txt , for cmake version 2.8, I am doing a message("hello world!") , right under PROJECT(myprojectname).

However hello world is not printing out to the console when i run ./configure. Why?
0
Hello Experts,

I have MFC_COM_APP1 which is an standalone application that implements an ATL COM object. I also have MFC_APP2 which is a standalone app the gets the ATL COM object from MFC_COM_APP1. If I run MFC_COM_APP1 and then run MFC_APP2, everything is fine. I see both applications and the COM object is working. However, If I only run MFC_APP2, it starts  MFC_COM_APP1and gets the COM object, but MFC_COM_APP1 does not display its form. I can see the NFC_COM_APP1 running in task manager, but it is not visible. Is there a way that when MFC_APP2 gets its COM object, that the MFC_COM_APP1 the application form will show?

Thanks, Brian

Using:
VS2013 Professional
Windows 7 Pro
0
Hello,
I'm a beginner so have became stuck with this here problem, the program i have begins with Form1 in which opens Form2. On Form2 i have a couple of Textboxes which store into Int and Strings. After the Form2 is finished with it is closed. How do i get those variables back to Form1?


Many Thanks
0
I am trying to build nodejs from source code.

WARNING: C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=g++)
creating ./icu_config.gypi
* Using ICU in deps/icu-small
Using version-specific floating patch tools/icu/patches/58/source/i18n/digitlst.cpp
creating ./icu_config.gypi
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'asan': 0,
                 'coverage': 'false',
                 'debug_devtools': 'node',
                 'force_dynamic_crt': 0,
                 'gas_version': '2.20',
                 'host_arch': 'x64',
                 'icu_data_file': 'icudt58l.dat',
                 'icu_data_in': '../../deps/icu-small/source/data/in/icudt58l.dat',
                 'icu_endianness': 'l',
                 'icu_gyp_path': 'tools/icu/icu-generic.gyp',
                 'icu_locales': 'en,root',
                 'icu_path': 'deps/icu-small',
                 'icu_small': 'true',
                 'icu_ver_major': '58',
                 'node_byteorder': 'little',
                 'node_enable_d8': 'false',
                 'node_enable_v8_vtunejit': 'false',
                 'node_install_npm': 'true',
                 'node_module_version': 48,
                 'node_no_browser_globals': 'false',
                 'node_prefix': '/usr/local',
   …
0
i need to read a path from a dll created in visual studio c++ 2010 in LABWINDOWS CVI (C)
.h is
 #ifndef IMAGE_H_
#define IMAGE_H_   

#ifdef COMPILING_DLL  
#define DLLEXPORT __declspec(dllexport)  
#else  
#define DLLEXPORT __declspec(dllimport)  
#endif  

#ifdef __cplusplus
extern "C" {
#endif

DLLEXPORT char* __cdecl read();

#ifdef __cplusplus
}
#endif

#endif[

Open in new window


and .cpp

#include "D:\opencv3.0\opencv\build\include\opencv2\highgui\highgui.hpp"
#include "D:\opencv3.0\opencv\build\include\opencv2\core\core.hpp" 
#include <iostream>
#include "image.h"
#include <stdexcept>

#define COMPILING_DLL
using namespace cv;
using namespace std;


	char*__cdecl read()
{char* path = " C:\\Users\\eouerten\\Desktop\\visual_cvi\\essai_visual_cvi\\essai_read\\cat.jpg";
    Mat mat = imread(path, CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'

    if (mat.empty()) //check whether the image is loaded or not
    {
        cout << "Error : Image cannot be loaded..!!" << endl;
        //system("pause"); //wait for a key press
        return path;
    }
	}

Open in new window


the main .c is

#include <ansi_c.h>
#include "image.h"

int main()
{

    char* p=read();
    getchar();
    printf("l'adresse de l'image est %s" ,p);
  return 0;
}

Open in new window

Result : build succeeded but the problem that i can't run it :erreur 0xc000007b i verified all dll like mscvp100.dll but it's not the problem
0
NEED THE CODE SOURCE OF DES AND VIGINERE CIPHER ON SAME SOFTWARE
0
I'm playing around with VS Community 2015 VC++, and when I try to step into PrintDlgEx() to find out why my code is failing, it tells me that the source isn't available.

Is this because I'm using a free version, or is something else going on.  Originally, I was getting an error due to a missing pdb file, but I got that loaded by clicking Microsoft Symbol Servers.

Is there a way to get that source?
0
Hi experts,

I have the following question

I have an array

vector<long> v = {5,7,2,10,4,6};

I did the Bit wise operation & of the first 4 numbers

5&7&2&10 = sum

now I need a sliding window i.e.
compute 7&2&10&4

I need  to perform the operation by removing first element and adding last element , how can I achieve that using bitwise operations ?

   something like  newSum =  ???sum&4,

I tried newSum = (~7)|(sum&4) but it gave a negative result .

Thanks
0
[Webinar] Learn How Hackers Steal Your Credentials
LVL 9
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

no clue how to do this question, someone please help me.
homework7.docx
0
Hi Guys,

I need help to perform the following
I have a the following class that has 3 functions with same name but different parameters type
class A : public ParentClass {
 void handleEvent (EventA ){}
void handleEvent(EventB){}
void handleEvent(EventC){}
}
Is there a way to store them in a map as function pointer and then call them back based on the type of event received ?

I was going to do :
Map<string, void*> map;
Map[eventAId] = &handleEvent  // here is the issue all the functions have the same name
Is there a way to fix that ?

I am using C++ 11 and stl library.
0
Fresh install of Windows 10, 64 bit. Installed Visual C++ Redistributable for Visual Studio 2015. Ran sfc /scannow
0
I am using Embarcadero XE10.1 Berlin C++ builder running on widows 7 Professional 64 bit and have a problem using a third party component. When compiling the Demo project from the component supplier ( an Android multi-Device project ), I get an error which is created by the Winapi.windows.hpp file (called for by the demo program) in the folder C:\Program Files (x86)\Embarcadero\Studio\18.0\include\windows\rtl

The header file would appear to have been created when the compiler was installed.

Where does WINVER get defined and what value would you expect from windows 7 professional 64 bit ?

The first few lines of the header file are shown below.

I have tried #defining WINVER to a value of 0x400 in the project source file but the error is still generated.

// CodeGear C++Builder
// Copyright (c) 1995, 2016 by Embarcadero Technologies, Inc.
// All rights reserved

// (DO NOT EDIT: machine generated header) 'Winapi.Windows.pas' rev: 31.00 (Windows)

#ifndef Winapi_WindowsHPP
#define Winapi_WindowsHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member 
#pragma pack(push,8)
#include <System.hpp>
#include <SysInit.hpp>
#include <System.Types.hpp>
#include <System.UITypes.hpp>

//-- user supplied -----------------------------------------------------------
// WINVER check BEGIN 
#if (WINVER < 0x0400)
  #error WINVER < 0x0400 //  <<<<<<< This generates the compile error

Open in new window

0
Hello,
In this C++ statement; T∗ begin(Vector<T>& x)  what is & doing, or supposed to do?
Thanks
0
Hallo,
I have written this program with mfc c++ and it looks nice on a 4:3   17 inch screen.
Every screen/display works from 1280 x 1024 to 800 x 600.

On an 16:9   22 inch screen the pictures on my bitmaps are looking much to big.
Every screen/display will have this bad look.

This is the nice look of a 4:3  17 inch screen:

4 : 3   17 inch screen


This is the bad look of a 16:9  22 inch screen:

16:9   22 inch screen


Can you help me to fix this?
500 points with a solution.

Best regards,
Thomas
0

C++

56K

Solutions

46

Articles & Videos

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.