c++-cli

How can convert this C# code to C++/CLI

情到浓时终转凉″ 提交于 2019-12-11 01:33:49
问题 How can I convert this segment of C# code to C++/CLI: protected string GetMD5HashFromFile(string fileName) { FileStream file = new FileStream(fileName, FileMode.Open); MD5 md5 = new MD5CryptoServiceProvider(); byte[] retVal = md5.ComputeHash(file); file.Close(); ASCIIEncoding enc = new ASCIIEncoding(); return enc.GetString(retVal); } Specially this part byte[] retVal = md5.ComputeHash(file); 回答1: Making liberal use of the stack semantics available in C++/CLI to automatically dispose objects.

Creating a multidimensional array in C++/CLI with an empty dimension size

安稳与你 提交于 2019-12-11 01:04:41
问题 I am working on converting a C# project to a C++/CLI project. I came across this code and wanted to verify that I am using the proper C++/CLI syntax. I am pretty sure I am doing it wrong, just setting parameters when I want to set the size of the dimensions. Original C#: public double[][] _ARRAY = new double[num][]; C++/CLI: array<double, 2>^ _ARRAY = gcnew array<double, 2>{ {num}, {} }; 回答1: That IS how you create a multidimensional array in C++/CLI. But the C# isn't actually a

What is the meaning of this strange syntax

与世无争的帅哥 提交于 2019-12-11 00:48:04
问题 Today I saw the following syntax. Can anybody tell me the meaning of this: System::ComponentModel::Container ^components; I got this code in Visual C++, after I used a wizard to create a service. 回答1: The ^ operator (not to be confused with the binary XOR operator) is specific to C++/CLI. It is used to declare a handle to a .NET managed object. A handle is a reference to the object which differs from traditional C++ pointers in the fact that it allows Garbage Collection to function correctly

How do I write to the CommandPrompt from Windows GUI?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 23:34:57
问题 Operating Environment: Windows 7, Visual Studio 2010, CLR GUI. So I've been given the unglorious task of enhancing a GUI application that is started from a command prompt. Because it is. Because poor design decisions by previous implementers. Anyway, it launches one of several GUIs depending upon the input arguments. I'd like to be able to print back to the same command prompt window if (when) the user types something that the code doesn't understand. Here's what I've tried (none of which

C++/CLI What class encloses global functions?

风格不统一 提交于 2019-12-10 21:48:59
问题 If I remember correctly, functions must be a member of a class in the CLR world, and yet global functions are possible in C++/CLI. Does this mean that these global functions are part of a hidden "global" class of some sort? If so, how would one go about getting its type, for reflection purposes? 回答1: Yes, .NET metadata supports global functions and variables. Called the "Global Class" in CLR source code, its name is <Module> . Using C# vernacular, it is internal , abstract and sealed to

Debugging a C executable with a C++-CLI Library compiled with /clr

旧巷老猫 提交于 2019-12-10 19:48:20
问题 I am using Visual Studio 2010 to debug an application mostly written in C. Normally, I can attach the debugger just fine, but I am running in to some problems when I link in a library written in C++ / CLI. If I compile the library with the /clr flag (which I will eventually have to do for this as of yet unwritten library) then I lose all ability to debug the entire C application, even the parts that have nothing to do with the library calls. I get the empty circle with the yellow triangle and

efficiently calling unmanaged method taking unmanaged objects as parameters from managed code

試著忘記壹切 提交于 2019-12-10 19:35:00
问题 I have the following scenario. The managed code will initialize lots of object of a class which is a wrapper around an unmanaged struct. There are two approaches that I can do for this. One is to have a managed class wrapper that just has a pointer to the unmanaged object. The other is to have a full fledged managed class and create the unmanaged object when required to call into unmanaged methods. I have provided both the methods below. I was told that if I use the approach 1(having a

How to use ColorMatrix in .NET to change Brightness, Color, Saturation, Hue

你离开我真会死。 提交于 2019-12-10 19:16:24
问题 I have a 'Bitmap' type containing some random bitmap data. I've written my own adjustments for Brightness, Color, Saturation, and Hue that act on each bit individually and, unsurprisingly, it's awful slow. In my research I've noticed that using matrices can be very fast in adjusting these. In addition, .NET has a ColorMatrix where you can apply the matrix effects when you DrawImage(). The matrix we set up looks like the following (from MSDN website): float[][] colorMatrixElements = { new

Is it possible to override IEnumerable in VC++/CLI?

六眼飞鱼酱① 提交于 2019-12-10 18:21:43
问题 I have an interface which returns an IEnumerable , and I want to implement this in VC++/CLI because the data comes from a third-party unmanaged DLL. So far I have: public ref class MyEnumerable : IEnumerable<SomeType^> { public: virtual IEnumerator<SomeType^>^ GetEnumerator(); } But the compiler complains with C2393: "Covariant returns types are not supported in managed types". Does that mean that I cannot implement IEnumerable s in C++, or is there a workaround? 回答1: Yikes, it is an awfully

error c1107 could not find assembly please specify the assembly search path using /AI or by setting the LIBPATH environment variable

蓝咒 提交于 2019-12-10 18:15:32
问题 I'm making two trivial C++/CLI projects, one is an executable and the other is a DLL. In the executable, I write #using "DllLibName.dll" and it gives me error c1107, which I though would be easy to solve. I googled for LIBPATH and went to Linker, General, Additional Library Directories and added the folder containing DllLibName.dll and it still wouldn't work. Same error. I tried replacing the directive with #using "D:\AbsolutePath\DllLibName.dll" and everything works. I don't wanna have to