c++-cli

How to convert System::array to std::vector?

旧城冷巷雨未停 提交于 2019-11-27 18:42:38
问题 Is there any easy way to convert a CLI/.NET System::array to a C++ std::vector , besides doing it element-wise? I'm writing a wrapper method ( SetLowerBoundsWrapper, below ) in CLI/C++ that accepts a System::array as an argument, and passes the equivalent std::vector to a native C++ method ( set_lower_bounds ). Currently I do this as follows: using namespace System; void SetLowerBoundsWrapper(array<double>^ lb) { int n = lb->Length; std::vector<double> lower(n); //create a std::vector for(int

How to call C++ code from C#

久未见 提交于 2019-11-27 18:37:39
I have C++ code. That code contains Windows mobile GPS enable/disable functionality. I want to call that method from C# code, that means when the user clicks on a button, C# code should call into C++ code. This is the C++ code for enabling the GPS functionality: #include "cppdll.h" void Adder::add() { // TODO: Add your control notification handler code here HANDLE hDrv = CreateFile(TEXT("FNC1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (0 == DeviceIoControl(hDrv, IOCTL_WID_GPS_ON, NULL, 0, NULL, 0, NULL, NULL)) { RETAILMSG(1, (L"IOCTL_WID_RFID_ON

Conversion between Base64String and Hexadecimal

谁说我不能喝 提交于 2019-11-27 18:31:00
问题 I use in my C++/CLI project ToBase64String to give a string like /MnwRx7kRZEQBxLZEkXndA== I want to convert this string to Hexadecimal representation, How I can do that in C++/CLI or C#? 回答1: FromBase64String will take the string to byte s byte[] bytes = Convert.FromBase64String(string s); Then, BitConverter.ToString() will convert a byte array to a hex string ( byte[] to hex string ) string hex = BitConverter.ToString(bytes); 回答2: Convert the string to a byte array and then do a byte to hex

C++ vs. C++/CLI: Const qualification of virtual function parameters

一世执手 提交于 2019-11-27 18:13:19
问题 [All of the following was tested using Visual Studio 2008 SP1] In C++, const qualification of parameter types does not affect the type of a function (8.3.5/3: "Any cv-qualifier modifying a parameter type is deleted") So, for example, in the following class hierarchy, Derived::Foo overrides Base::Foo : struct Base { virtual void Foo(const int i) { } }; struct Derived : Base { virtual void Foo(int i) { } }; Consider a similar hierarchy in C++/CLI: ref class Base abstract { public: virtual void

IntelliSense: “#using” requires C++/CLI to be enabled

柔情痞子 提交于 2019-11-27 17:35:07
问题 #using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Text; using namespace System::IO; using namespace System::Net; using namespace System::Net::Sockets; using namespace System::Collections; Errors: IntelliSense: "#using" requires C++/CLI to be enabled.... how to fix this prob!? 回答1: Your project settings are wrong. Specifically Configuration Properties, General, Common Language Runtime support. Fall in the pit of success by starting your project by

Passing bitmap from c# to c++

北城余情 提交于 2019-11-27 16:35:53
问题 I have an image processing function written in C++ based on opencv. In my wpf application I have used AForge library to access a webcam and update it on UI. This the function for handling newframes. void UI_NewFrame(object sender, NewFrameEventArgs eventArgs) { try { System.Drawing.Bitmap bitmapFrame = (Bitmap)eventArgs.Frame.Clone(); MemoryStream ms = new MemoryStream(); bitmapFrame.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); BitmapImage bitmapImageFrame = new BitmapImage();

How to map Qt Signal to Event in Managed C++ (C++/CLI)

柔情痞子 提交于 2019-11-27 15:18:33
问题 I'm writing a wrapper in .NET (C++/CLI) to be able to use some native C++ Qt code in .NET. How can I map a Qt signal into a managed .NET event, so that when my Qt code fires off a signal, I can bring this forward to the .NET code. My Managed class defines the event, but if I try to use the normal QObject::connect method to hook up to the signal, it requires a QObject * receiver... I guess I have to do some magic marshalling of some sorts? 回答1: Define normal unmanaged Qt event handler. From

Incompatibility using managed array and std:array at same time

那年仲夏 提交于 2019-11-27 14:54:50
问题 I have my C++/CLI code using arrays like this (for example): array<String^>^ GetColNames() { vector<string> vec = impl->getColNames(); array<String^>^ arr = gcnew array<String^>(vec.size()); for (int i = 0; i < vec.size(); i++) { arr[i] = strConvert(vec[i]); } return arr; } It's compiling fine until I add the library "array" to the project: #include <array> Then I don't know how to use the managed CLI array, because the compiler thinks that all the declared arrays are the std::array . Errors

Debugging C++/Cli: <Unknown function> and no Locals

风流意气都作罢 提交于 2019-11-27 14:45:54
I am trying to debug a project with a C# assembly and a C++/Cli assembly. An interface defined in C# is inherited by a C++/Cli class, which in turn calls a native C++ class. Mixed-mode debugging is enabled in both C++ and C# assembly, as well as the startup .exe. Now, when I try to debug into the C++ part, it gets tricky; if I simply set breakpoints in the C++ part, they are not hit (despite the fact that I know that they are hit because logs (etc) are written and throwing an exception there actually will throw it properly). When I set a breakpoint at the latest call in C# before the call to

C++/CLI Support in .Net Core

泪湿孤枕 提交于 2019-11-27 13:04:46
问题 Our project structure is like, native.dll :- This contains pure native code written in c\c++. This native.dll exposes some functions using *def file. Wrapper Library(wrapper.dll compiled with .Net framework v4.0) :- In order to use functionality of native.dll , a Wrapper lib(wrapper.dll) is written in C++\CLI using :clr\oldsyntax . This wrapper has all code of Interoperability and Marshalling . Application(Console App v4.0) directly uses wrapper.dll to use functionality provided by native.dll