c++

Given text in a #define, can it somehow be passed to a template?

Say I have a macro, FOO(name), and some template class Bar<> that takes one parameter (what type of parameter is the question). Everytime I call FOO with a different name, I want to get a different instantiation of Bar. The Bar<> template doesn't actually need to be able to get at the name internally, I just need to be sure that differen...

What does this mean const int*& var?

I saw someone using this void methodA(const int*& var); in one answer, but couldn't understand what the argument means. AFAIK: const int var => const value which can't be changed const int* var => pointer to int which is const i.e *var can't be changed but var can be changed const int& var => reference to const int i.e value of va...

Variable sized structs with trailers

I posted on this topic earlier but now I have a more specific question/problem. Here is my code: #include <cstdlib> #include <iostream> typedef struct{ unsigned int h; unsigned int b[]; unsigned int t; } pkt; int main(){ unsigned int* arr = (unsigned int*) malloc(sizeof(int) * 10); arr[0] = 0xafbb0000; arr[...

Boost Program Options Examples

In the boost tutorials online for program options : http://www.boost.org/doc/libs/1_39_0/doc/html/program_options/tutorial.html#id2891824 It says that the complete code examples can be found at "BOOST_ROOT/libs/program_options/example" directory. I could not figure out where is this. Can anyone help me finding the examples? ...

Windows user credential validation on a different domain

Hi, I'm trying to validate a user's windows credentials on a computer that's not joined to the domain. It seems like this should be possible to do using the SSPI API, but I haven't been able to get it to work. I included the code that I've been trying (resource cleanup omitted for brevity). These are the important pieces of informatio...

Writing an app to interact with SQL 2008 without managed code

I want to write a winPE(vista) application that connects to a DB and just writes a row in a table saying it booted winPE. Here is my problem. I only ever do .NET. I'm pretty familiar with OO concepts so I'm finally taking the plunge to unmanaged code. I assume I have to use visual studio's unmanaged c++ project type, but I don't know wh...

Can I use a mask to iterate files in a directory with Boost?

I want to iterate over all files in a directory matching something like "somefiles*.txt". Does boost::filesystem have something built in to do that, or do I need a regex or something against each leaf()? ...

Using break in nested loops

Hello everyone, Quick question, is it proper to use the break function to exit many nested for loops? If so, how would you go about doing this? Can you also control how many loops the break exits? Thanks, -Faken ...

Getting mouse position unbounded by screen size, c++ & windows

I'm currently writing a c++ console application that grabs the mouse position at regular intervals and sends it to another visual application where it is used to drive some 3d graphics in real time. The visual app is closed source and cannot be altered outside it's limited plug-in functionality. Currently I'm using the GetCursorPos()...

wxWindows vs. Gtk for Cross Platform GUI Programming

I've been looking at making a cross-platform GUI application, and I'm wondering whether I should use wxWindow or GTk? I'll be coding in C++, so the quality of the documentation surrounding its C++ bindings is key. I've heard that GTk works better with plain C than with C++. Is this true? ...

How to layout the code of a simple game?

I'm coming from a background mostly developing websites, and maybe some simple form-based apps. MVC works well for that, but I don't quite see how that's applicable to a game. So how do you guys do it? I'm developing with Qt and OpenGL, if that's relevant. I have a QGLWidget which I'm basically using as a central hub at the moment. Shou...

0xDEADBEEF equivalent for 64 bit development?

For C++ development for 32-bit systems (be it Linux, Mac OS or Windows, PowerPC or x86) I have initialised pointers that would otherwise be undefined (e.g. they can not immediately get a proper value) like so: int *pInt = reinterpret_cast<int *>(0xDEADBEEF); (To save typing and being DRY the right-hand side would normally be in a ...

Is it OK to use "delete this" to delete the current object?

I'm writing a linked list and I want a struct's destructor (a Node struct) to simply delete itself, and not have any side effects. I want my list's destructor to iteratively call the Node destructor on itself (storing the next node temporarily), like this: //my list class has first and last pointers //and my nodes each have a pointer to...

Best way to serialize a Float in java to be read by C++ app?

Hi, I need to serialize a java Float to be read by an application written in C++ over Socket comms. Is there a standard for this? It would be easiest to use the method floatToIntBits in the Float Class, however I am not sure how standard that is. ...

Will using goto cause memory leaks?

Hello everyone, I have a program in which i need to break out of a large bunch of nested for loops. So far, the way most people have been telling me to do it is to use an ugly goto in my code. Now, if i create a bunch of local stack (i think that's what they are called, if not, i mean just regular variables without using the new comma...

Language integration

I may be the minority here, but it seems through my entire academic/professional career I've been taught varying languages. During this time, syntax and programming paradigms were the focus, but at no point were we taught about integrating systems written using varying languages and the proper way to make this decision. Now for the rec...

Logging exchange of messages by a process

I am currently having an OS which does support logging mechanisms like syslog. However, it is tedious when it comes to debug a process ie to find out what events or messages have a particular process exchanged with other processes in the system. Can any one suggest me a better mechanism to do the same ? ...

Locking files in windows

I am working on some legacy code which opens a file and adds binary data to the file: std::ifstream mInFile; #ifdef WINDOWS miWindowsFileHandle = _sopen(filename.c_str(), O_RDONLY , SH_DENYWR, S_IREAD); #endif mInFile.open(filename.c_str(), std::ios_base::binary); For some reason the code opens the file twice...

How to programmatically (C/C++) get Country code on Linux?

I'm porting my application into Linux (from Windows). I have such code: char buffer[32] = {0}; if ( GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ICOUNTRY, buffer, _countof(buffer)) ) { std::string newPrefix(buffer); if ( !newPrefix.empty() } } I need a fuction which return "country/region code, based on international pho...

Hex to String Conversion C++/C/Qt?

Hi all, I am interfacing with an external device which is sending data in hex format. It is of form > %abcdefg,+xxx.x,T,+yy.yy,T,+zz.zz,T,A*hhCRLF CR LF is carriage return line feed hh->checksum %abcdefg -> header Each character in above packet is sent as a hex representation (the xx,yy,abcd etc are replaced with actual numbers)....