c++-cli

Access Violation Exception/Crash from C++ callback to C# function

醉酒当歌 提交于 2019-12-01 04:44:40
So I have a native 3rd party C++ code base I am working with (.lib and .hpp files) that I used to build a wrapper in C++/CLI for eventual use in C#. I've run into a particular problem when switching from Debug to Release mode, in that I get an Access Violation Exception when a callback's code returns. The code from the original hpp files for callback function format: typedef int (*CallbackFunction) (void *inst, const void *data); Code from the C++/CLI Wrapper for callback function format: (I'll explain why I declared two in a moment) public delegate int ManagedCallbackFunction (IntPtr oInst,

C++/CLI: Use LoadLibrary + GetProcAddress with an exe

家住魔仙堡 提交于 2019-12-01 04:24:40
问题 Up until now, I had some sort of plugin mechanism in which I loaded dlls using LoadLibrary and GetProcAddress to create a concrete object and return a common interface. This worked fine until I decided that one of the dlls should be an exe. LoadLibrary's documentation says that it can be used for exe's as well, so I gave it a shot. The exe gets loaded without errors, as GetProcAddress. But when I try to call my concrete object's constructor, I get an access violation. I thought this would

Getting error C3352 (specified function doesn't match delegate type), even though function seems to match delegate type

心不动则不痛 提交于 2019-12-01 04:21:10
Here is the exact error message on compilation: error C3352: 'double MyNamespace::MyRefClass::MyFunction(const std::vector<_Ty> &,std::vector<_Ty> &,void *)' : the specified function does not match the delegate type 'double (const std::vector<_Ty> &,std::vector<_Ty> &,void *)' MyFunction is a private function in the reference class MyRefClass The quoted error shows up when I try to create an instance of the private delegate MyDelegate , declared in the same reference class, with the code: MyDelegate^ del = gcnew MyDelegate(&MyRefClass::MyFunction); As far as I can tell, the signatures of the

C++/CLI: Catching all (.NET/Win32/CRT) exceptions

不打扰是莪最后的温柔 提交于 2019-12-01 04:19:05
I know this is frowned upon, but I'm out of options here. I'm developing a C++/CLI app that has a bug that I'm unable to track down - mainly because it's bypassing my current crash handler: AppDomain::CurrentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(&LogAndExit); Application::ThreadException += gcnew ThreadExceptionEventHandler(&LogAndExit); Application::SetUnhandledExceptionMode(UnhandledExceptionMode::CatchException); try { Application::Run(gcnew frmMain()); } catch (Exception^ ex) { LogAndExit(ex); } catch (...) { LogAndExit(); } Standard .NET crash handling, I

Remote debugging an app with the DEBUG versions of the CRT when VS is not installed on the remote machine

人盡茶涼 提交于 2019-12-01 04:06:42
问题 First let me say that I can remote debug a release build on the remote computer. I set up my release build much like my debug build but I mostly had to make sure the Debug flag was not set. I've dealt with doing this for a while and finally decided to try and figure out why I had to go through this. I should also mention that my remote debugging experience is limited to this project and the C# program uses a C++/CLI (built with /clr) .DLL to mediate to some critical C++ libs. I don't need to

Why does printf work with managed Strings?

左心房为你撑大大i 提交于 2019-12-01 03:44:57
问题 we are currently digging through some really old C++/CLI-Code (Old Syntax .NET Beta) and were a bit surprised to see something like this: System::String ^source("Test-String"); printf("%s", source); The program correctly outputs Test-String We are wondering, why is it possible to pass the managed string source to printf - and more importantly: Why does it work ? I don't expect it to be some convenience-feature by the compiler because the following doesn't work: System::String ^source("Test

What is CLI/C++ exactly? How does it differ from 'normal' c++?

我的未来我决定 提交于 2019-12-01 03:16:32
Let me clarify what I mean by 'normal' C++ first- I'm currently reading Walter Savitch's "Problem Solving in C++". As far as I am aware this is not written specifically for Microsoft or Unix. So my question is, how does what I am learning in this book (which I am using for my universal knowledge-gaining of c++) differ from what I keep reading about CLI C++? Is CLI C++ just what I would encounter if I used Visual C++? I'm totally confused. C++/CLI, (Also sometimes C++/CLR) refers to a language which is positioned somewhere in between native C++, and the .NET framework. It's usually used for

How to add shared C# NuGet dependencies to a C++/Cli project?

梦想的初衷 提交于 2019-12-01 03:00:25
Context: A Visual Studio solution with 2 assemblies, Cs and Cpp. Cs is a C# / .net45 dll Cpp is a C++/Cli dll, a C++ dll compiled with /clr. I have some dependencies that are pure C# projects from nuget.org. I use the original packages provided by the authors. Adding them to the Cs project works fine, but not to Cpp. How can I add the C# package to the C++ project? Since it's C++/Cli, I can easily use .net objects, and I use e.g. in the C++ library stuff from the C# library. But somehow nuget only allows me to select C# projects to add a C# dependency to, not C++ /clr ones. In your C++/CLI

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

吃可爱长大的小学妹 提交于 2019-12-01 02:30:24
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 the version for a C++/CLI Project? Update I will add the content of my AssemblyInfo.cpp. I just filled

How do I detect the user's locale to get the correct csv separator?

血红的双手。 提交于 2019-12-01 02:00:50
问题 I have a simple data conversion tool and one of the outputs it can produce is a csv file. This works perfectly here in the UK but when I shipped it out to a German customer I had some issues. Specifally, they use a ' , ' to represent the decimal point in a floating point number and vice versa. This means that when they open their data file in excel, the result is rather messy to say the least :-) Substituting the correct character is trivial, but how can I detect whether or not to apply this?