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 have a C++ class that needs to get information from an oscilloscope for analysis. I have the code that issues the command to the o'scope and can see the o'scope getting the info. Here is that code:

void CbeLecroy::GetScaledWF(LCHAN channel, int numpoints, VARIANT* rvals)
{
	waveform.Attach(activeDSO->GetScaledWaveform(bCHANNEL[channel], numpoints, 0));
	rvals->parray = waveform.parray;
	float* pfloatVals;
	HRESULT hr;
	hr = SafeArrayAccessData(rvals->parray, (void**)&pfloatVals); // direct access to SA memory

	if (SUCCEEDED(hr))
	{
		long lowerBound, upperBound;  // get array bounds
		SafeArrayGetLBound(rvals->parray, 1, &lowerBound);
		SafeArrayGetUBound(rvals->parray, 1, &upperBound);

		fvec.clear();

		long cnt_elements = upperBound - lowerBound + 1;

		for (int i = 0; i < cnt_elements; ++i)  // iterate through returned values
			fvec.push_back(pfloatVals[i]);

		SafeArrayUnaccessData(rvals->parray);
	}
//	SafeArrayDestroy(psa);
}

Open in new window


The calling function looks like this:
    VARIANT rvals;
	comLecroy->GetScaledWF(channel, numpoints, &rvals);

Open in new window


When I breakpoint in the top function, I can see valid data in the loop:
		for (int i = 0; i < cnt_elements; ++i)  // iterate through returned values
			fvec.push_back(pfloatVals[i]);

Open in new window


However, when I exit the called function and return to the calling function, I get an exception. Any ideas why?

Thanks, Brian
0
Enroll in June's Course of the Month
LVL 8
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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
Hi,
I have a problem with custom templates not creating solutions correctly. It works fine on my Home computer but not on my office computer. I have reinstalled VS 2015 several times but problem remains. The issue is the "Location" and "Solution Name" dialog are not visible nor are the "Create directory for solution" or "add source to control" checkboxes and browse button.

Below is an example of what happens and below is one of the template files (this effects several new project templates under c++).

If I select New -> Visual C++ -> Empty Project, I get the following dialog at bottom of window (You can see that "Location Field" is Enabled and yet it does not show when I create a new project)



Name: Project 1
Location: C;\users\david\visual studio 2015\projects
Solution Name : Project 1
Also a "Browse" button, "Create directory for solution" checkbox and "add to source control" checkbox.

If I select New -> Visual C++ -> Particle Project (which is one of the custom projects) I get

Name : Sketch1

All the other dialogs and checkboxes are missing.

BUT, When I am on my computer at HOME, I see all the correct solution name, location and checkboxes ok, but NOT on my OFFICE computer.

I am sure it is related to some setting in a file somewhere that is overriding the parameters for the VM template but don't know which file will be controlling this behavior.

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" …
0
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
My work Environment :Qt 5.8 MSVC2015 64bit, QT GraphicsView, QGraphicsRectItem, Windows 7 64 bit.

Issues : When I zoom in & zoom out on GraphicsView, I call GraphicsView scale method. But When I add QGraphicsRectItem to scene it failed to call its paint method.

my class hierachy :

  class GraphicsView : public QGraphicsView
  class mySquare : public QObject, public QGraphicsRectItem
  class Scene : public QGraphicsScene 

Open in new window

Code :

//////*****Draw Rect in QGraphicsRectItem *****////////////

void mySquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
      QRectF rect(0,0,_width,_height);
      painter->drawRect(rect);
}

Open in new window


 
 void GraphicsView::wheelEvent(QWheelEvent * event)
{
    int angle = event->angleDelta().y(); // angle will tell you zoom in or out.
    double scaleFactor = 1.15; //How fast we zoom
    setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
    if (angle > 0)
    {
        qDebug()<<"Zoom in";
        scale(scaleFactor, scaleFactor);
    }
    else
    {
        qDebug()<<"Zoom out";
        scale(1.0 / scaleFactor, 1.0 / scaleFactor);
    }
        mySquare  _square = new mySquare(0,blankImage);
       _square->setPos(QPointF(0, 0));
       //add square to scene. 
] //Bug!!! Why after scale function call, _square failed to draw rect in paint method.
]        _scene->addItem(_square);
        _square->update(); 
}

