Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

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

Hi,

I want to Add Right Click Context Menu  for only one Folder (e.g. C:\MyFolder\)

If i right click on any file inside C:\MyFolder, My Context Menu need to display. Outside C:\MyFolder no need to display My Context Menu. (like dropbox context menu for only one folder)

I am able to global Context Menu but not able to specific Folder Context Menu.


thanks

Kalpesh
0
I have a query on Memset, which one we need to use 0x00 or 0

Ex:
char myname[512]; //created a character array and wants to memset it
//Is there any difference in the below lines:
memset (&myname, 0, sizeof(myname));
memset (&myname, 0x00, sizeof(myname));  //some are saying we should use only this. 0x00 will be replaces the string with NULL.

I feel both are same. 0x00 will be converted into int as memset takes 2nd argument as int.

I have seen the visual studio also used both. so where we need to use these two types of memsets? 0x00 in which situation and 0 in which situation.?

 C:\program files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcoll.h(2948):      
memset( ppBins, 0, nBins*sizeof( CNode* ) );
  C:\program files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcoll.h(3554):      
memset(m_pNil, 0x00, sizeof(CNode));

Please clarify in detail.
0
Hello,

i have a list of thousand of different IDs. A sample:
static struct
{
  TCHAR org_openbddb[41];
  TCHAR cross_openbddb[41];
} openbddb_matrix[] = {
/* The ISO 639 language codes.
 */
	{_T("ec62b87bfd5585ac8be5c7fb0cbba1ce6a29c0bd"), _T("ec62b87bfd5585ac8be5c7fb0cbba1ce6a29c0bd")}, 


};

Open in new window


I need to search the value "org_openbddb" in the list and return the "cross_openbddb" value if found. If nothing found, return "". Any ide how to do this?
0
Hi

I have a class hierarchy as follows:
A (parent)->B(child)


I create an object A. A a=new A();

Somewhere, later in the code, I want to create an object B, called b, and want to specifically assign the object a as its parent. Is there a way to do this in C++?

Normally, I would do something like this:
B b=new B();

B's constructor would make a call to A's constructor
B::B()
:A(){
}

But if i have a parent object already instantiated, is there a way to assign that particular object as a child object's parent at the time the child is instantiated?

thanks
0
I'm using Keil uVision version 4.73.  In my Options for Target I select RTX Kernel Operating System.  This selection will add following to the Linker Control String in the Linker Tab:

C:\Keil\ARM\RV31\LIB\RTX_ARM_L.LIB
This means this operating system library will be linked when I build my project.  In addition to linking this library, I have added all files used to create this library to my project as follows:

rt_Event.c
HAL_ARM.c
...

These files are in  C:\Keil\ARM\RL\RTX\SRC\ARM  folder.

Why does my build work ?   I'm including same Operating System twice.  Shouldn't I get re-defined symbols ?
0
Hi Experts,
We need to check if an exe file is already rinnung/working,
 if not then launch it from our App.
Important not to have two instances of the same App at the same time.

Can you help us with some source that can do this in visual basic ?
Regards!
0
As of today, 24th Feb 2014 I am retiring my tenure as an Expert and Community Helper with EE. I no longer have the time nor the motivation to continue with my membership.

I just wanted to post this final message to say farewell to my fellow experts and those that I might have helped during my 10 years here.

So long and thanks for all the fish :)
0
Hi

I receive the error when trying to comile, it mentions that "addSoft" is of non-class type "SoftList*".
I am trying to create a container which I want to write to and read from and am getting stuck trying to understand how to access this container.


#include "softwriter.h"
#include "softList.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>

SoftWriter::SoftWriter(){
   
}

void SoftWriter::write(Soft &s){
       sl.addSoft(s);
}
QString SoftWriter::read()
{
    QFile file(fileName);
    file.open(QIODevice::ReadOnly | QFile::Text);
    QTextStream in(&file);
    QString line = in.readLine();
    do
    {
        qDebug()<< line;
        line=in.readLine();
    }while(!in.atEnd());

   file.close();

}

Open in new window


#ifndef SOFTWRITER_H
#define SOFTWRITER_H

#include "soft.h"
#include "softList.h"
class SoftWriter{
public:
    SoftWriter();
    void write(Soft& s);
    QString read();
private:
    QString fileName;
    SoftList* sl;
};
#endif // SOFTWRITER_H

Open in new window


