c++

How to set up a Winsock UDP socket?

I want to create a Winsock UDP socket that only sends data to a client. I want the kernel to choose an available port for me. On the other hand, I want to indicate which local IP to use, since I'm running a few nics. I've tried combing through the maze of socket options, as well as binding with the port in the socket address set to 0 t...

How to find all possible subsets of a given array?

I want to extract all possible sub-sets of an array in C# or C++ and then calculate the sum of all the sub-set arrays' respective elements to check how many of them are equal to a given number. What I am looking for is the algorithm. I do understand the logic here but I have not been able to implement this one by now. :s ...

How can I use a dynamically sized texture array with glTexImage2D?

Currently, I'm able to load in a static sized texture which I have created. In this case it's 512 x 512. This code is from the header: #define TEXTURE_WIDTH 512 #define TEXTURE_HEIGHT 512 GLubyte textureArray[TEXTURE_HEIGHT][TEXTURE_WIDTH][4]; Here's the usage of glTexImage2D: glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_WIDT...

DXGetErrorString newbie question

Hello, I'm new to C++ and Direct X, and I was wondering what is the proper use of DXGetErrorString and DXGetErrorDescription? According to http://msdn.microsoft.com/en-us/library/bb173057(VS.85).aspx and http://msdn.microsoft.com/en-us/library/bb173056(VS.85).aspx, these functions return a pointer to a string. However, in all the examp...

Advice on a better way to extend C++ STL container with user-defined methods

I inherited from C++ STL container and add my own methods to it. The rationale was such that to the clients, it will look act a regular list, yet has application-specific methods they can readily be called. This works fine, but I have read numerous posts about not inheriting from STL. Can someone provide a concrete advice of how I migh...

When to use "new" and when not to, in C++?

Possible Duplicate: When should I use the new keyword in C++? When should I use the "new" operator in C++? I'm coming from C#/Java background and instantiating objects is confusing for me. If I've created a simple class called "Point", when I create a point should I: Point p1 = Point(0,0); or Point* p1 = new Point(0, 0);...

How do I define a generic std::list of a custom type?

I'm getting the following error trying to define a list of "Lines": line-clip.cpp:44: error: expected initializer before '<' token #include <list> using namespace std; class Line { public: Point p1; Point p2; Line(Point P1, Point P2) { p1 = P1; p2 = P2; } } // Line List list <Line> lineLi...

Should C++ template be used in this case?

I have a class that my client uses to Get() a packet. The packet contains a std::vector whose type is not known until the packet is generated internally in my Interface class (in this example, it depends on the Packet::type variable). I was wondering if template could be used for this since the Packet class is just a generic class whose...

Resource for C++

Hello, It has been a long time since I've used C++. I want to start programming in C++ again but I am looking for a particular resource and wondering if anyone here has any good references. I am looking for a book, web tutorial, video...whatever that teaches you C++ while you're building an application. So, for example, a book might sta...

Defining Function Pointers

I am trying to call the internal Windows NT API function NtOpenProcess. I know calling internal APIs can be a bad idea, but for this particular tool I need the low-level access this API provides. My problem is that to use such an internal API, I need to use Runtime Dynamic Linking, as specified in this article To do that, I need to def...

How can I easily work with a char**?

I have a char** that I frequently need to insert into or perform a lookup. It is very tedious to realloc(), malloc() the array and insert strings. Is there any standard way that I can add strings to or do lookups in a char**? I guess I'm looking for something like string, but using char**'s instead. ...

Finding Strings Neighbors By Up To 2 Differing Positions

Hi all, Given a seed string, I want to find its neighbors with at most differ in 2 positions. All the digits involve in generating string are only four (i.e. 0,1,2,3). This is the example for what I mean: # In this example, 'first' column # are neighbors with only 1 position differ. # The rest of the columns are 2 positions differ See...

What is the degree of a tree? (As in, a tree ADT)

I understand that the degree of a node is the number of children it has. However, how do we define the degree of a tree? ...

Calling C++ dll function from C#: Of structs, strings and wchar_t arrays.

Here's a simple problem I need to solve, but it makes me feel my hair turning gray as all my attempts are returning me the same error: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I have a sample app written in C++ which makes a call to the dll. Here is the relevant code: ...

I've heard i++ isn't thread safe, is ++i thread-safe?

I've heard that i++ isn't a thread-safe statement since in assembly it reduces down to storing the original value as a temp somewhere, incrementing it, and then replacing it, which could be interrupted by a context switch. However, I'm wondering about ++i. As far as I can tell, this would reduce to a single assembly instruction, such as...

Can I use a grayscale image with the OpenGL glTexImage2D function?

I have a texture which has only 1 channel as it's a grayscale image. When I pass the pixels in to glTexImage2D, it comes out red (obviously because channel 1 is red; RGB). glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, dicomImage->GetColumns(), dicomImage->GetRows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelArrayPtr); Do I change GL_RGBA? If s...

C# RSA equivalent code to the C++ Crypto API

DWORD nSize; LPBYTE lpData; HCRYPTKEY hPublicKey; nSize = ReadFromFile(lpszUserPublicKey, NULL); if(nSize == -1) return FALSE; lpData = new BYTE[nSize]; ReadFromFile(lpszUserPublicKey, lpData); if(!CryptImportKey(hProv, lpData, nSize, NULL, 0, &hPublicKey)) { delete lpData; return FALSE; } Erase(lpData, nSize); // Get the data...

Operator overloading with memory allocation?

The sentence below is from, The Positive Legacy of C++ and Java by Bruce Eckel, about operator overloading in C++: C++ has both stack allocation and heap allocation and you must overload your operators to handle all situations and not cause memory leaks. Difficult indeed. I do not understand how operator overloading has any...

How do I send and receive broadcast messages using QT 4.5 and Linux?

Hi. I'm new to QT programming. Could anyone explain how I can send broadcast messages given a network adapter and its IP address? I also don't know how to receive datagrams using QT. Could anyone please help? ...

C++ Pointers and References - Beginner Question

Hi, I was looking at a library a person has made for FaceBook in C++. The header file is this: #ifndef __FACEBOOK_H__ #define __FACEBOOK_H__ /** * Facebook Class * Joel Seligstein * Last mod: Aug 22, 2006 * * This is the beginnings of a facebook class set and REST client. Its not documented * yet nor nearly complete. But thi...