c++-cli

C++/CLI forward declarations

吃可爱长大的小学妹 提交于 2019-12-11 03:16:00
问题 I have a header looking like this: namespace Dummy { ref class ISYSession {}; namespace Afw { /// <summary>Sammlung von AFW-Utility-Methoden</summary> public ref class AfwUtility { public: static void CopyAFWParamsToIDictionary(AFWParams &parameterIn, System::Collections::IDictionary^ parameterOut); static AFWParams* CopyIDictionaryToAFWParams(System::Collections::IDictionary^ dictionary); static void ShowExceptionLog(System::String^ sessionId); static void ShowStatementLog(System::String^

Functions and return const char*

帅比萌擦擦* 提交于 2019-12-11 03:15:38
问题 const char* test(bool i) { const char t[] = "aa\n"; const char* p = "bbb\n"; if(i) return p; return t; } int main(array<System::String ^> ^args) { printf(test(true)); printf(test(false)); return 0; } That returns something of sort: bbb %^&$^$% It is clear that test(false) returns a pointer to a local variable. The question is that p is also local variable. Why the memory for "bbb\n" is not cleaned after the function returns. I thought const char[] is interpreted same way as const char* but it

C++/CLI - Managed class to C# events

倾然丶 夕夏残阳落幕 提交于 2019-12-11 03:12:54
问题 I have a c++ class that triggers some method like an event. class Blah { virtual void Event(EventArgs e); } How can I wrap it so whenever the method is called a C# (managed) event will be called? I thought of inheriting that class and overloading the event method, and then somehow call the managed event. I'm just not sure how to actually do it. 回答1: Something like this (now compile-tested): #include <vcclr.h> struct blah_args { int x, y; }; struct blah { virtual void Event(const blah_args& e)

calling C++/CLI from C# with out parameter

十年热恋 提交于 2019-12-11 03:09:47
问题 Need some references to better understand the out parameter (and the '%' operator used) when interfacing C# with C++/CLI. Using VS2012 and this msdn reference:msdn ref C++ DLL code compiled with /clr #pragma once using namespace System; namespace MsdnSampleDLL { public ref class Class1 { public: void TestOutString([Runtime::InteropServices::Out] String^ %s) { s = "just a string"; } void TestOutByte([Runtime::InteropServices::Out] Byte^ %b) { b = (Byte)13; } }; } And the C# code: using System;

3ds Max .NET SDK and creating reference maker

瘦欲@ 提交于 2019-12-11 02:33:47
问题 I have .Net DLL for Max with ui, and I want to react to parameter changes of some nodes in the viewport. The easiest solution that came up to me, was to create ReferenceMaker plugin and set reference for node I want to watch. According to the documentation it should be public class ReferenceListener : Autodesk.Max.Plugins.ReferenceMaker{ ... } But when I create new instance of this class and try to set reference, it crashes on "Object reference not set to an instance of an object." When I try

Using OpenGL to draw directly to a .NET Bitmap

杀马特。学长 韩版系。学妹 提交于 2019-12-11 02:12:52
问题 I'd like to use OpenGL to draw directly to a .NET System::Drawing::Bitmap (C++/CLI). It seems like it should work like this: char buf[48]; ZeroMemory( &buf, sizeof(buf)); System::Drawing::Bitmap bmp( 4, 4, 12, Imaging::PixelFormat::Format24bppRgb, (System::IntPtr)buf); Graphics^ g = Graphics::FromImage(%bmp); HDC local_hdc = (HDC)((void*)g->GetHdc()); HGLRC local_hrc = wglCreateContext( local_hdc ); if(!wglMakeCurrent( local_hdc, local_hrc )) ShowError(); //Draw something with OpenGL ... g-

C++ no appropriate default constructor available

谁说胖子不能爱 提交于 2019-12-11 02:00:53
问题 I have some experience with C# but C++ syntax and program construction makes some problems. I am using Visual C++ 2008. Firstly why is there this error?: 1>......\Form1.h(104) : error C2512: 'Cargame::Car' : no appropriate default constructor available Secondly, why is not this line possible? //System::Drawing::Color color; error C3265: cannot declare a managed 'color' in an unmanaged 'Car' Form1.h contains: namespace Cargame { using namespaces bla bla bla class Car; public ref class Form1 :

C++/CLI: Boxing and Generic Lists

牧云@^-^@ 提交于 2019-12-11 01:53:03
问题 I am trying to create a generic list of references to PointF objects. (No, I am not looking to create a generic list of PointF objects.) However, the following line fails to compile: Generic::List<PointF^> ^pointList; // Generates error C3225 On the other hand, creating an array of PointF references works without a problem as follows: array<PointF^> ^points = gcnew array<PointF^>; Here is a sample program: using namespace System; using namespace System::Drawing; namespace Generic = System:

Using EventHandler in C++/CLI

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:49:43
问题 -I am trying to use event handler in c++/cli to throw event and then subscribe it in c# class Mclass { event System::EventHandler ^ someEvent; void ShowMessage(System::String ^) { someEvent(this,message); } } -but it throws error error C2664: 'managed::Mclass::someEvent::raise' : cannot convert parameter 2 from 'System::String ^' to 'System::EventArgs ^' How to rectify it 回答1: As winSharp93 points out, the signature for System::EventHandler takes a System::EventArgs . You can either: Create

Is there any class count limit in MFC project compiled with /CLR

孤者浪人 提交于 2019-12-11 01:34:57
问题 With the risk to fall into too specific question... Given a C++ MFC (mixed, not shaked) project compiled with /CLR, I have 200 classes already defined. When I add a new empty class to this project, an error raises when I compile and execute in debug mode. An unhandled exception of type 'System.IO.FileLoadException' occurred in Unknown Module. Additional information: Could not load file or assembly 'ProjectA, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.