c++

Passing C# data type parameters to dll written in C++?

Still working on a problem that started from here Calling C++ dll function from C#: Of structs, strings and wchar_t arrays., but with a different approach. Following the example Calling Managed Code from Unmanaged Code and vice-versa I wrote a managed wrapper in C++ to access the unmanages class in the unmanaged C++ dll. It looks like ...

Howto Construct Char Arrays

Dear all, I have the following code that tries to enumerate strings. #include <string> #include <iostream> using namespace std; string base = "000"; char values[] = {'0', '1', '2', '3' }; // Error Here for (int i = 0; i < base.length(); ++i) { for (int j = 0; j < countof(values); ++j) { if (base[i] != values[j]) ...

How can protocol-buffers support serialization/deserialization of std containers?

We plan to replace Boost.serialization with protocol-buffers used in distributed system design. How protocol-buffers support complicated data structures such as std containers? For instance, such a class is required to be serialized/deserialized in our case: class Foo { std::vector< std::pair< unsigned int, std::vector< std::pair< in...

Best practices for a C++ portable opensource application

I am starting an open source cross platform project in C++. My development environment is Linux. There may be other developers who develop from different platforms as well. So I need some help in getting started with the configuration and development environment setup, so that all developers from multiple platforms can develop easily. ...

C++ how to copy a map to a vector

What's the best way in C++ to copy a pair from a map to vector? I'm doing this so I can subsequently sort the vector. ...

Howto Pass Filehandle to a Function for Output Streaming

Dear all, I have the following template function which prints to cout: template <typename T> void prn_vec(const std::vector < T >&arg, string sep="") { for (unsigned n = 0; n < arg.size(); n++) { cout << arg[n] << sep; } return; } // Usage: //prn_vec<int>(myVec,"\t"); /...

"Already listening" when invoking an RPC call

I use Microsoft RPC for interprocess communications. I have an interface with a set of methods accepting a byte pipe as an "in" parameter (IDL description): [ uuid(ActualGuidHere), version(1.0), pointer_default(unique) ] interface IMyInterface { //other irrelevant methods here error_status_t rpcDoAction( [in] pipe...

Why does operator< need to be overloaded when implementing class-based priority queues in c++?

note, I am not asking for answers. I simply am curious regarding why things work I need to implement a priority queue for a printer simulator for a class assignment. After looking at examples on the internet, I noticed that operator< was being overloaded in order to arrange the priority queue correctly. code in question: java2s prior...

Normalize file path with WinAPI

Given two file path strings with potentially different casing and slashes ('\' vs '/'), is there a quick way (that does not involve writing my own function) to normalize both paths to the same form, or at least to test them for equivalence? I'm restricted to WinAPI and standard C++. All files are local. ...

What does it mean when you get a compile error "looks like a function definition" for a class declaration?

I recently encountered this problem. I found many instances of people asking the questionhere, for examplebut no concrete answers. Here's the sample code hoisted from that link: class AFX_BASE_APPLICATION_APP_CLASS CFileExtension { public: CFileExtension (); virtual ~CFileExtension (); }; The error this generates is...

How to Write Strings Into Binary File

With this code I tried to print the string "foo" 10 times in binary format. But why doesn't the function to do it work? #include <iostream> #include <fstream> using namespace std; template <typename T> void WriteStr2BinFh (string St, ostream &fn) { for (unsigned i = 0; i < St.size(); i++) { char CStr = St[i]; fn....

Content of Binary Output File Created With Output Stream

Dear all, This code compiles and does execute. It simply print the content into a binary format. However the output differs from what I expected, namely: Output file size should be much smaller that those created with std::cout. The content of output file should be compressed, hence when we open it in editor, we should not be able to...

"Multiple definition of" C++ compiler error

I can't seem to get rid of these seemingly random compiles errors in one of my classes. I get about 4 errors such as: multiple definition of `draw_line(float, float, float, float)' and multiple definition of `near_far_clip(float, float, float*, float*, float*, float*, float*, float*)' that are flagged in the middle of the method. I a...

About C/C++ stack allocation

While studying C++ (and C) I had some particular doubts regarding the working of stack allocation, that I can't find a solution to: Does stack allocation call malloc/free functions implicitly? If not; how does it assure there is no conflict between stack allocation and heap allocation? If yes; does stack allocation in C++ implicitly ca...

How do I do floating point rounding with a bias (always round up or down)?

I want to round floats with a bias, either always down or always up. There is a specific point in the code where I need this, the rest of the program should round to the nearest value as usual. For example, I want to round to the nearest multiple of 1/10. The closest floating point number to 7/10 is approximately 0.69999998807, but th...

Does C# clean up C++ allocated memory?

I have a hypothetical COM object with the following signature void MemAlloc(ref double[] test, int membercount) where the memory is allocated in C++ using new/malloc. Once this is in C#, using the RCW, how do I ensure that the memory is freed correctly? I would think it would be difficult for .NET to free, considering in C++ you need ...

How can I check if a client disconnected through Winsock in C++?

How can I check if a client disconnected through Winsock in C++? ...

Does C++ have a sequential search function?

I have a small unsorted array and I'd like to find the index of a particular value. Does C++ have a built-in sequential search function for this, or do you just write the loop yourself each time it comes up? I'm specifically using a C-style array like: std::string arr[5] = { "EVEN", "ODD", "NONE", "MARK", "SPACE" }; and I need the i...

log4cpp in borland codegear 2007

I'm trying to make work the library and run the tests provided with the latest version of log4cpp on Borland Codegear 2007, in which it's included a bpr project for Borland C++ Builder 5, which it's meant to be able to build and run the different tests. The problem is that i'm trying to open this project with the 2007 version, which has ...

C++ random float

How do I generate random floats in C++? I thought I could take the integer rand and divide it by something, would that be adequate enough? ...