c++-cli

Lambdas don't appear to work within ref classes in VS2010

大城市里の小女人 提交于 2019-12-10 14:27:39
问题 One of the cool new C++ features in Visual Studio 2010 are lambda expressions. However, I can't get them to work within a managed class. class UnmanagedClass { void Foo() { // Creating empty lambda within unmanaged class. // This compiles fine. auto lambda = [](){ ; }; } }; ref class ManagedClass { void Foo() { // Creating empty lambda within managed class. // This creates error C3809: // A managed type cannot have any friend functions/classes/interfaces. auto lambda = [](){ ; }; } }; My best

C++ Struct Size unequal C++ Struct Size in C++/CLI?

落爺英雄遲暮 提交于 2019-12-10 14:21:42
问题 my question refers to the problem mentioned in the title. I have a simple struct in a header file that looks like this: typedef struct { WORD FileType; // File ID (0x7000) WORD HeaderSize; // Size of this file header in Bytes WORD HeaderVersion; // yy.y ULONG FileSize; // Size of the whole file in Bytes WORD ImageHeaderSize; // Size of the image header in Bytes WORD ULX, ULY, BRX, BRY;// bounding rectangle of the image WORD NrOfFrames; // self explanatory WORD Correction; // 0 = none, 1 =

how to turn boost::asio socket into C++/CLI .Net socket?

耗尽温柔 提交于 2019-12-10 14:14:20
问题 What I want is simple - code sample of creating new C++/CLI .Net socket from boost asio socket. How to create such thing? Here is pseudo code of what I would like to do: .net::socket a; boost::asio::socket b; a.assign(b.nativeWin32Socket()); BTW: Here is how to turn C++/CLI .Net socket into boost::asio socket. 回答1: You can't 'detach' a Boost.ASIO socket. You can use the native_handle() member function to get a SOCKET handle from the asio::socket object, but you must ensure that the asio:

How to use ConsoleCancelEventHandler several times

♀尐吖头ヾ 提交于 2019-12-10 13:48:27
问题 I've been busy coding a application that functions as a frontend: it has a GUI taking command line options with buttons and things like that and passing them to a command line .exe. It uses the console of the application to display the output of the command line app. This works fine, but when using Ctrl+C or trying to close the console window, the GUI closes too, which is not really what I want. However, letting the program output with it's own console is not possible because it batch

Can I have a function/method passing an argument by reference and an overload passing it by value in C++? [duplicate]

泄露秘密 提交于 2019-12-10 13:48:16
问题 This question already has answers here : Function Overloading Based on Value vs. Const Reference (5 answers) Closed 6 years ago . In C# this is certainly possible, as this compilable example can show: static void Teste(int x) { } static void Teste(ref int x) { } static void Teste() { int i = 0; Teste(i); Teste(ref i); } But can it be done in C++(/CLI) with a constructor? See the example below: class Foo { Foo(int bar) { // initializing "Foo" instance... } Foo(int &bar) { // initializing "Foo"

C++/CLI : Why can't I pass Strings by reference?

蹲街弑〆低调 提交于 2019-12-10 13:24:36
问题 Why doesn't Microsoft's C++/CLI allow me to pass strings by reference? I received the following error: C3699: '&': cannot use this indirection on type 'System::String' 回答1: Sounds like you are using Managed C++, which is a bastardised C++ used with the .NET Framework. in Managed C++, I believe the syntax you are looking for is System::String^ . The reason for this is that since managed types are garbage collected by .NET Framework, you aren't allowed to create 'regular' references since the

Pinning an empty array

℡╲_俬逩灬. 提交于 2019-12-10 13:14:08
问题 In C++/CLI, is it possible to pin an array that contains no elements? e.g. array<System::Byte>^ bytes = gcnew array<System::Byte>(0); pin_ptr<System::Byte> pin = &bytes[0]; //<-- IndexOutOfRangeException occurs here The advice given by MSDN does not cover the case of empty arrays. http://msdn.microsoft.com/en-us/library/18132394%28v=VS.100%29.aspx As an aside, you may wonder why I would want to pin an empty array. The short answer is that I want to treat empty and non-empty arrays the same

gcroot in c++/cli

时光毁灭记忆、已成空白 提交于 2019-12-10 12:33:33
问题 What does gcroot mean? I found it in code I am reading. 回答1: gcroot is a C++/cli template class that eases holding managed types in C++/cli classes. You can for example have the following: #include <msclr/gcroot.h> using namespace msclr; class Native { public: Native(Object ^obj) : netstring(obj->ToString()) { // Initializing the gcroot<String ^> } ~Native() { } void Print() { array<Char> ^chars = netstring->GetChars(); // Dereferencing the gcroot<String ^> _wprintf("netstring is:"); if

Why C++ CLI has no default argument on managed types?

依然范特西╮ 提交于 2019-12-10 12:32:19
问题 The following line has the error Default argument is not allowed . public ref class SPlayerObj{ private: void k(int s = 0){ //ERROR } } Why C++ has no default argument on managed types ? I would like to know if there is a way to fix this. 回答1: It does have optional arguments, they just don't look the same way as the C++ syntax. Optional arguments are a language interop problem. It must be implemented by the language that makes the call, it generates the code that actually uses the default

read multiple files with quite similar names c++

梦想的初衷 提交于 2019-12-10 12:25:49
问题 I am reading a file from current directory ifstream myfile; myfile.open("version1.1.hex"); Now a situation is arising that if user updates version then there will be version1.2.hex or version1.3.hex ..so on in the current directory, but one file at a time will be present. I want to write a code now which will cater this future need of reading different file. I'm writing this code in C++/CLI. 回答1: Since file listings are a bit environment-dependant I am not sure if this is helpful to you, but