c++

How to receive strings from C# in Visual-C++ based .net DLL?

How to receive strings from C# in Visual-C++ based .net DLL? In C++ (using clr) I have this code: #include "stdafx.h" ##include <Windows.h> #include <string> #include <windows.h> namespace NSST { public ref class Wrapper { public: Wrapper() {} static void init_1(std::string a, std::string b){} static void init_2(){}...

How to turn System::String^ into std::string?

So i work in clr, creating .net dll in visual c++. I tru such code: static bool InitFile(System::String^ fileName, System::String^ container) { return enc.InitFile(std::string(fileName), std::string(container)); } having encoder that normaly resives std::string. but here the compiler (visual studio) gives me C2664 error if I str...

Can I add numbers with the C/C++ preprocessor?

For some base. Base 1 even. Some sort of complex substitution -ing. Also, and of course, doing this is not a good idea in real life production code. I just asked out of curiosity. ...

boost deadline_timer question

I expected the code below to print Hello, world! every 5 seconds, but what happens is that the program pauses for 5 seconds and then prints the message over and over with no subsequent pauses. What am I missing? #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace boost::as...

Const confusion in C++

Possible Duplicate: Why is my return type meaningless? Hi, I'm confused about a particular const conversion. I have something like // Returns a pointer that cannot be modified, // although the value it points to can be modified. double* const foo() { static double bar = 3.14; return &bar; } int main() ...

C++ for iphone crash

Hey guys, Im developing a game engine for iphone in C++ but im getting a crash with my Matrix class. I hope you can see whats wrong because i stare my self blind on the crash. /* * Copyright (c) 2010 Johnny Mast * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated docum...

c++ native WebBrowser timeout catching

I can't google for C++ for some reason, like it ignores ++ completely and returns me stuff on C#. That aside, I have never used Visual C++ before (Windows Forms app) and I can't figure out how to catch any errors in the WebBrowser. I'd like to pop up a message saying that the server is offline and exit the application if navigation c...

What are the caveats to using inline optimization in C++ functions?

What would be the benefits of inlining different types of function and what are the issues that would I would need to watch out for when developing around them? I am not so useful with a profiler but many different algorithmic applications it seems to increase the speed 8 times over, if you can give any pointers that'd be of great use to...

Bitmap transfer using Winsock, GetDIBits and SetDiBits

Hello. I started working on something similar to a remote control application in c++. I wish to transfer a particular window's screenshot to another PC and display it in a window. Both GetDIBits and SetDIBits functions succeed, the connection is established, the data is sent, yet the image does not appear on the other side, just blacknes...

Header Files Mystery

Possible Duplicate: what is the difference between #include <filename> and #include filename Why do we use Quotation Marks ("...") for custom build classes and braces for built in classes(<...>)? ...

Can you explain in more detail what's the difference between PIPE_READMODE_MESSAGE/PIPE_READMODE_BYTE?

Though I've go through the document here, it still doesn't make sense to me what it is: Data is read from the pipe as a stream of messages. This mode can be only used if PIPE_TYPE_MESSAGE is also specified. ...

WinINet trouble downloading file to client?

I'm curious why I'm having trouble with this function. I'm downloading a PNG file on the web to a destination path. For example, downloading the Google image to the C: drive: netDownloadData("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png", "c:\file.png"); The file size is correct after downloading. Nothing returning false. W...

Declaring array using a variable in C++

Hi, I am writing a program that needs to take text input, and modify individual characters. I am doing this by using an array of characters, like so: char s[] = "test"; s[0] = '1'; cout << s; (Returns: "1est") But if I try and use a variable, like so: string msg1 = "test"; char s2[] = msg1; s2[0] = '1'; cout << s1[0] I get an erro...

Should I use string or char[]?

So I want to have a buffer with an array of structs like this: EventItem { tag; // some string or array of characters to describe the value; value; // some integer or something } The value can be anything like int32. What I am concerned about is the tag. If I have an array of these objects, and I make the tag a string, what hap...

Reference Counted Objects and multiple Allocators

Hi Guys. This is a design question, assuming C++ and a reference counted object hierarchy. A lot of classes in my codebase derive from a common base class (ObjectBase), which implements retain() and release() methods to increase and decrease the reference count of an object instance. Every instance of an object may be created on the st...

how can I read exactly 128 bytes from an fstream into a string object?

How do I read exactly 128 bytes from an fstream into a string object? I wrote some code to read the first 128 bytes of a file and print it and then the last 128 bytes of the file and print that. The last part works, since you can easily iterate to EOF, but how do I get exactly 128 bytes from the front? The code below doesn't work since ...

Boost::Date from_simple_string performance

After profiling some code I've found boost::gregorian::from_simple_string to be inefficient in loops with many iterations. Instruction read counts from using this function seem to be inordinately high. I've tried the locale/facets + stringstream method discussed in this thread but followup profiling didn't show any noticeable improvement...

c++ vectors erase check

Is there a way in C++ to check that erase succeeds? I have two pieces of code that erase the same object. The first erased the object, then the second tries to erase it but doesn't find the object. Any ideas? for(long indexs=0; indexs < (long)Enemie1.vS2Enemie1.size(); indexs++) { if((vRegularShots[index].x>=Enemie1.vS2Enemie1[inde...

multithreading hack

Hello, I am writing a numerical program that should be somewhat fast, and is also multithreaded. I have a class that represents a number, and I want to use in it a random number generator. Now, I don't really require my RNG to be a true RNG, I just need it to generate integers with even distribution between 0 and NMAX. So I have this i...

How to send/receive data with complicated data structure via pipe?

HRESULT GrabberCB :: SampleCB ( double SampleTime , IMediaSample * pSample ) { How to send the pSample content via pipe? } I know how to send/receive string by WriteFile/ReadFile after reading this sample: http://msdn.microsoft.com/en-us/library/aa365592%28v=VS.85%29.aspx But how to send a pSample over? ...