c++-cli

How to convert array<System::Byte> to char* in C++ CLR?

拥有回忆 提交于 2021-02-17 19:41:44
问题 In my project, I pass a byte[] from C# to C++ CLR function. C++ CLR code: void TestByteArray(array<System::Byte>^ byteArray) { ... } C# code: byte[] bytes = new byte[128]; ... TestByteArray(bytes); In the TestByteArray() function, I need convert byteArray to char*, so that I can used it in native C++ code. How can I do such conversion? 回答1: void TestByteArray(array<System::Byte>^ byteArray) { pin_ptr<System::Byte> p = &byteArray[0]; unsigned char* pby = p; char* pch = reinterpret_cast<char*>

System:Uint32^ in C++/CLI compiles to VaueType in C#?

你离开我真会死。 提交于 2021-02-11 04:28:21
问题 In a C++/CLI class library I have the following function: static System::UInt32^ Fn() { return gcnew System::UInt32(0); } When I use the class library in a C# the System::Uint32 is a System::ValueType and the compiler error: Error 1 Cannot implicitly convert type 'System.ValueType' to 'uint'. An explicit conversion exists (are you missing a cast?) Why is it that when I'm defiing a System::UInt32 in C++/CLI I get a ValueType in C#? Thanks 回答1: UInt32 is a value type ( struct in C#), not a

System:Uint32^ in C++/CLI compiles to VaueType in C#?

旧巷老猫 提交于 2021-02-11 04:26:15
问题 In a C++/CLI class library I have the following function: static System::UInt32^ Fn() { return gcnew System::UInt32(0); } When I use the class library in a C# the System::Uint32 is a System::ValueType and the compiler error: Error 1 Cannot implicitly convert type 'System.ValueType' to 'uint'. An explicit conversion exists (are you missing a cast?) Why is it that when I'm defiing a System::UInt32 in C++/CLI I get a ValueType in C#? Thanks 回答1: UInt32 is a value type ( struct in C#), not a

How to avoid Visual C++ Redistributable LARGE file installing?

北城以北 提交于 2021-02-10 16:26:35
问题 I want to deploy a C++/CLI application on Windows 7 32bit clients. I have built it using Visual Studio 2017 and I noticed my project needs Visual C++ 2017 Redistributable. My executable file is less than 1 megabytes and the MSVCR dependency is 13 megabytes, which is really huge for this app. Is there any way I can reduce this amount of size? 回答1: I found a possible solution but I don't know if it is fine or not. I can compile my C++/CLI code with Visual Studio 2010 toolkit. So I would need C+

C++ Using System::String::Split

老子叫甜甜 提交于 2021-02-10 07:20:31
问题 I am trying to split a System::String at ":" using System::String::Split in my C++ code. The string to be split is called "responseString". It is a System::String. I have: char id[] = { ':' }; return responseString->Split(id); However, it errors at the "->" saying that no instance of the overloaded function matches the argument list. I checked the MSDN documentation, and see no information on doing this in C++. I also tried the following, with the same results: System::Char id[] = { ':' };

Cannot compile template C++/CLI (.NET Core 3.1) project via dotnet build command

若如初见. 提交于 2021-02-10 05:37:15
问题 Install latest stable Visual Studio 2019 16.4.2 (check .NET Core Development and Desktop development with C++ workloads, also make sure that C++/CLI support component in checked). Create new project with CLR Class Library (.NET Core) template (or CLR Empty Project (.NET Core) if you like). Compilation via dotnet build command will fail ( dotnet build CLRNetCoreTest.sln /p:Configuration=Debug /p:Platform=x86 ): Compilation via msbuild command is successfull ( "%ProgramFiles(x86)%\Microsoft

How to use System::Threading::Interlocked::Increment on a static variable from C++/CLI?

穿精又带淫゛_ 提交于 2021-02-08 07:38:42
问题 I would like to keep a static counter in a garbage collected class and increment it using Interlocked::Increment. What's the C++/CLI syntax to do this? I've been trying variations on the following, but no luck so far: ref class Foo { static __int64 _counter; __int64 Next() { return System::Threading::Interlocked::Increment( &_counter ); } }; 回答1: You need to use a tracking reference to your _int64 value, using the % tracking reference notation: ref class Bar { static __int64 _counter; __int64

Pass a c# array to a c++ method

时间秒杀一切 提交于 2021-02-08 04:10:46
问题 I have a CLR class library in c++: namespace ANN_Lib { public ref class ANN_FF_BP { private: int neurons; int inputs; int outputs; double **wi; double *wl; public: ANN_FF_BP(int neurons, int inputs, int outputs); void Train(double **p, double *t, int pairsCount, int epochs, double goal); }; } I am using this class as a reference in a WPF project: ANN_FF_BP neuralNetwork = new ANN_FF_BP(neurons, inputs, outputs); Now I want to call the Train() method (in WPF) from that class and pass in some

Pass a c# array to a c++ method

一世执手 提交于 2021-02-08 04:10:44
问题 I have a CLR class library in c++: namespace ANN_Lib { public ref class ANN_FF_BP { private: int neurons; int inputs; int outputs; double **wi; double *wl; public: ANN_FF_BP(int neurons, int inputs, int outputs); void Train(double **p, double *t, int pairsCount, int epochs, double goal); }; } I am using this class as a reference in a WPF project: ANN_FF_BP neuralNetwork = new ANN_FF_BP(neurons, inputs, outputs); Now I want to call the Train() method (in WPF) from that class and pass in some

What is the difference between type “long” in C++/CLI and C#?

ぃ、小莉子 提交于 2021-02-07 04:32:05
问题 In the C++/CLI project I have the method void DoSomething(long x); . If I want to use it in any unit-test written in C# , the method parameter x shows up as type int . Why do I have to change the signature to void DoSomething(long long x); to use it with parameters of type long in my unit-tests (C#)? 回答1: In C# long is a 64 bit data type. In C++ All we know about long is that it has to hold as much or more than an int and it is at least 32 bits. If you use a long long in c++ that is