c++

Problem assigninging values to a struct in C++ to a structure passed from C#

I have a function in C# that is passing an array of structures into a DLL written in C++. The struct is a group of ints and when I read out the data in the DLL all the values come out fine. However if I try to write to the elements from C++ the values never show up when I try to read then back in C#. C# [StructLayout(LayoutKind.Sequent...

Optimal way to perform a shift operation on an array

Suppose I have an array unsigned char arr[]= {0,1,2,3,4,5,6,7,8,9}; Is there a way to perform shift operation on them besides just copying them all into another array. We can easily do it using linked lists but I was wondering if we can use a shift operator and get work done faster. Note: The data in this question is just an example....

Change Clickonce cache directory

We have been using ClickOnce deployment for some time now and all has been fine until recently. We have one of our clients that is now deleting their clients Documents and Settings directories which inturn is totally erasing our clickonce cache. From what I have seen, there is no way of setting an alternate location for this, but many ...

C++ client for Java RMI? Or any other way to use Java from C++?

Hi, We need to use a Java library from C++ code. An idea that I had is that if we could build a C++ client for Java RMI (ideally using some framework or wizard), than we could run the Java lib as a separate server. This seem cleaner than trying to run Java VM within a C++ application. Alternatively, if you have any other idea on how t...

xerces-c++ compile/linking question

After installing Xerces-C++ (XML library): ./configure --disable-shared ./make ./make-install ldconfig And writing the simple program (xmlval.cpp): #include <stdio> #include <xercesc/dom/DOM.hpp> int main() { std::cout << "HI" << std::endl; } And compiling: /usr/bin/g++ -L/usr/local/lib -I/usr/local/include -o xmlval xmlval.c...

How to implement icmp packet handler using winsock version 1.1?

I am working on an very old application right now. I need to make change in this application to listen for coming icmp request and decide to reply or drop the packet (kind of access control on ICMP). The application is Winsock version 1.1 based. I tried different ways to create a socket and capture icmp packet using the socket. But none ...

Set a file wide breakpoint in gdb

Hello everyone, I'm trying to understand how a piece of code is working. I've enabled a breakpoint for a function, but it looks like it never gets hit. So, I'd like to break whenever ANY function within this class is invoked. Is this possible? Thanks! ...

Using a Set Iterator in C++

When I try to use a set iterator in debug mode in C++, I get an error that says "map/set iterator not dereferencable". I don't understand because I thought dereferincing was how you are supposed to use an iterator. The code looks like this: set<int>::iterator myIterator; for(myIterator = mySet.begin(); myIterator != mySet.end(); ...

C++ convert decimal hours into hours, minutes, and seconds

I have some number of miles and a speed in MPH that I have converted into the number of hours it takes to travel that distance at that speed. Now I need to convert this decimal number into hours, minutes, and seconds. How do I do this? My best guess right now is: double time = distance / speed; int hours = time; // double to integer con...

Compiling a static lib inside a exe

I have a dll and an exe, both of which I have the sources to. For the DLL I have compiled completely statically and therefore, I would assume that the the .lib is also static. However, when I include that lib in my C++ VC++ 2008 project under Linker > Input > Additional Dependencies . I set the compile mode to /MT (multi-threaded) for t...

Is there a standard sign function (signum, sgn) in C/C++?

I want a function that returns -1 for negative numbers and +1 for positive numbers. http://en.wikipedia.org/wiki/Sign%5Ffunction It's easy enough to write my own, but it seems like something that ought to be in a standard library somewhere. Edit: Specifically, I was looking for a function working on floats. ...

C++ openssl for digitally signing data

I would like to use OpenSSL in C++ to digitally verify signed data. Here is what I want to do: use the openssl command line to sign a file, with my private key. send the data to the program the program will verify the signature (public key stored internally), and will check if it's correct Also I would like to add ablity to encrypt/...

Passing a pointer to a base class to derived class's member functions in C++

How to access the derived class's data from one of its instances' member function that receives a pointer to the base class? I have: class Base{ public: virtual void compare(Base*)=0; }; class A: public Base{ int x; public: A(); void compare(Base*); }; cla...

How do I create a WT project in MSVC ?

Hi, if anyone has used WT successfully with MSVC (mine is 2005), could you please provide some details on how this can be done? I have installed WT fine , then ran some examples. The problems begin when I try to create a project of my own, as simple as hello.C. I get a thousand compiler errors like this one : C:\Program Files\Microsoft...

C++ Boost date with format dd/mm/yyyy?

How could I print the current date, using Boost libraries, in the format dd/mm/yyyy H? What I have: boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); cout << boost::posix_time::to_simple_string(now).c_str(); 2009-Dec-14 23:31:40 But I want: 14-Dec-2009 23:31:40 ...

Global Variable Count

How to count the number of global variables in C++ with a program that I can run with Grep? ...

Borland Assertion failed in local_unwind()

I have a comms server that is supposed to run for an indefinite amount of time. However, it sometimes errors with Assertion failed: !"bogus context in Local_unwind()", file xx.cpp, line 2262 which is followed by Abnormal Program Termination after which pressing ok causes the program to disappear. This problem happens interm...

Building VOIP into an application (C++ specifically)

Are there existing libraries and frameworks which allow VOIP to be built into a bespoke application without reinventing the wheel? A customer is interested by the possibility for a C++ desktop application and while it's not hugely useful (they could just use skype), it is quite cool. I believe some technologies like DirectX may have som...

C++ RTTI and Derived Classes

My C++ is a bit rusty. Here's what I'm attempting to do: class Cmd { }; class CmdA : public Cmd { }; class CmdB : public Cmd { }; ... Cmd *a = new CmdA (); Cmd *b = new CmdB (); First problem: cout << typeid (a).name () cout << typeid (b).name () both return Cmd * types. My desired result is CmdA* and CmdB*. Any way of accomplis...

From C# to C++, good references?

Hi, I've just completed my second OOP class, and both my first and second classes were taught in c#, but for the rest of my programming classes, we will be working in c++. Specifically, we will be using the visual c++ compliler. The problem is, we are required to learn the basics of c++ ourself, with no transition from our professor. So...