c++-cli

Initialize static Dictionary while creating in C++/CLI

蓝咒 提交于 2019-12-09 16:06:13
问题 Today I saw C# code that creates static dictionary and initializes it: public static readonly Dictionary<string, string> dict = new Dictionary<string, string>() { {"br","value1"}, {"cn","value2"}, {"de","value3"}, }; but when I decided to write same code for C++/CLI, an error occurred. Here is my attempt: static System::Collections::Generic::Dictionary<System::String^, System::String^>^ dict = gcnew System::Collections::Generic::Dictionary<System::String^, System::String^>( ) { {"br","value1"

Exposing an ISO C++ class to C#

感情迁移 提交于 2019-12-09 14:29:14
问题 I need to expose some C++ classes to C# (I am building on Linux, using mono, so COM is not an option) The evidence I have gathered so far suggests that the best way to approach this is: Write a wrapper C++.Net class around the ISO C++ class Consume the C++.Net classes from C# I have the following questions: First, is this the "best" way of achieving the goal of exposing ISO C++ classes to C# ? So far though, I have not seen any examples that actually show how to do this - can anyone suggest

Is there an overview of all SQL Server 2012 error codes?

穿精又带淫゛_ 提交于 2019-12-09 14:16:26
问题 SQLGetDiagRec returns a native error code. Is there anywhere an overview of the error codes of SQL Server 2012? I couldn't find anything on MSDN. 回答1: I'm unable to find a list of the individual codes in the internet. However I did find a list of the severity levels here on MSDN. They are as follows: Severity level / Description 0-9: Informational messages that return status information or report errors that are not severe. The Database Engine does not raise system errors with severities of 0

How do I do typeof(int) in Managed C++?

廉价感情. 提交于 2019-12-09 14:01:59
问题 I am working on a project now and part of it uses Managed C++. In the managed C++ code, I am creating a DataTable. While defining the Columns for the datatable, I need to specify the Type of the column. In C#, that would: typeof(int) but how do I do that in Managed C++? Thanks! 回答1: In C++/CLI, use the typeid keyword. e.g. Type ^t = Int32::typeid; In the older "Managed C++ Extensions" syntax, you'd use __typeof(Int32) , but that whole version of the language is severely deprecated and you

Can I use mock objects to mock a serial port?

℡╲_俬逩灬. 提交于 2019-12-09 13:34:53
问题 I am developing an application in C++/CLI that communicates with a device via a Serial Port. and testing them using MS Test. I'm just reading up about mock objects and have only understood it conceptually. I face many challeneges in unit testing, primarily because the simulator I use to send data over the serial port to my app behaves in a certain way and I cant get it to change its behaviour. What I would like to know is: Can I use mock objects to mimic the Serial Port behaviour? its input

C++/CLI Inheriting from a native C++ class with abstract methods and exposing it to C#

谁都会走 提交于 2019-12-09 12:14:31
问题 I've been googling around in circles trying to find an fully fledged example to this but to no avail. I have a C++ API that presents a number of classes that contain pure virtual methods for the developer to extend from. What I'm attempting to do is provide this interface to C# via the C++/CLI. I've managed to get the API compiled into the C++/CLI library and I've reached a sticking point as I'm new to this. I'm aware that I need to create a wrapper to expose the C++/CLI unmanaged class to a

ComVisible in C++/CLI

故事扮演 提交于 2019-12-09 12:04:50
问题 i'm converting C++ to C++/CLI and would like to expose some managed classes as COM objects. In C# it was easy and setting [ComVisible] & inheriting from interface (also ComVisible) did the job. However C++ project build as C++/CLI does not export DllRegisterServer. Here is sample project (started from CLR Console Application project in VS 2008). #include "stdafx.h" using namespace System; using namespace System::Runtime::InteropServices; [ComVisible(true)] [Guid("E3CF8A18-E4A0-4bc3-894E

C++ CLI System.String^ to MFC LPCTSTR

半世苍凉 提交于 2019-12-09 09:41:12
问题 How would I convert a System (.net) C++\CLI String^ into a MFC C++ LPCTSTR string. It is very easy to get a LPCTSTR into String^ , but so far found nothing on doing it the other way around. 回答1: If you have Visual Studio 2008 or above, you should be able to do this using the C++/CLI marshaling library, like so: #include <msclr\marshal.h> using namespace System; using namespace msclr::interop; ... String^ cliString; marshal_context context; LPCTSTR cstr = context.marshal_as<const TCHAR*>

How do people handle warning C4793: 'some_function' : function compiled as native?

二次信任 提交于 2019-12-09 07:55:31
问题 I'm using the OpenCV library and one of its header files, cxoperations.hpp, generates "warning C4793: 'anonymous namespace'::CV_XADD' : function compiled as native" , if my C++ project is compiled with CLR support. I can prevent the warning by surrounding the OpenCV header include like this: #pragma managed(push,off) #include <cv.h> #pragma managed(pop) But the project that actually uses OpenCV isn't compiled with CLR support, it's a native C++ static library. The project that does have CLR

What are the situations or pros and cons to use of C++/CLI over C#

流过昼夜 提交于 2019-12-09 05:45:56
问题 I have been keeping up with .NET CLR for awhile now, and my language of choice is C#. Up until recently, I was unaware that C++/CLI could produce "mixed mode" executables capable of running native and managed code. Now knowing this, another developer friend of mine were discussing this attribute and trying to determine when and how this ability would be useful. I take it as a given that native code has the capability to be more efficient and powerful than managed code, at the expense of