c++

Stacking Cg shaders

In my engine I load Cg shaders from pairs of vertex/pixel shader files. I would like to be able to stack shaders to combine them (lighting + material, etc.). Short of breaking up the shaders into separate functions and then creating a single shader script string from those, do you know of any good ways of stacking different shaders in Cg...

Uploading a file over HTTP/HTTPS and/or FTP/FTPS on a Mac

I have found numerous examples on uploading a file to a web server via C++ on Windows. However I am struggling after a lot of searching (and I thought I was good with Google!) to find any examples to help me achieve the same on a Mac. Can anyone point me towards some help on how to upload a file to a web server on a Mac OS using either...

using accessors in same class

I have heard that in C++, using an accessor ( get...() ) in a member function of the same class where the accessor was defined is good programming practice? Is it true and should it be done? For example, is this preferred: void display() { cout << getData(); } over something like this: void display() { cout << data; } data...

Can't access a #defined constant in C

This is a C program that I was using, in the header file I define an offset: #define LDR_DATA_PATHFILENAME_OFFSET 0x24 // MODULE_ITEM.PathFileName Later in the program I use it as following: pImageName = (PUNICODE_STRING)( ((DWORD)(pUserModuleListPtr)) + (LDR_DATA_PATHFILENAME_OFFSET-dwOffset)); When inspecting the value of ...

SpiderMonkey vs JavaScriptCore vs ?

I have a C++ desktop application (written in wxWidgets) and I want to add support for some scripting language. Scripting would mostly be used for run-time conversions of strings, numbers and dates by user supplied JavaScript code. I'd like to use JavaScript because it is widely used and everyone is familiar with the syntax. Googling ...

tchar.h on linux

I am trying to write cross platform i18n C++ code. Since most linux system prefer to use UTF-8 as the character encoding, I thought that I should use string on linux and wstring on Windows. Is tchar.h available on linux? What is an equivalent replacement on for tchar.h on Linux? ...

What is the difference between _tmain() and main() in C++?

If I run my C++ application with the following main() method everything is OK: int main(int argc, char *argv[]) { cout << "There are " << argc << " arguments:" << endl; // Loop through each argument and print its number and value for (int i=0; i<argc; i++) cout << i << " " << argv[i] << endl; return 0; } I get wha...

OracleConnection throws EEMessageException in managed C++

I have an native C++ app which needs to connect to an Oracle DB. Oracle data layers written in C#.Net so was hoping to reuse the code as a dll. I decided to try using managed C++ to bridge the gap between native C++ and C#. The managed C++ adaptor layer works fine (almost). The unmanaged C++ exe can invoke various classes and meth...

Good methods for converting char array buffers to strings?

I am relatively new to C++. Recent assignments have required that I convert a multitude of char buffers (from structures/sockets, etc.) to strings. I have been using variations on the following but they seem awkward. Is there a better way to do this kind of thing? #include <iostream> #include <string> using std::string; using std::c...

[c++] tr1::unordered_set union and intersection

How to do intersection and union for sets of the type tr1::unordered_set in c++? I can't find much reference about it. Any reference and code will be highly appreciated. Thank you very much. Update: I just guessed the tr1::unordered_set should provide the function for intersection, union, difference.. Since that's the basic operation o...

C++ Threading Question

I have an object Foo which has a global variable, Time currentTime Foo has two methods which are called from different threads. update() { currentTime = currentTime + timeDelay; } restart(Time newTime) { currentTime = newTime; } I am seeing behavior on a restart, the time changes correctly and other times where currentTime d...

DLL interop / interesting error

char ARRAY[1024]; // <-- global Code below works myFunctionInDll("some string"); // everything ok Code below doesn't work myFunctionInDll(ARRAY); // after compilation the entry point of DLL cannot be found So, to sum up, if I pass a "static string" to my function inside my dll the dll compiles and loads perfectly. However, i...

Recursively generate ordered substrings from an ordered sequence of chars?

Edited after getting answers Some excellent answers here. I like Josh's because it is so clever and uses C++. However I decided to accept Dave's answer because of it's simplicity and recursion. I tested them both and they both produced identical correct results (although in a different order). So thanks again everyone. Say I have a st...

Use a "User Macro" in .vcproj RelativePath

Inside .vcproj files There is a list of all source files in your project. How can we use a macro to specify the path to a source file? If we do this: <File RelativePath="$(Lib3rdParty)\Qt\qtwinmigrate-2.5-commercial\src\qmfcapp.cpp"> </File> The compiler cannot find the folder: qmfcapp.cpp c1xx : fatal error C1083: Cannot open so...

COM Error 0x80004003 (Invalid Pointer) access MS Outlook contacts

I am some ATL code that uses smart COM pointers to iterate through MS Outlook contacts, and on some PC's I am getting a COM error 0x80004003 ('Invalid Pointer') for each contact. The same code works fine on other PCs. The code looks like this: _ApplicationPtr ptr; ptr.CreateInstance(CLSID_Application); _NameSpacePtr ns = ptr->GetName...

C++ struct member, what type to keep calendar time on iPhone?

I need to keep datetime in a C++ structure for an iPhone app. The time will be saved and restored into sqlite db. What is the best data type and corresponding API for this? My candidates are: time_t and struct tm from <ctime> and <time.h> NSTimeInterval from <NSDate.h> TimeValue from the QuickTime API My instinct is to go with the g...

cout or printf which of the two has a faster execution speed C++?

I have been coding in C++ for a long time. I always wondered which has a faster execution speed printf or cout? Situation: I am designing an application in C++ and I have certain constrains such as time limit for execution. My application has loads printing commands on the console. So which one would be preferable printf or cout? Thank...

Most accurate line intersection ordinate computation with floats ?

I'm computing the ordinate y of a point on a line at a given abscissa x. The line is defined by its two end points coordinates (x0,y0)(x1,y1). End points coordinates are floats and the computation must be done in float precision for use in GPU. The maths, and thus the naive implementation, are trivial. Let t = (x - x0)/(x1 - x0), then...

Convert lib + header file to DLL

I have a library (lib file + .h header file). I like to turn it into a DLL so I can easiliy use it in VB6. Is there a convenient way to do this? ...

Decrease Qt GUI application size

Hi! I'm learning to develop apps using Qt Creator. I have built a simple app under Windows, depends on uses mingwm10.dll, QtCore4.dll, QtGui4.dll, QtNetwork4.dll. Out of QtQui4.dll I use only a a couple of widgets, and don't need all of the rest... Is it possible to either shrink the size of QtGui4.dll or do something else to decrease de...