c++

check floppy Drive

Hello To get the removable drives i have used GetDriveType ( ) function Is it possible to check whether a drive is floppy drive or not ? Please let me know your suggestions on this... Thank you dor any help ...

Difference in memory allocation in WIn 7/Vista compared to WinXP/Win2k3 in following code

I have the following piece of code. This is written for getting the list of timezones from registry and populating into an array. This piece of code works fine in Win7 and Vista OS but not in WinXp and Win2k3. The reason is because of the size of array getting overflown. I have defined only 100 elements. However there are more than 100...

How to get pointer name.

Actually I am hooking memory management functions but one problem that confronts me is that I am unable to get the pointer name for which memory is being allocated in my hooked function. I mean... suppose Myfunction() allocates memory to a pointer Myptr through new operator as geven below. Myfunction() { int * Myptr = new int; } Now h...

Make any class reference counted with inheritance?

In my new project I wish to (mostly for to see how it will work out) completely ban raw pointers from my code. My first approach was to let all classes inherit from this simple class: template class Base { public: typedef std::shared_ptr ptr; }; And simple use class::ptr wherever I need a pointer. This ap...

Override or remove an inherited constructor

Here is some C++ code: #include <iostream> using namespace std; class m { public: m() { cout << "mother" << endl; } }; class n : m { public: n() { cout << "daughter" << endl; } }; int main() { m M; n N; } Here is the output: mother mother daughter My problem is that I don't want the m's constructor to...

Software product pricing/cost estimation

I always had trouble with estimating cost/price of finished software (or programming work), so here are two questions about it. question 1: You're asked to write a piece of code for cash (all rights to the code belongs to buyer once you're done). You know approximate number of hours it will take (+-25%), and approximate complexity (i....

No matching function for call to operator new

I'm trying to wrap a class from a library I'm using in Lua. Specifially, I'm trying to wrap the color class from SFML. The full source for the color class can be seen here and here. This is the function that's that I'm failing in. int SFColor_new(lua_State* L) { // omitting part where I set r, g, b, and a new (lua_newuserdata...

Indenting nested namespaces on the same line to just one level

In emacs 21: namespace Abc { namespace Def { class X; namespace Ghi { class Y; } } } But now in emacs 22.2.1: namespace Abc { namespace Def { class X; namespace Ghi { class Y; } } } How do I get the old behaviour back? Note that I don't want a fixed column for indentation...

boost::filesystem::rename: Cannot create a file when that file already exists

I'm renaming a file using boost::filesystem, and sometimes the target file will exist. According to the boost documentation here: http://www.boost.org/doc/libs/1_42_0/libs/filesystem/doc/reference.html#Non-member-functions template void rename(const Path1& from_p, const Path2& to_p); Requires: Path1::external_string_type and ...

Why would I want to start a thread "suspended"?

The Windows and Solaris thread APIs both allow a thread to be created in a "suspended" state. The thread only actually starts when it is later "resumed". I'm used to POSIX threads which don't have this concept, and I'm struggling to understand the motivation for it. Can anyone suggest why it would be useful to create a "suspended" thread...

Whats the right approach to return error codes in C++

I'm using error codes for handling errors in my c++ project. The problem is how to return error codes from a function which is supposed to return some variable/object. consider this: long val = myobject.doSomething(); Here, myobject is an object of some class. If doSomething function encounters some error condition then how should i...

The inner depths of PHP

I've been studying Visibility issue in PHP (public, private, protected) and wondered how is this sort of "dom-building" is implemented in PHP? I mean there should be some kind of algorithm that PHP uses to go through all your classes and establish relations between them. Not sure if it is called "dom-building" though, but I think the sam...

Problem with WH_JOURNALRECORD hook in Windows (C++) - Callback never called.

Hello everyone, The following code has been giving me some troubles for the past few hours. I'm trying to write a small program (based on some tutorials from the web), that uses a WH_JOURNALRECORD windows hook to log keystrokes. Main code: #include "StdAfx.h" #include <tchar.h> #include <iostream> #include <windows.h> using std::cout...

Acessing browser socket using Winsock SPI(LSP)

Hi, how can i access to the socket, that is used by web browser. Or how can i get data transfered between web browser and web server. I need to connect to that socket and modify the data, the web browser sends and recieves. What concrete functions should i use? I studiend the msdn documentation about this, but didnt noticed how do i get...

Interrupt sleep() function

How can I interrupt sleep() using a signal handler? ...

How can I simplify this binary-tree traversal function?

template<typename T> void traverse_binary_tree(BinaryTreeNode<T>* root,int order = 0)// 0:pre, 1:in , 2:post { if( root == NULL ) return; if(order == 0) cout << root->data << " "; traverse_binary_tree(root->left,order); if(order == 1) cout << root->data << " "; traverse_binary_tree(root->right,order); if(orde...

Visual Studio solutions in Qt Creator

Hi, I am using Qt 4.5 and having Qt Creator as the IDE. I am quite comfortable with it. I know we can open the .pro files (from the Qt Creator) in the Visual Studio IDE. But how about the reverse? i.e How can I open a visual studio Qt solution (.sln) in Qt Creator? Is it possible or I have to create a pro file again for the project? T...

C++: Fill array according to template parameter

Hello, Essentially, the situation is as follows: I have a class template (using one template parameter length of type int) and want to introduce a static array. This array should be of length length and contain the elements 1 to length. The code looks as follows up to now: template<int length> class myClass{ static int array[leng...

sig in pthread_kill(pthread_t thread, int sig)

What does sig in int pthread_kill(pthread_t thread, int sig) refer to? Are there predefined sigs? :S ...

C++ char * pointer problem

I have a the following code: #include <iostream> using namespace std; void func(char * aString) { char * tmpStr= new char[100]; cin.getline(tmpStr,100); delete [] aString; aString = tmpStr; } int main() { char * str= new char[100]; cin.getline(str,100); cout<< str <<endl; func(str); cout<< str <<end...