c++

Get full path of executable of running process on HPUX...

Hi All, I want to get the full path of the running process (executable) without having root permission using C++ code. Can someone suggest a way to achieve this. on Linux platforms i can do it by using following way. char exepath[1024] = {0}; char procid[1024] = {0}; char exelink[1024] = {0}; sprintf(procid, "%u", getpid()); strcpy(e...

Caching a const char * as a return type

Hi all.. Was reading up a bit on my C++, and found this article about RTTI (Runtime Type Identification): http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx . Well, that's another subject :) - However, I stumbled upon a weird saying in the type_info-class, namely about the ::name-method. It says: "The type_info::name member fu...

How to create a JNIEnv mock in C/C++

I am writing some JNI code in C that I wish to test using cunit. In order to call the JNI functions, I need to create a valid JNIEnv struct. Does anyone know if there is a mocking framework for such a purpose, or who can give me some pointers on how to create a mock JNIEnv struct myself? ...

How to get the result of strlen into an int without a warning when compiling with /Wp64

int l = strlen(s); warning C4244: '=' : conversion from '__w64 int' to 'int', possible loss of data I need to replace strlen with an inline function int l = new_strlen(s); But how do I portably get the result of the strlen into the int without a warning, and without using pragmas? I can guarantee there aren't more than 2 billion char...

Is there a simple script to convert C++ enum to string?

Suppose we have some named enums: enum MyEnum { FOO, BAR = 0x50 }; What I googled for is a script (any language) that scans all the headers in my project and generates a header with one function per enum. char* enum_to_string(MyEnum t); And a implementation with something like this: char* enum_to_string(MyEnum t){ ...

Good Book on C++ Internals?

I'm looking for a good book or website on how C++ works under the hood. Some topics might be virtual function lookup tables, function name mangling, class/struct relationship, etc. Even better, something that covers other languages as well (I'd love to know more about Perl's internals) Thanks! ...

how to concat two stl vectors?

how to concat two stl vectors? ...

can realloc Array, then Why use pointers?

This was an job placement interview I faced. They asked whether we can realloc Array, I told yes. Then They asked - then why we need pointers as most of the people give reason that it wastes memory space. I could not able to give satisfactory answer. If any body can give any satisfactory answer, I'll be obliged. Please mention any situat...

How to read until EOF from cin in C++

Hi, I am coding a program that reads data directly from user input and was wondering how could I (without loops) read all data until EOF from standard input. I was considering using cin.get( input, '\0' ) but '\0' is not really the EOF character, that just reads until EOF or '\0', whichever comes first. Or is using loops the only way to...

Creating Docking Panes in CView instead of CMainFrame

When creating an MDI Application with "Visual Studio" style using the AppWizard of VS2008 (plus Feature Pack), the CMainFrame class gets a method CreateDockingWindows(). Since I don't want all panes to be always visible but display them depending on the type of the active document, I made those windows to members of my views and also mo...

Is there a convenient way to wrap std::pair as a new type?

Often times I find myself using std::pair to define logical groupings of two related quantities as function arguments/return values. Some examples: row/col, tag/value, etc. Often times I should really be rolling my own class instead of just using std::pair. It's pretty easy to see when things start breaking down - when the code becomes ...

Parsing iCal/vCal/Google calendar files in C++

Hello all, Can anyone recommend a ready-to-use class/library compatible with C/C++/MFC/ATL that would parse iCal/vCal/Google calendar files (with recurrences)? It can be free or commercial. Thanks in advance! ...

Can the result of a function call be used as a default parameter value?

Is there a good method for writing C / C++ function headers with default parameters that are function calls? I have some header with the function: int foo(int x, int y = 0); I am working in a large code base where many functions call this function and depend on this default value. This default value now needs to change to something ...

How does the C++ compiler know which implementation of a virtual function to call?

Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base class #include <iostream> using namespace std; class Polygon { protected: int width; int height; public: void set_values(int a, int b) { width = a; height = b; } ...

Accessing Win32 C/C++ struct members from C#

I am intercepting Win32 API calls a native dll or exe is doing from C# using some kind of hooking. In this particular case I am interested in DrawText() in user32.dll. It is declared like this in Win32 API: INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags) The LPRECT struct has the following signature (als...

How to get a list of installed True Type Fonts on Linux using C or C++?

How can my app get a list of the True Type Fonts that are available on Linux. Is there a standard directory where they are stored across different distributions? Or some other standard way to locate them? ...

Undefined Symbol ___gxx_personality_v0 on link

I've been getting this undefined symbol building with this command line: $ gcc test.cpp Undefined symbols: "___gxx_personality_v0", referenced from: etc... test.cpp is simple and should build fine. What is the deal? ...

Why does C# not provide the C++ style 'friend' keyword?

The C++ friend keyword allows a class A to designate class B as it's friend. This allows Class B to access the private/protected members of class A. I've never read anything as to why this was left out of C# (and VB.NET). Most answers to this earlier StackOverflow question seem to be saying it is a useful part of C++ and there are go...

C++ "Named Parameter Idiom" vs. Boost::Parameter library

I've looked at both the Named Parameter Idiom and the Boost::Parameter library. What advantages does each one have over the other? Is there a good reason to always choose one over the other, or might each of them be better than the other in some situations (and if so, what situations)? ...

C++ headers - separation between interface and implementation details

One of classes in my program uses some third-party library. Library object is a private member of my class: // My.h #include <3pheader.h> class My { ... private: 3pObject m_object; } The problem with this - any other unit in my program that uses My class should be configured to include 3p headers. Movi...