c++

MD5 Code Coverage

I'm currently implementing an MD5 hash algorithm based RSA data security code, in the UpdateData method there is a section which reads: mCount[0] += (length << 3); if (mCount[0] < (length << 3)) { mCount[1]++; } I'm trying at the moment to understand how the if statement could ever evaluate to true (the mCount[0] value is initial...

Converting (void*) to std::vector<unsigned char>.

I have a (void*) buffer that I need to convert to std::vector<unsigned char> before I can pass it on. Unfortunately, my C++ casting skills a little weak. Any suggestions? ...

Why can't I get my CDatabase object to understand my Data Source Name?

I'm using the MFC class CDatabase. To establish a connection to SQL Server, I'm calling OpenEx() with a connection string. My problem is that the object seems unable to interpret the DSN part of the string. The connection string looks like this: ODBC;DSN=mySystemDSN;UID=myUsername;WSID=myMachineName;DATABASE=myDatabaseName;Trusted_C...

How to detect 'strict aliasing' at compile time?

'Strict aliasing' optimization needs special care from the source code, s.a. using a union instead of pointer casts. Is there a way to detect using preprocessor directives (#if/else) whether the compiler is trying to do such optimizations? I would like to maintain the old and non-strict-aliasing-prepared code path for processors and com...

What is the link_.exe file?

I am having trouble with my linker, I asked a question but have not got an exact solution. However its a problem with a linker called LINK_.exe Does anybody know why this file is different or why it is called just after LINK.exe during my compile? I am using Visual Studio 2008 SP1 on Windows XP SP3. For a C++ project. Further to tha...

How does a reference-counting smart pointer's reference counting work?

In other words, how does the implementation keeps track of the count? Is there a map-like object maintained which is accessible by all the shared_ptr instances whose key is the pointer's address and value is the number of references? If I've to implement a shared_ptr, this is the first idea that's coming to my mind. Is there a possibil...

Const-correct Notifier in Observer Pattern

Hi, I want to implement an Observer of a Model class which does not change the Model. Thus, it should be able to use a const-Reference to access the Model. But the Registering of the Observer prohibits this. Here is how the observer pattern is implemented in my Project: //Attributes of type Observable are used by classes that want ...

Is programming for me?

I learned to program 2 months ago (I read "C++ A Beginner Guide" by Herbert Schildt), I understand most of how C++ works but I can't actualy code something from start to finish (console aplications yes but nothing more complicated than that). What should I ask myself to see if programming is really a thing for me? If I can't become a go...

MSVC++ compiler error C2143

The following code excerpt is responsible for a cryptic MSVC++ compiler error: template<class T> class Vec : public vector<T>{ public: Vec() : vector<T>(){} Vec(int s) : vector<T>(s){} T& operator[](int i){return at(i); } const T& operator[](int i)const{ return at(i);} }; ... The error: test.cpp(5) : error C2143:...

Xerces/Xalan: UNC path as argument for document function?

I'm transforming an XML document by using Xerces-C 2.5 and Xalan-C 1.8. The XSL contains a "document" function, that references a file on the network. Unfortunately I cannot access this file by HTTP. I've only got the UNC path. Xerces refuses to parse the referenced document, because WinSockNetAccessor::makeNew is called in Xerces as th...

C2065 undeclared identifier while assigning a define to an int

Hi, I have a small problem with a define. I want to assign it to an integer variable but the compiler says it's undeclared. Here's what the code looks like: defines.h #ifndef DEFINES_H #define DEFINES_H #define MYDEFINE 2 #endif myclass.h namespace mynamespace { class myClass { int someFunction(); }; } myclass.cxx #include ...

Windows Explorer like folder tree browser

I am trying to implement a platform independent file/directory tree browser. Basically, I am trying to replicate windows explorer's tree control to browse the computer. However, I can't figure out how to find the "Desktop" or "My Computer" folder string (It changes in every pc and os type, version and language). If I can find a way to ge...

Accessing private members

Is it ethical to access a class' private members by casting it to a void pointer and then to a struct? I don't think I have permissions to modify the class that contains the data members that I need to access. I don't want to take a risk accessing the data members in an indirect way if it is not ethical. EDIT: Had to edit this furth...

How can you make buttons on a MSVS C++ CToolBar larger along with their images?

We have a touch screen, and the toolbar is too small to hit with my meaty fingers. Is there an easy way I can have an option to make the toolbar buttons bigger and easier to hit? So far I've attempted a few things: m_toolbar.SetSizes( CSize(64,64), CSize(50,50) ); m_toolbar.SetSizes( CSize(64,64), CSize(50,50) ); m_toolbar.GetToolBarC...

Serialize in C++ then deserialize in C#?

Is there an easy way to serialize data in c++ (either to xml or binary), and then deserialize the data in C#? I'm working with some remote WINNT machines that won't run .Net. My server app is written entirely in C#, so I want an easy way to share simple data (key value pairs mostly, and maybe some representation of a SQL result set). I...

C++ template class error with operator ==

Error: error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const entry' (or there is no acceptable conversion) The function: template <class T, int maxSize> int indexList<T, maxSize>::search(const T& target) const { for (int i = 0; i < maxSize; i++) if (elements[i] == target) //ERROR??? ...

String to Enum

Is there a way to associate a string from a text file with an enum value? The problem is, I have a few enum values stored as string in a text file which I read on the fly on meeting some condition... Now I want to assign the read value to an enum. What is the most effective way to do so? It needn't be the simplest approach. ...

Timer message in MFC/Win32

I was just trying the SetTimer method in Win32 with some low values such as 10ms as the timeout period. I calculated the time it took to get 500 timer events and expected it to be around 5 seconds. Surprisingly I found that it is taking about 7.5 seconds to get these many events which means that it is timing out at about 16ms. Is there a...

Working with audio in C++

I need to be able to get the length of an audio file (preferably in milliseconds, the timing is very important for the application), and play back the audio. The application is written in C++ on the windows XP platform. Any suggestions for audio formats/3rd party libraries that would do the trick? ...

MagickNet C++ Source Compilation Failure

I'm attempting to compile a working copy of the MagickNet class library (DLL) using the sources from the ImageMagick and MagickNet libraries. I was unable to obtain a copy of the MagickNet source files from the creator's homepage as it is currently down, so I was forced to obtain the files and C++ project file from here, courtesy of a G...