c++-cli

Difference between array<T> and array<T^> where T is ValueType

眉间皱痕 提交于 2019-12-20 05:15:58
问题 I'm writing a C++/CLI wrapper over native lib for my C# project. I'm trying to convert std::vector<unsigned char> in native c++ to System.Byte[] in C#. In C++/CLI both variants are valid auto arr = gcnew array<System::Byte>(10); auto arr = gcnew array<System::Byte^>(10); But in first case in C# code we got System::Byte[] type whereas in second case we got System::ValueType[]. So my question is why we got such strange behavior? 回答1: The ^ hat should only be used on reference types. Byte is a

C++/CLI DLL namespace not found in MSVS

假装没事ソ 提交于 2019-12-20 04:36:06
问题 The big picture: what I am trying to accomplish is writing code in both C# and C++, to strike a good performance/productivity balance. It is not for code reuse reasons; I just want to be able to write new code in native C++ when it suits me, without committing to all its horrors. I have a solution with 4 projects: GUI: C# WPF interface Logic_Cs: C# DLL, high level reference implementation of game logic Logic_CLI: CLI DLL, interface between managed and unmanaged code Logic_Cpp: C++ lib with

Using Visual C++ for C++ instead of C++/CLI

こ雲淡風輕ζ 提交于 2019-12-20 04:34:19
问题 I know how to program in C++ making console programs, but now I want to code programs with interfaces for Windows. MS VS 2010 makes things easy when coding C++ Windows applications with its drag & drop design system. (.net Framework) However, Visual Studio seems to use C++/CLI, which I'm unfamiliar with. Is there for an IDE which only uses C++? Is there any good IDE with an easy to use GUI designer, or can I tweak VS 2010 to not to use C++/CLI? 回答1: Visual C++ is perfectly happy to not use C+

Mixed mode C++/CLI performance considerations - best practices

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:10:22
问题 I have a C++/CLI library that calls many native C++ methods. I have read many threads stating that you should not mix managed and unmanaged code. I couldnt find any that says how to avoid those switches and why it will cause a performance issue. Can someone share best practices. 回答1: The only reason to use C++/CLI is for its support of mixing managed and native code. If everything is managed then use C# or VB, if everything is native then use C or C++. Or whatever language you prefer. Clearly

Memcpy of native array to managed array in C++ CLI

自古美人都是妖i 提交于 2019-12-19 16:35:07
问题 Am I doing this right? I get a pointer to a native array and need to copy to a managed array. Use memcpy() with a pin_ptr. unsigned char* pArray; unsigned int arrayCount; // get pArray & arrayCount (from a COM method) ManagedClass->ByteArray = gcnew array<Byte,1>(arrayCount) pin_ptr<System::Byte> pinPtrArray = &ManagedClass->ByteArray[0]; memcpy_s(pinPtrArray, arrayCount, pArray, arrayCount); arrayCount is the actual length of pArray, so not really worried about that aspect. Looked at the

Preventing a RichTextBox operation from being added to the control's Undo stack

戏子无情 提交于 2019-12-19 12:04:04
问题 Editing a RichTextBox control's text (more specifically, modifying selection font/color) programmatically seems to be tracked in the control's built in undo stack. Is there a way, short of writing my own undo/redo "manager", to prevent certain actions/operations from being added to the undo stack ? 回答1: No cando. At best you can flush the undo stack completely by sending EM_SETUNDOLIMIT twice. EM_SETTEXTEX offers the same option with the ST_DEFAULT flag. Surely not what you want. Look at

how to unload managed c++ dll?

柔情痞子 提交于 2019-12-19 11:19:23
问题 A.dll is a native c++ dll, B.dll is a managed c++ dll. A.dll depends on B.dll, so when load A.dll, B.dll is loaded automatically, but after A.dll is unloaded, B.dll is still loaded. Only A.dll depends on B.dll, why B.dll can't be unloaded? How to unload the managed c++ dll? I'm using vs2010. Thanks 回答1: You cannot unload a managed assembly once it is loaded by the CLR. The only way is to kill the AppDomain. 来源: https://stackoverflow.com/questions/7697621/how-to-unload-managed-c-dll

What is the simplest way to display (and change) an image resource on a WPF dialog (using C++/CLI)?

早过忘川 提交于 2019-12-19 11:02:32
问题 I have a C++/CLI GUI application and I want to display an image as a visual aid for the user to see what step in a procedure they're at. This image will need to be changed each time the user selects the new step. Currently I'm using a picture box and have an image loaded from the disk at run time. So there are a few things I need to know here: Is a picture box the best thing to use for this purpose or is there another control that would better suit? How do embed the images in the executable

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

∥☆過路亽.° 提交于 2019-12-19 07:18:35
问题 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

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

佐手、 提交于 2019-12-19 06:29:09
问题 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