c++-cli

C++/CLI delegate as function pointer (System.AccessViolationException)

蹲街弑〆低调 提交于 2021-02-06 15:15:48
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

C++/CLI delegate as function pointer (System.AccessViolationException)

纵饮孤独 提交于 2021-02-06 15:14:34
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

C++/CLI delegate as function pointer (System.AccessViolationException)

旧巷老猫 提交于 2021-02-06 15:11:48
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

C++/CLI delegate as function pointer (System.AccessViolationException)

五迷三道 提交于 2021-02-06 15:11:27
问题 I have been experimenting with C++/CLI delegates (as I am trying to make a .NET reference library), and I have been having the following problem. I define a delegate in C++/CLI, and then create an instance of the delegate in C#, and then call the instance of the delegate through unmanaged C++ via a function pointer. This all works as expected. Code to illustrate this (first my C#) using System; namespace TestProgram { class Program { static void Main(string[] args) { Library.Test

P/Invoke or C++/CLI for wrapping a C library

风格不统一 提交于 2021-02-05 13:37:48
问题 Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the rest of the project. Are there any objective reasons to prefer P/Invoke or C++/CLI for the interoperability underneath that API, in terms of robustness, maintainability, deployment, ...? The issues I could think of that might be, but aren't problematic are: C++/CLI will require an separate assembly, the P/Invoke

C++ read/write to binary file. on program exit it gives System.AccessViolationException

江枫思渺然 提交于 2021-02-05 09:20:44
问题 This C++ program is created using Visual Studio 2010. It's a group project that has everyone in class stumped. The program initially starts fine and the user can run through the program and add items that are written out to file. the items are read back in and displayed. When the user is done, on the program exiting return 0; it gives me "An unhandled exception of type System.AccessViolationException occurred. Attempted to read or write protected memory. This is often an indication that other

String conversion from System::String ^ to const wchar_t *

人走茶凉 提交于 2021-02-04 08:12:22
问题 I'm trying to open a file using a string parameter, however I'm getting the following error: error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const wchar_t *' How do you convert System::String ^ to const wchar_t * ? 回答1: As Hans points out, simple conversion is necessary. It would look similar to the following: System::String ^str = L"Blah Blah"; pin_ptr<const wchar_t>

String conversion from System::String ^ to const wchar_t *

▼魔方 西西 提交于 2021-02-04 08:12:06
问题 I'm trying to open a file using a string parameter, however I'm getting the following error: error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const wchar_t *' How do you convert System::String ^ to const wchar_t * ? 回答1: As Hans points out, simple conversion is necessary. It would look similar to the following: System::String ^str = L"Blah Blah"; pin_ptr<const wchar_t>

How Do I Read Raw Input in C++/CLI

旧街凉风 提交于 2021-01-29 16:52:11
问题 Here's my problem. I am trying to get raw input from attached devices. I am using the information on MSDN to figure it out, but it's been very difficult for me to make sense of some of it. I believe I have successfully created a RAWINPUTDEVICE object and registered a device with RegisterRawInputDevices(). Now I am trying to figure out how to use the GetRawInputDeviceList() and GetRawInputDeviceInfo() functions. The big trouble is trying to understand the parameters they take, which includes a

How to handle exceptions from native code?

放肆的年华 提交于 2021-01-28 21:47:05
问题 Suppose that my application is composed of 3 components. They are: c++ native library c++ cli managed library, which wraps native library c# gui application. As I understand, any native exception, thrown from a native c++ library will be wrapped with SEHException managed class. I am interested in the next steps, what is recommended to do after the creation of such an exception object. Should I catch all such possible exceptions within the c++ cli managed library then create an appropriate