#ifndef SOFTLIST_H
#define SOFTLIST_H

#include <QList>
#include "soft.h"

class SoftList : public QList<Soft*> {

  public:

    SoftList();

    Soft* addSoft(Soft* s);

    void deleteAll() {qDeleteAll(*this);}

};
#endif // SOFTLIST_H

Open in new window


#include "softlist.h"

SoftList::SoftList(){}

Soft* SoftList::addSoft(Soft* s) {
        append(s);
    return s;
}

Open in new window

0
Hi All,

Can someone please tell me the single most efficient way to clear the keyboard buffer in C++?  I found the following but don't know if it's efficient:

cin.ignore(numeric_limits<streamsize>::max(), '\n');

Some background:  I'm a college student in 1st Semester OOP.

- Thanks
0
Hello,

inside an external DLL I have a function to set a RGB Buffer for a logo to render. This function is:
 void       SetLogo(unsigned char *RGBBuf, int width, int strideLen, int height); // sets the actual logo 

Open in new window


The description of this function is:
RGBBuf is a bitmap buffer, which contains a large bitmap width * height. Because Windows bitmaps still have padding inside, one must also specify strideLen in bytes, that is the line size. Without padding the line size is width * 3, with padding it varies between width * 3 + 0 and width * 3 + 3

I use now following code:
void CDVDConverterWork::GetImageForLogo()
{
	HBITMAP hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_OVLLOGO), IMAGE_BITMAP, 0, 0, 0); 

	BITMAP bm;
	::GetObject( hBitmap , sizeof(bm) , &bm );

	/* Omitting error checks for brevity */
	HDC dcBitmap = CreateCompatibleDC ( NULL );
	SelectObject( dcBitmap, hBitmap );

	BITMAPINFO bmpInfo;
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmpInfo.bmiHeader.biWidth = bm.bmWidth;
	bmpInfo.bmiHeader.biHeight = -bm.bmHeight;
	bmpInfo.bmiHeader.biPlanes = 1;
	bmpInfo.bmiHeader.biBitCount = 24;
	bmpInfo.bmiHeader.biCompression = BI_RGB;        
	bmpInfo.bmiHeader.biSizeImage = 0;  

	 
	unsigned char* retArray = new unsigned char[bmpInfo.bmiHeader.biSizeImage];

	//LPVOID retArray = malloc(bmpInfo.bmiHeader.biSizeImage);
	GetDIBits( dcBitmap , hBitmap , 0 , bm.bmHeight , retArray , &bmpInfo , DIB_RGB_COLORS );

Open in new window

0
I have C++ based java native methods that works perfectly in passing String parameters back and forth with Java but wanted to know how could i load the C library from this C++ program and pass the parameters into it and get return string back from it.

The reason I want to not interact with C directly is because I need to pass 32 string parameters and handling them may be a challenge. If there is a easy way to handle 32 parameters in C  that will be great.
0
HI Experts,

I'm curious to know what's the best regarded way to write code for cross platform when using Qt?  Do most people choose Visual Studio for Windows and most use gcc on linux, all with the same source, but with different projects?  Or do these projects all compile from makefiles that are recognized by most major compilers?  It doesn't seem like you write once, build anywhere...  Seems more like write once, write again, fix up tweak, tweak some more...  Am I missing something?

I'd love to hear some of your tricks of the trade.  Even if you don't think they're the best -cuz they're probably better than you think...

Thanks,
Mike
0
Ah hello.

I am reading about 64bit programming, and found the site http://www.viva64.com/en/a/0065/ (Example 17) which describes an issue:

"Consider one more kind of the error related to signed and unsigned types. In this case, the error will immediately cause a program crash instead of a wrong comparison operation.

LONG p1[100];
ULONG x = 5;
LONG y = -1;
LONG *p2 = p1 + 50;
p2 = p2 + x * y;
*p2 = 1; // Access violation

The "x * y" expression has value 0xFFFFFFFB and its type is unsigned. This code is efficient in the 32-bit version since addition of the pointer to 0xFFFFFFFB is equivalent to its decrement by 5. In the 64-bit version, the pointer will point far outside the p1 array's boundaries after being added to 0xFFFFFFFB (see Figure 16)."