Open in new window


My git gitcode
I spend days & hours but still not able to find out why it QGraphicsRectItem failed to print, when scale method get called. Any suggestion is highly appreciated ?
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
I have installed a C++ add-on to Visual Studio that enable code to be developed for Particle Electron and Photon devices. I have an issue that I believe is more related to Visual Studio than the plug in.
First I installed the plug-in on my home PC (running Windows 10, 64 bit OS) and VS 2015. All worked fine.
I then copied the same steps on my office PC (also running Windows 10, 64 bit OS) and VS 2015 but when I attempt to create a project I get no option to enter solution name or location and the checkbox to create a directory is also gone. When I proceed, I get a project but no solution and then I can never save the project. I can only exit VS if I discard the project.
What-is-should-look-like.JPG
what-is-does-look-like.JPG
0
Hi All,

I want to change the face color of property sheet wizard button. The wizard has ID_WIZNEXT, ID_WIZFINISH and other default button. the button label and position is changed. i want to change the color of this default button.

class CDiskSanPropertySheet : public CPropertySheet
{
}


BOOL CDiskSanPropertySheet::OnInitDialog()
{
      CPropertySheet::OnInitDialog();

        CButton *tmpButtonNext = reinterpret_cast<CButton *>(GetDlgItem(ID_WIZNEXT));
      CButton *tmpButtonFinish = reinterpret_cast<CButton *>(GetDlgItem(ID_WIZFINISH));
      CButton *tmpButtonBack = reinterpret_cast<CButton *>(GetDlgItem(ID_WIZBACK));
      CButton *tmpButtonCancel = reinterpret_cast<CButton *>(GetDlgItem(IDCANCEL));

        buttonString.LoadStringW(IDS_TEXT_BUTTON_NEXT);
      tmpButtonNext->SetWindowTextW(buttonString.GetBuffer());
      
      buttonString.ReleaseBuffer();

        LONG rightPos, nextRightPos;
      
      //inc. to 1.7 for greek issue
      MoveButton(tmpButtonCancel,shiftFactorX, 1.7,NULL,tmpButtonNext,&nextRightPos);
      MoveButton(tmpButtonFinish,shiftFactorX, 1.7,NULL,NULL,NULL);

      rightPos = nextRightPos;

      MoveButton(tmpButtonNext,shiftFactorX, 1.7,&rightPos,tmpButtonBack,&nextRightPos);
      
      rightPos = nextRightPos;
      
      MoveButton(tmpButtonBack,shiftFactorX, 1.7,&rightPos,NULL,NULL);

}

