c++-cli

How do you 'cancel' a UdpClient::BeginReceive?

为君一笑 提交于 2019-12-04 01:28:59
问题 I have a thread which sits around waiting for UDP messages from multiple interfaces using UdpClient::BeginReceive and a callback which calls UdpClient::EndReceive to pick up the data and pass it on. If after 5 seconds I don't get anything, I return from the function which calls UdpClient::BeginReceive so that the process can be cancelled and to issue another broadcast which would trigger external clients to send in UDP responses. If we're not cancelling, I call the UdpClient::BeginReceive

How can I deterministically dispose of a managed C++/CLI object from C#?

Deadly 提交于 2019-12-04 00:55:18
I have a managed object in a C++/CLI assembly. Being C++/CLI, it implements the Disposable pattern through its "destructor" (yes, I'm aware it's not the same as a standard C++ destructor). From C++/CLI, I would simply delete the object. However, I am using this object as a member variable in a C# class. From my C# class, then, I would like to call the equivalent of the Dispose() method on the C++/CLI object when I am finished using it. Since it is (and must be) a member variable of the class, utilizing a using() block is out of the question. As far as I can tell, there is no exposed method for

How do you set the version of a C++/CLI project in Visual Studio?

时光怂恿深爱的人放手 提交于 2019-12-03 23:37:36
问题 I am working with a C++/CLI Project that wraps a C++ Native Library in Visual Studio 2012. My C++/CLI Project has an AssemblyInfo.cpp. I set all the fields there, which include an "AssemblyVersionAttribute". However when I built my project and check its properties in the Windows Explorer, the version information is empty. This is my first C++/CLI project, I have been going over all the options in the project properties but I couldn't find any that works for setting the version. How do you set

Implementing IEnumerable<T> in C++/CLI

老子叫甜甜 提交于 2019-12-03 23:35:56
I'm having problems implementing IEnumerable<T> in my custom collection class in C++/CLI. Here is the relevant part of the code: using namespace System::Collections::Generic; ref class MyCollection : IEnumerable<MyClass^> { public: MyCollection() { } virtual IEnumerator<MyClass^>^ GetEnumerator() { return nullptr; } }; When compiled, this results in the following errors: error C2392: 'System::Collections::Generic::IEnumerator ^MyCollection::GetEnumerator(void)': covariant returns types are not supported in managed types, otherwise 'System::Collections::IEnumerator ^System::Collections:

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

大兔子大兔子 提交于 2019-12-03 23:33:01
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! Daniel Earwicker 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 should be using C++/CLI. 来源: https://stackoverflow.com/questions/1133221/how-do-i-do-typeofint

Find programmatically if under C++ or C++/CLI

可紊 提交于 2019-12-03 23:25:58
I would like my C++/CLI headers to compile even when under another platform. Of course I am not expecting to compile them but just ignore them. Would this be appropriate ? (_MSC_VER) #ifdef _MSC_VER using namespace System; namespace ENMFP { public ref struct Data { }; } #endif Thanks ! You can use the __cplusplus_cli predefined macro documented here : #ifdef __cplusplus_cli using namespace System; namespace ENMFP { public ref struct Data { // ... }; } #endif // __cplusplus_cli 来源: https://stackoverflow.com/questions/9976194/find-programmatically-if-under-c-or-c-cli

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

对着背影说爱祢 提交于 2019-12-03 22:56:28
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. 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 through 9. 10: Informational messages that return status information or report errors that are not severe.

Issue in compiling with marshal.h : error C2872: 'IServiceProvider' : ambiguous symbol

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 22:09:56
I am trying to use the marshalling library in my C++/CLI project. When compiled with #include <msclr/marshal.h> I get the error error C2872: 'IServiceProvider' : ambiguous symbol . Most of the resolutions seems to be suggesting moving #include <windows.h> like the one here -> Ambiguous references , but I dont have those includes. All I have is: using namespace System; using namespace System::Configuration; using namespace std; #include <msclr/marshal.h> How do I debug this issue ? You do, indirectly, marshal.h includes it. It dumps an enormous amount of identifiers in the global namespace. The

System.AccessViolationException from unmanaged code?

狂风中的少年 提交于 2019-12-03 19:15:35
问题 I'm writing this library that implements some basic audio player features in C++/CLI via the Media Foundation framework that will be consumed by managed code. I can play audio, stop, pause, etc just fine. For anyone who is not familiar with Media Foundation, the media session posts events that you can handle for notifications. This is done by calling BeginGetEvent on the session object with an IMFAsyncCallback object. The IMFAsyncCallback defines the method Invoke(IMFAsyncResult) that you

Could C++.Net assemblies be decompiled easily?

一世执手 提交于 2019-12-03 16:43:12
I know that all assemblies can be decompiled somehow, but C# & VB applications are the easiest to be decompiled into source code using tools like ( .Net Reflector ). So my question is, if I programmed an application using .Net assemblies and functions with C++, would it be easy to decompile it as if it was a C# or VB application with .Net reflector and such tools? Ok, if I programmed it without using any function from .Net framework and made UI only what calls .Net assemblies, would be easy to decmpile also ? My question is similar to this one : Could this C++ project be decompiled with such