c++

Can an out-of-process COM object determine its parent process?

From an out-of-process COM object (LocalServer32) can I determine the client process that requested the creation of the object? - to be specific I need to get hold of the client processes command line. This question arrises because (due to poor standardisation, implementation and support) the potential 3rd party clients of the object ha...

Word automation in plain C++

I'm finding resource which is about word automation in C++ ( Win32 API / MFC ) . But it's quite rare. Are there a book or comprehend article about this ?. Thanks so much :) ...

MFC: Best way to get text from a CRichEdit?

I've got a CRichEdit that I need to get the text from. What is the best way to do that? GETTEXTEX? StreamOut? If I go the StreamOut approach, what would my callback look like? ...

What is the difference between NULL in C++ and null in Java?

I've been trying to figure out why C++ is making me crazy typing NULL. Suddenly it hits me the other day; I've been typing null (lower case) in Java for years. Now suddenly I'm programming in C++ and that little chunk of muscle memory is making me crazy. Wikiperipatetic defines C++ NULL as part of the stddef: A macro that expands ...

What is a good way to quantify C++ knowledge and skill?

I have only recently started to study (with the hopes of mastering) C++, one because i have started to love it and two because it's a good career/profession move. At the same time i wish to quantify my knowledge and skill so as to set my self apart from those who just throw C/C++ on their resumes and fish. Is there an open, industry an...

POD global object initialization

I've got bitten today by a bug. Question for the C++ lawyers Let's consider the following source : struct MyPod { short m_short ; const char * const m_string ; } ; MyPod myArrayOfPod[] = { { 1, "Hello" } } ; int main(int argc, char * argv[]) { return 0 ; } Note that all values are known at compile time, and t...

C Population Count of unsigned 64-bit integer with a maximum value of 15

I use a population count (hamming weight) function intensively in a windows c application and have to optimize it as much as possible in order to boost performance. More than half the cases where I use the function I only need to know the value to a maximum of 15. The software will run on a wide range of processors, both old and new. I a...

Why is NULL/0 an illegal memory location for an object?

I understand the purpose of the NULL constant in C/C++, and I understand that it needs to be represented some way internally. My question is: Is there some fundamental reason why the 0-address would be an invalid memory-location for an object in C/C++? Or are we in theory "wasting" one byte of memory due to this reservation? ...

correct way to store an exception in a variable

I have an API which internally has some exceptions for error reporting. The basic structure is that it has a root exception object which inherits from std::exception, then it will throw some subclass of that. Since catching an exception thrown in one library or thread and catching it in another can lead to undefined behavior (at least Q...

getline() sets failbit and skips last line

I'm using std::getline() to enumerate through the lines in a file, and it's mostly working. It's left me curious however - std::getline() is skipping the very last line in my file, but only if it's blank. Using this minimal example: #include <iostream> #include <string> int main() { std::string line; while(std::getline(...

Explicit type conversion

I have read in a book that specifies this : //: C03:SimpleCast.cpp int main() { int b = 200; unsigned long a = (unsigned long int)b; } ///:~ "Casting is powerful, but it can cause headaches because in some situations it forces the compiler to treat data as if it were (for instance) larger than it really is, so it will occupy more spac...

Proper way to handle issue when porting 32 to 64 bit. Conversion from DT1 to DT2 of greater size

So I am trying to port 32 bit to 64 bit. I have turned on the VS2008 flag for detecting problems with 64 bit. I am trying following: char * pList = (char *)uiTmp); warning C4312: 'type cast' : conversion from 'unsigned int' to 'char *' of greater size Disregard the code itself. This is also true for any pointer, because 64 bit poin...

DUMP in unhandled C++ exception

In MSVC, how can I make any unhandled C++ exception (std::runtime_error, for instance) crash my release-compiled program so that it generates a dump with the full stack from the exception throw location? I have installed NTSD in the AeDebug registry and can generate good dumps for things like memory access violation, so the matter here ...

How to populate wxListCtrl??? (using c++)

Hi all, I'm trying to populate a wxListCtrl but after trying various methods can't seem to be able to populate it with items. Basically, I want a list control that would have three columns with headings and will show values in rows. But I've tried InsertItem, SetItem, or InsertColumn methods but am only able to show the column headings...

Casting a byte array to a struct pointer depends on endianness or memory alignment?

Suppose this code: unsigned char list[3] = { 1, 2, 3 }; struct _struct{ unsigned char a; unsigned char b; unsigned char c; } *s; s = ( _struct * ) list; Can I assume that always s->a == 1, s->b == 2, s->c == 3 ? Or it will depend on the system's endianness or memory alignment? ...

And now for a complete change of direction from C++ function pointers

I am building a part of a simulator. We are building off of a legacy simulator, but going in different direction, incorporating live bits along side of the simulated bits. The piece I am working on has to, effectively route commands from the central controller to the various bits. In the legacy code, there is a const array populated w...

Can you explicitly set a structure layout/alignment in C++ as you can in C#?

In C# you have nice alignment attributes such as this: [StructLayout(LayoutKind.Explicit)] public struct Message { [FieldOffset(0)] public int a; [FieldOffset(4)] public short b; [FieldOffset(6)] public int c; [FieldOffset(22)] //Leave some empty space just for the heck of it. public DateTime dt; } Whi...

Which design pattern is most appropriate?

Hello, I want to create a class that can use one of four algorithms (and the algorithm to use is only known at run-time). I was thinking that the Strategy design pattern sounds appropriate, but my problem is that each algorithm requires slightly different parameters. Would it be a bad design to use strategy, but pass in the relevant par...

Can I use a switch to hold a function?

I have a 3 file program, basically teaching myself c++. I have an issue. I made a switch to use the math function. I need and put it in a variable, but for some reason I get a zero as a result. Also another issue, when I select 4 (divide) it crashes... Is there a reason? Main file: #include <iostream> #include "math.h" #include <stri...

Help with Assembly/SSE Multiplication

I've been trying to figure out how to gain some improvement in my code at a very crucial couple lines: float x = a*b; float y = c*d; float z = e*f; float w = g*h; all a, b, c... are floats. I decided to look into using SSE, but can't seem to find any improvement, in fact it turns out to be twice as slow. My SSE code is: Vector4 abcd...