Now, LONG and ULONG are 32bits, so the result of (x * y) will be a 32 bit value.  When we add this to the 64bit pointer value p2, I don't see why it suddenly becomes 64 bits (hence 0x000000000FFFFFFFB, which is not -5).  I have looked at https://www.securecoding.cert.org/confluence/display/seccode/INT02-C.+Understand+integer+conversion+rules, but cannot see what rule is being applied.  (Maybe I have looked at this for too long however!)

Can someone please explain?
0
I created Java native method written in C++ on windows as suggested in:
 
Java programming with JNI

I creatde dll and it works on windows.
However how do we create and deploy the same shared lib on AIX 6.1 environment.  and how we set path to make the shared library accessible to web applications.
0
Dear Experts,

I'm porting application from C++ to C#.
In C++, it used InitializeCriticalSection (Win API) in controlling threads.
It also used the structure
typedef struct _RTL_CRITICAL_SECTION { 
    PRTL_CRITICAL_SECTION_DEBUG DebugInfo;   

    // 
    //  The following three fields control entering and exiting the critical 
    //  section for the resource 
    // 

    LONG LockCount; 
    LONG RecursionCount; 
    HANDLE OwningThread;        // from the thread's ClientId->UniqueThread 
    HANDLE LockSemaphore; 
    ULONG_PTR SpinCount;        // force size on 64-bit systems when packed 
} RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;

Open in new window

How can I porting this to C#.
Are there any substitution in C#

Please help.
Regards.
0
Hello,
I'am looking for a method to encrypt a string with XOR to a usable string to save this to a file.
Later read the string from file and decrypt to original. Save and read from file is no problem but how to XOR a string to something that has no special characters?
Source is a char array.
0
I need to hide a plain text AES key in my code, For this I think about to use a XOR decrypting or encrypting. Any ide how to do this? Or better, another idea to hide the key?
The key is a char[15]
0
Hi

Anyone have suggestions as to a good memory viewer. I can provide address ranges
but the viewer must spot values of my choice.

Quick memory editor does not work for me and the memory pane in visual studio  is limited (cannot search)


thanks!
0
Hello,
in my old code I worked with fread to read from an little text file some settings. This I want now replace with reading from a buffer (char).  The original ocde is:
	int val;
	fread(&val, sizeof(int), 1, f); DBFFTSize  = val;
	fread(&val, sizeof(int), 1, f); DBNumFFTs  = val;
	fread(&val, sizeof(int), 1, f); DBNumBins  = val;
	fread(&val, sizeof(int), 1, f); DBFirstBin = val;
	fread(DBOrgBuf, sizeof(float), 16, f);
	fclose(f);

Open in new window

How to replace this while read from a char buffer.  I have a buffer that was filled before and that was initialized with:
char buff[100];
memset(buff,0,sizeof(buff));

Open in new window


Thanks,

Ingo
0
I have created dll with C++ code successfully and put the dll in the jdk/bin folder in windows environment.

When I execute the native method it gives Runtime error

 
Exception in thread "main" java.lang.UnsatisfiedLinkError: TestJNI.jgd_function()V
        at TestJNI.jgd_function(Native Method)
        at Test.jgd_function(FedExTest.java:12)
        at main.main(main.java:5)

Open in new window


It is not due to mismatch of the parameters as I passed empty parameters and returned void (even then it gives this error).
0
I'm looking for some suggestions to help me fix my problem.

I'm using Visual Studio 2010 SP1, C++ MFC code.

I have a program that makes hundreds of TCP/IP connections per second. The connections stay active for 1-4 seconds each and then are disconnected. On Windows Server 2003 the program can successfully handle around 300 connections/second.

I then tried to run the same program on a newer server (more CPUs, more memory, more horsepower) running Windows Server 2008. The program runs, but the main window (which displays the statistics for each connection) no longer updates. If I slow the rate down to under 50 connections/second then the display will update.

A little about the program design for the statistics display... Internally there is a std::map "qDA" that keeps track of everything going on with each connection. It is preloaded to 10,000 entries. Every second a timer hits that cycles through all 10,000 entries and counts up the statistics. It then updates screen values and finally does an UpdateData(FALSE) to show them on the main window.

I know that doesn't sound efficient, and I agree. Once I started getting display issues, I changed the design and took out the part where all 10,000 connections are cycled through and went to a PostMessage() design where only the connections that have changed state will be counted. Essentially this means that instead of 10,000 connections being cycled through each second, only 300 are (when running at 300 …
0
Ah hello.

Please consider the following code:

printf("unsigned long long int: %llu \n", 0);
printf("unsigned long long int: %llu \n", (unsigned long long int)0);

Open in new window


On 64-bit Windows (VS 2005), this outputs

unsigned long long int: 9109355120595828736
unsigned long long int: 0

Open in new window


On a second run, it outputs

unsigned long long int: 6927490199261806592
unsigned long long int: 0

Open in new window


Which shows it is pretty random.

On 64-bit Linux (Netbeans), the output is as expected:

unsigned long long int: 0 
unsigned long long int: 0 

Open in new window


I am assuming here the printf is exercising its right to exhibit undefined behaviour, since I have broken my "promise" that I am going to give it an unsigned long long integer by passing 0.

1) Am I correct in my assumption; if so, can someone point me at some documentation stating this?
2) In my real code, I am passing variables to printf whose underlying type depends on a typedef; it may be an int or it may be an unsigned long long.  Am I guaranteed safety by always casting to the larger of those two types (unsigned long long here), which seems to work in my code above?
3) Any comments on the difference between Windows and Linux?

TIA
0
Hello experts.  I'm working on this project.  If your not familiar with the Monty Hall paradox here it is.  
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?

My program simulates the execution of the game over a large number of possible runs. It gives statistics of the outcomes based on player keeping his original choice or picking another choice. It has errors.  Here's what I have:

#include <iostream> 
#include <cstdlib> 
#include <ctime> 

using namespace std; 

int main(){
	int numTests , origChoice , car , qswitch ;
	double keepDoor = 0 ;
	double newDoor = 0 ;
	cout << "Enter the number of iterations to test: " ;
	cin >> numTests ;

	cout << "Choose door 1 , 2 , or 3: " ;
	cin >> origChoice ;

	time_t t; // get the system time
	srand((unsigned)time(&t)); // transfer time_t var to int and send it to the srand func
  	for (int i = 0; i < numTests; i++) { 
    	     origChoice = rand() % 2; // random 0 1 or 2 
    	     car = rand() % 2; // 0 1 2
		
    	     if (origChoice == car) 
      		++keepDoor ; 
		else
      		++newDoor ; 
        }
	car+=1; origChoice+=1; // so door and random num are both 1 2 3
	
	if (origChoice == 1){
		if ( car == 2)
			cout << 

Open in new window

0
Hi Experts,

I downloaded Qt 5.2.1 and am trying to compile the code I get from here:  
QCA 2.0.3

I went into the Qt folder in startup menu | 5.2.1 | MinGW 4.8 (32-bit) | Qt 5.2.1 for Desktop (MinGW 4.8 32 bit) (command line)

I run configure, followed by mingw32-make I get errors with some set function in SecureVector:

Can anyone help?


Setting up environment for Qt usage...

C:\QtProjects\qca-2.0.3>configure
Configuring Qt Cryptographic Architecture (QCA) ...
Verifying Qt 4 build environment ... ok
Checking for Qt >= 4.2 ... yes
Checking for certstore ... using Windows built-in

Good, your configure finished.  Now run mingw32-make.

C:\QtProjects\qca-2.0.3>mingw32-make
cd src/ && ( test -e Makefile || C:/Qt/5.2.1/mingw48_32/bin/qmake.exe C:/QtProje
cts/qca-2.0.3/src/src.pro -o Makefile ) && mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'c:/QtProjects/qca-2.0.3/src'
c:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[2]: Entering directory 'c:/QtProjects/qca-2.0.3/src'
g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -m
threads -DUNICODE -DQCA_MAKEDLL -DBOTAN_TYPES_QT -DBOTAN_TOOLS_ONLY -DBOTAN_FIX_
GDB -DBOTAN_MINIMAL_BIGINT -DBOTAN_MP_WORD_BITS=32 -DBOTAN_KARAT_MUL_THRESHOLD=1
2 -DBOTAN_KARAT_SQR_THRESHOLD=12 -DBOTAN_EXT_MUTEX_QT -DQT_NO_DEBUG -DQT_CORE_LI
B -I. -I'../include/QtCrypto' -I'.'
0
Model-View-Controller:

"Screen" sounds like it should be a part of the Model, as it's a physical tangible thingy. And the Screen display sounds like data, (the state of the pixels on the screen, (a screen has pixels,)) and doesn't data go in the Model?

Or, is "Screen" supposed to be a part of the View?
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.