c++-cli

How to pass C# method as a callback to CLI/C++ function?

别说谁变了你拦得住时间么 提交于 2019-12-10 18:15:24
问题 I have such method in C++/CLI: void Foo(OnEngineCloseCallback callback); with such callback definition: typedef void (*OnEngineCloseCallback)( int, String ^ errorMessage); The C++/CLI compiles. The C# code looks like this: static void onCallback( int code, String errorMessage) { System.Diagnostics.Debug.WriteLine(errorMessage); } and the call: Foo(onCallback); // error "Foo is not supported by the language" (error: CS0570). So how can I pass my callback to CLI/C++? 回答1: If neither of you is

How do I use MethodInvoker in C++?

眉间皱痕 提交于 2019-12-10 18:14:48
问题 I've got a C++/CLI application which has a background thread. Every so often I'd like it to post it's results to the main GUI. I've read elsewhere on SO that MethodInvoker could work for this, but I'm struggling to convert the syntax from C# to C++: void UpdateProcessorTemperatures(array<float>^ temperatures) { MethodInvoker^ action = delegate { const int numOfTemps = temperatures->Length; if( numOfTemps > 0 ) { m_txtProcessor2Temperature->Text = temperatures[0]; } else { m

Dynamic C# object used in C++/CLI

﹥>﹥吖頭↗ 提交于 2019-12-10 18:03:33
问题 I'm currently building a c++/cli interop library. The library will be consumed by c# and vb.net applications, and I would like to make use of .Net 4 dynamic typing. I have a configuration module that uses dynamic member access to refer to configuration keys, this works fine in c# but is giving me trouble in c++/cli (not entirely unexpected) Is there any way to use this library in C++/CLI (e.g. by invoking TryGetMember() directly or something)? If the C++/CLI library then passes the dynamic

C++ virtual (sealed) function

自作多情 提交于 2019-12-10 17:36:35
问题 I am using classes from a dll in my C++ project. All is working fine, until... When trying to call a certain method (listed in the object browser), I am getting an error that this method is not a member of the namespace. Upon investigation, I noticed that this method is listed as "virtual void x() sealed". Is there a way to make a call to such a function? 回答1: For future reference, I just received a response from the enterprise library support team. They posted a link to the following:

C++ CLI DLL not being loaded by IIS7 but only if built with anything newer than VS2008

吃可爱长大的小学妹 提交于 2019-12-10 17:32:12
问题 For my development environment I'm using Windows 7 Ultimate x64, with VS2008, V2010 and VS2013, and my application is written in C#. The remote test server has Windows Web Server 2008 R2 x64 and IIS 7. Here is my specific issue: I have a native C++ library that I want to use in my C# applications, so I wrote a C++ CLI/CLR wrapper around it, and compiled it all into the same DLL. I've tried both compiling the C++ source into the DLL, and also statically linking the native library into the DLL,

C# - mixed assembly (C++/CLI, DirectX native) interplay (32/64bit)

允我心安 提交于 2019-12-10 17:26:00
问题 I have a problem related to this question. Two players: C# application Mixed assembly used by 1) The application has to support anything from Windows XP (32bit) to Windows 7 (32 & 64bit). The assembly is complicated in different ways. It contains managed C++/CLI code and some native C++ classes dancing with native DirectX. It also is linked to a few 32bit native dll's w/o source access (containing C++ classes with import libraries). Things are working well in 32bit environments (XP and 7

InterlockedIncrement64 with managed C++

巧了我就是萌 提交于 2019-12-10 15:36:35
问题 I'm porting code written under Visual Studio 2012 to compile with Visual Studio 2015. The code builds OK with Windows 2012. I have an issue with some code that calls InterlockedIncrement64 . It builds OK for an x64 target, but fails where the target is Win32 and the calling code is managed (i.e. compiled with /clr ), yielding: error C3861: 'InterlockedIncrement64': identifier not found Looking in winnt.h, it seems that InterlockedIncrement64 is undefined when the target is Win32 and _MANAGED

Calling a Visual Basic DLL in C++, Part 2

冷暖自知 提交于 2019-12-10 15:32:18
问题 This question is a follow up to a previous question (here). I have acquired a DLL that was created in Visual Basic from a third party vendor( Sensor DLL.dll ). This DLL contains functions for talking to a sensor, and I need to call these functions from a Visual C++ program I am writing. The vendor will not provide a header file, and I do not know Visual Basic. I have a small amount of documentation on each function. For example, I am told one function ( Get_Data ) in the DLL is of the form:

What does the ^ do? [duplicate]

半城伤御伤魂 提交于 2019-12-10 15:16:20
问题 This question already has answers here : What does the caret (‘^’) mean in C++/CLI? (7 answers) Closed 6 years ago . I'm new to C++ programming and am going through some examples that I found a while back. Since I am a decent Java programmer, I'm making good progress (at least from my perspective :D). Now I've come across something I cannot figure out what it does: Threading::Thread ^ th = Threading::Thread::CurrentThread; Net::IPEndPoint^ hostEp; What is the purpose of the ^ ? And is there a

What does the ^ character mean when used in C++ declarations? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-10 14:42:03
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What does the caret (‘^’) mean in C++/CLI? In C++/CLR, what does a hat character ^ do? What does the ^ character mean in C++ when applied to the data type in a variable declaration, as in: String^ input; or List<String^>^ phoneNumbers; 回答1: Assuming a Microsoft-compiler, this is not from C++ but from Microsoft own C++ dialects called C++/CLI . It denotes a .NET-garbage collected object. 回答2: It's a managed