HBRUSH CDiskSanPropertySheet::OnCtlColor(CDC* pDC, CWnd *pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CPropertySheet::OnCtlColor(pDC,pWnd, nCtlColor);

    COLORREF myColor = …
0
I installed C++ builder 6.0 on windows 10.
when I reopen a project , my working directory don't change to new project path and my new forms create on the directory that last time I used "FILE->Open Project" method.
if every body knows how can say to it change to the project path after reopen .
-- thanks reza
0
Hello Experts, I have a routine in a C++ application the creates a named  shared memory view of a structure:

struct TEST_STRUCT
{
	long 			tnum;
	unsigned long 	pass_count;
	unsigned long 	fail_count;
	unsigned long 	try_count;
	double 			sum_result;
	double 			sumsq_result;
	double 			min;
	double			max;
	unsigned 		histogram[HISTOGRAM_SIZE];
	bool 			tested;
	bool 			passed;
	double 			last_result;
};

Open in new window


The C++ application puts data into the named shared memory structure and then sets a windows named event for another process to read the same structure. That other process was written in C++ and works fine. I now need to do the same thing as the reading process, but in c#. Can you tell me how to create a TEST_STRUCT variable in c# that can be used to access the C++ named shared memory?

Thanks, Brian

Windows 7 Pro
VS2013
0
Technology Partners: We Want Your Opinion!
Technology Partners: 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!

the array has series of numbers Need to find all pairs in the array using a hash table
integers ...
0
I'm making windows form called form2.h that has a trackbar and a label on it. I've pass the trackbar value to the label

System::Void trackBar1_Scroll(System::Object^  sender, System::EventArgs^  e) {
                        label2->Text = String::Concat( "", trackBar1->Value );
                   }

I also have a cpp file called form2.cpp and I want to use label2 from form2.h in my cpp file.
for example
string hmin = label2;
cout << hmin;

How do I do that? I already include things like

#include "StdAfx.h"
#include "Form2.h"
#include "stdio.h"
using namespace messagebox;

on top of the cpp file but I still cant use label2 element
0
I wish to implement interactive gesturing (Zoom)  in an android application that uses an FMX TGrid control. so far I have not succeeded.

The Embarcadero documentation for enabling Firemonkey  Interactive gesturing is as follows :
Enabling Standard Gestures To add support for standard gestures for a control, you need to do the following:

In the Form Designer, add a TGestureManager to the control you want to enable for gestures. Either give the GestureManager a unique name or just use its assigned name, such as GestureManager1.
In the Object Inspector, assign the TGestureManager in the Touch | GestureManager field of the control.
In the Object Inspector, select the specific custom gesture(s) from the Touch | Gestures field of the control.
Implement the OnGesture event procedure for the control and handle the appropriate EventInfo.GestureId.

I am stuck in " Implementing the  OnGesture event procedure for the control and handle the appropriate EventInfo.GestureId"

Any help would be appreciated.

I am using C++ Builder XE10.1 Berlin
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
Hello,
i sukkel with a problem,
whit i add a void call.

for a good look you can view the print screen.

HDC hdc;
TCHAR halloworld[] = _T("Hallo World\n - nadir81");
....
..
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);

		
TextOut(hdc, 10, 10, halloworld, _tcslen(halloworld));

//  The Test void i need to add. 
 test( 20,20 , "text"); 
		
		
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);



void test(int x, int y,const char text_valuta)
{
	HDC hdc;
	TextOut(hdc, x , y , text_valuta, _tcslen(text_valuta));

}

Open in new window

Capture.GIF
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,

I have "tree" include file that not wanna associate with the cpp file.
..
.....
#include <stdio.h>
#include "../sys/pcsc.h"  <<  fatal error C1083
#include "/sys/util.h"  <<  fatal error C1083
#include "sys/clessCardType.h" <<  fatal error C1083
....
..

i tried three different ways to link the in the cpp file.

print screen added
Capture.GIF
0
I want to invoke a python script from my C++ app and get the data from the python script into my C++ app. How do I do this?

example: testing.py   reads data from and ADC -

C++ app - invoke testing.py  ; data = python testing.py
0
Free Tool: ZipGrep
LVL 8
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Hi guys.

I have Form1.h and Test.cpp files in my project which was generated by VS. I have around 5 functions in my Test.cpp file and each function has to update the label with its result. I've made the label1 public on my Form1.h file and with this solution I am now able to write to the label1 outside the h file, I mean I can write to the label1 from .cpp file but only when the application is starting up or should I say only from the main function. I've used the solution provided on this post here and now my problem is that I can not use the same approach on other 5 to 6 functions as this approach also uses the
Application::Run(form);

Open in new window

which I don't think is appropriate to keep calling this from each and every function that needs to update the label.

The updates are based on the App returned results for each and every function its execute.
0
Hello Experts,

I wasn't sure what the terminology for this is, so I will use a CPP example:

class CA
{
public:
   void setvalue(double newvalue);
};

class CB
{
public:
    void setvalue(double newvalue);
};

class CMainClass
{
public:
        CA* Aobj;
        CB* Bobj;
};

later in my main code I would do this:

CMainClass* my_main = new CMainClass;  (assume that the objects Aobj and Bobj get created in constructor)

my_main->Aobj->setvalue(2.0);
my_main->Bobj->setvalue(3.0);


The above code is simple and pretty straight forward. Now the question, Can I do this as a ATL COM server? That is, have a ATL COM class that is used like CMainClass, with object in it that represent CA and CB (but in ATL COM format).

And please let me know what the terminology is for this kind of objects inside another object.

Thanks, Brian
0
Hello I'm using C++ builder 10 and I need to bold (highlight) the last value that comes into advmemo from  advcombobox/advedit.
Maybe somehow with using AdvMemo->SyntaxStyles->HighlightStyle?
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

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.