c++

GetProcessName in C++

I have a function with blow detail. typedef part typedef DWORD (WINAPI *GETMODULEFILENAMEEX)(HANDLE hProcess, HMODULE hModule, LPTSTR lpBaseName,DWORD nSize); typedef BOOL (WINAPI *PFNTERMINATEPROCESS)(HANDLE hProcess,UINT uExitCode); /// GetProcessName function void GetProcessName(DWORD PID, PTSTR szProcessName, size_t c...

How can I use std::binary_search using just a key?

I have some data that is stored in a sorted vector. This vector is sorted by some key. I know the STL has an algorithm for checking if an element is in this sorted list. This means I can write something like this: struct MyData { int key; OtherData data; }; struct MyComparator { bool operator()( const MyData & d1, const MyData & d2 ) ...

How to get a QModelIndex from another QSqlQuery used for searching the database (needed for selecting the found items)

Hi there, I have a problem when dealing with my QSqlQueryModel. I want to search the database for some items and select them in my QTableView with QItemSelectionModel which needs a QModelIndex. What I don't understand is how should I search in order to get the corresponding QModelIndex for my model/view architecture. I can't possibly u...

Over reliance on macros

I feel, every time I read a C or C++ program, that half or more of it is just macros. I understand that macros can be cool but they are hard to track, debug, etc. Not to mention that most programming languages do not even define something like macros (although Perl6 will have something of the sort). I personally always have found a way ...

Unions to extract data

Won't the union in this question cause UB when used as this: union Data { unsigned int intValue; unsigned char argbBytes[4]; }; Data data; data.intValue = 1235347; unsigned char alpha = data.argbBytes[0]; //UB? I'm thinking about 9.5/1 in the standard: In a union, at most one of the data members can be active at any time...

different types of objects in the same vector array ?

Hi , I am using an array in a simple logic simulator program and I want to switch to using a vector to learn it but the reference I am using "OOP in C++ by Lafore" doesn't have a lot about vectors and objects so I am kinda of lost . Here is the previous code : gate* G[1000]; G[0] = new ANDgate() ; G[1] = new ORgate; //gate is a class i...

how i show a dWord value in Messagebox api function

i want show a message dialog with a dword value like this MessageBox(0, (LPCWSTR) hProcess ,TEXT("My MessageBox Info"),MB_OK | MB_ICONERROR); hProcess is a DWORD value but it when messagebox appear , body part of message that should show dowrd value is empty. ...

Gdb gives no stack on a simple std::string uncaught exception

Hi folks, im a little bit newbie on gdb so here goes: Im working on cpp unit testing operation right now. I try to construct string objects with invalid parameters like null_char but program expectedly gives exceptions :). When i try to debug the app using gdb, i type bt after the crash, but it gives me no stack message. Any ideas to w...

Vim different textwidth for multiline C comments?

In our C++ code base we keep 99 column lines but 79-some-odd column multiline comments. Is there a good strategy to do this automagically? I assume the modes are already known because of smart comment line-joining and leading * insertion. ...

Why can't I increment a variable of an enumerated type?

I have a enumerated type StackID, and I am using the enumeration to refer to an index of a particular vector and it makes my code easier to read. However, I now have the need to create a variable called nextAvail of type StackID. (it actually refers to a particular stackID ). I tried to increment it but in C++, the following is illegal...

What causes a Sigtrap in a Debug Session

In my c++ program I'm using a library which will "send?" a Sigtrap on a certain operations when I'm dubugging it ( using gdb as debugger). I can then choose weather I wish to Continue or Stop the program. If I choose to continue the program works as expected but setting custum breakpoints, after a Sigtrap has been caught, causes the debu...

Class or Container to store heterogenous items in C++

Is there any structure or class or container which i can use to store heterogenous items which is serializable. For example say i have a int,float and another class object. I want to store all of them in a particular container at runtime and pass it across classes. Does C++ give any such options. ...

how to show both icon and text on button on mfc?

m_pButton->Create(L"ABC", WS_CHILD | WS_VISIBLE| BM_SETIMAGE,CRect(0,0,100,100),this,ID_BUTTON1); m_pButton->SetIcon(::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1))); //above show neither showing image nor showing text. ...

Destructor crash

Hi, I am working on a Win32 c++ application in Visual studio. In one of the source files, I have global object like below. TestClass tObj; int main() //Execution starts here { } TestClass is defined in other DLL like below. struct Source { }; class TestClass { list<Source> sourceList; public: TestClass() {} ...

What is the best way to present a list of images in Qt?

I want to load a number of images into a widget that will show me the images in a list. It can be many images so it needs to be fast, also I'd like to attach a check box for each image presented. What will be the best way to implement it in Qt 4.6? ...

How to read data from excel file in C++/VC 6.0 without MFC ?

Have to read data from MS Excel File, the data contains name DOB as well as some numeric values... ...

Making a crash log meaningful (c++, Linux env)

I have a compiled c++ application that produces a stack trace when it crashes. At the moment, the stack trace isn't particularly meaningful. I would like to process it so that it contains symbols, rather than addresses. Does anyone have any pointers on how I might go about doing this? ...

Possible to abstract this logic with macro?

Hi all, I have thousands of function wrappers which inside actually perform a similar logic like: // a, b, ... are variable length parameters of different type void API_Wrapper(hHandle, a, b, ..) { if (hHandle) return remote_API(hHandle, a, b, ..); else return API(a, b, ..); } I wanna use a macro to reuse the if-else logic so ...

What is the reason for #pragma once inside header guards?

Just seen this inside <boost/asio.hpp> #ifndef BOOST_ASIO_HPP #define BOOST_ASIO_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) /// .... #endif // BOOST_ASIO_HPP Disregarding the _MSC_VER preprocessor checks, what is the benefit of having the #pragma once in this case...

Signed / unsigned comparison and -Wall

I have recently started using the -Wall compiler switch in an attempt to improve the quality of my code. It is giving (correctly) a warning about this little snippet... int i; for (i = start - 1; i >= 0; i--) { if (i >= number1.array.size()) { one_value = 0; } because number1.array.size...