c++

Keeping alive a Bluetooth serial port on Windows Mobile 6.0 after power-off/suspend

I encountered an unexpected behavior while debugging a WinMo 6 program last night, and I wonder if I was dreaming. But first, some context. The program communicates through a serial port with a GPS device. It uses either a physical port with cable, and also tries via Bluetooth. After a suspend or power-off, I don't need to close and reo...

c++ and multi pointers

I have a simple problem with pointers. Here is my code: #include <iostream> #include <vector> using namespace std; int main() { typedef float RtPoint[3]; RtPoint** b = new RtPoint*[4]; b[0] = (RtPoint*)new RtPoint; RtPoint* p = b[0]; RtPoint c; (*p)[0] = &(c[0]); (*p)[1] = &(c[1]); (*p)[2] = &(c[2]); ...

How to genrate a monochrome bit mask for a 32bit bitmap

Under Win32, it is a common technique to generate a monochrome bitmask from a bitmap for transparency use by doing the following: SetBkColor(hdcSource, clrTransparency); VERIFY(BitBlt(hdcMask, 0, 0, bm.bmWidth, bm.bmHeight, hdcSource, 0, 0, SRCCOPY)); This assumes that hdcSource is a memory DC holding the source image, and hdcMask is ...

Multiple TESTFLAGs in C++

Hi all. Our rather large C++ code base has a different debug flag for each module. These are currently defined in the code like so: #ifdef A_DEBUG {foo foo} #endif However, we have more than one of these flags. So while clearmake -C gnu TESTFLAG=-DA_DEBUG works just great on one flag, I would love to be able to compile with...

Can I link MSVCRT statically with mingw?

I have C program I compile with mingw on Windows. It works fine but requires MSVCRT.DLL. I want to link that statically (like I can do in Visual Studio). Is this possible? I tried -static flag to gcc and it didn't make any change. What about C++ program using also standard C++ library? ...

const and no const methods in c++ ?

Hi, I have a program and many of its classes have some operators and methods with the keyword const like the followings: operator const char* () const; operator char* (); void Save(const char *name) const; void Load(const char *name); First: what does it mean const at the end of the method declaration?, is it the same like putting it...

implementation of hash table

i have following code #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <hash_map> #include <string> #include <iterator> #include <ostream> using namespace std; struct Equal { bool operator()(const char *s1,const char *s2)const { return std::strcmp(s1,s2)==0; } }; ...

Get parent directory of file as string c++

I'm using Managed C++. I need to extract the parent directory after OpenFileDialog returns the String^ file path. System::String^ filestring = openFileDialog1->FileName; The method that microsoft uses is Directory::GetParent but this must be saved as System::IO::DirectoryInfo^ WhyIsThisNotAString = Directory::GetParent(files...

How to make a webbrowser in C++ without dependencies?

How can I use IE control or some kind of webbrowser in c++ but without any external dependencies? I mean can be done with pure win api or something like that? I know the basics of c++ and the methods I know to use the webbrowser control needs the c++ libs to work. Edit: Sorry my question is unclear, im such a noob sometimes. What I mean...

How to clone multiple inheritance object?

I have defined a Cloneable interface: struct Cloneable { virtual Cloneable * clone(void) const = 0; } I have also some other interface classes (content not relevant to issue): struct Interface { }; struct Useful_Goodies { }; I have created a leaf object which inherits from the above classes: struct Leaf : public Cloneable, publ...

Rearranging array elements

Not sure if it is a duplicate. Given a data structure having first N integers and next N chars. A = i1 i2 i3 ... iN c1 c2 c3 ... cN. I need an in-place algorithm to rearrange the elements as A = i1 c1 i2 c2 ... iN cN. ...

Is it allowed to assign to a dereferenced this (*this)?

Hi! I'm currently refreshing my C++ skills and was wondering if it is possible to assign something to *this. I know assigning to this is forbidden, but can't find the same information for my case. An example: class Foo { int x; public: Foo(int x) : x(x) {} Foo incr() { return Foo(x+1); } void incr_() { (*this) = incr(); } }; ...

Detecting signed overflow in C/C++

At first glance, this question may seem like a duplicate of http://stackoverflow.com/questions/199333/best-way-to-detect-integer-overflow-in-c-c, however it is actually significantly different. I've found that while detecting an unsigned integer overflow is pretty trivial, detecting a signed overflow in C/C++ is actually more difficult ...

Pass an array back from a JNI function to without copying it

I am trying to use JNI to process large chunks of data using C++ however I am having trouble understanding weather the function SetArrayRegion will duplicate an array element by element or if it can just leave the data in place and return it to the calling java function. The following documentation is where I have been reading about i...

Changing TabControl tab title text background color c++

I am using Visual Studio 2005, C++, and I have a tabcontrol with a couple tabs. I have changed the color of each tab to have a back color of Transparent, to match the color of the rest of the program (Control grey), however the color behind the text for the title of the tab is white. Is there any way to change this? ...

C++ is Virtual destructor still needed if there are no data members in derived?

Suppose I have this code class Base{ public: int getVal(); private: int a, b; }; class Derived::public Base{ public: void printVal(); }; int main(){ Base *b = new Derived(); delete b; } I know a virtual destructor would delete things properly, but is it bad to delete with base pointer (w...

Allocating memory for delayed event arguments

Here is my issue. I have a class to create timed events. It takes in: A function pointer of void (*func)(void* arg) A void* to the argument A delay The issue is I may want to create on-the-fly variables that I dont want to be a static variable in the class, or a global variable. If either of these are not met, I cant do something lik...

MsgWaitForMultipleObjects sometimes returns WAIT_FAILED with no GetLastError value

I have a thread that creates COM objects that require a single threaded apartment. Originally, this thread's main function put it into a WaitForMultipleObjects loop. Evidently this is a problem, because it prevents the COM message pump from doing it's job. I replaced this with MsgWaitForMultipleObjects as a solution, but now I'm runnin...

Setting up CERN ROOT with an IDE

I'm interested in setting up an IDE (preferably Eclipse or Netbeans) for a project that uses C++ and ROOT and have it be able to compile for me. Is this possible? Source code is available for ROOT, so there should be some way of hooking these things together... ...

Why does free crash here?

The following crashes when it gets to free: (there is reasoning for using void*). bool s = true; void* arg = &s; argument = malloc(sizeof(arg)); memcpy(argument,arg,sizeof(arg)); free(argument); argument here is a void* why does free crash the application? Thanks ...