c++-cli

Can C++/CLI be used to call .NET code from native C++ applications? [closed]

折月煮酒 提交于 2019-11-28 05:34:01
I've done the other way around (calling pure C++ code from .NET) with C++/CLI, and it worked (for the most part). How is the native-to-C++/CLI direction done? I really don't want to use COM interop... You can always host the CLR in your native app. Daniel Earwicker If you have an existing native C++ app and want to avoid "polluting" it with too much CLR stuff, you can switch on the /clr flag for just one specific file and use a standard C++ header to provide an interface to it. I've done this in an old bit of code. In the header I have: void SaveIconAsPng(void *hIcon, const wchar_t

Calling C# from C++, Reverse P/Invoke, Mixed Mode DLLs and C++/CLI

岁酱吖の 提交于 2019-11-28 05:29:16
As I understand it I can use reverse P/Invoke to call C# from C++. Reverse P/Invoke is simply a case of: Create you managed (c#) class. Create a c++/cli (formerly managed c++) class library project. Use this to call the managed c# class (presumably via a reference). Call the c++/cli code from native c++. Questions: Is this correct? Is the DLL created at step 2 known as a mixed mode DLL? Has C++/CLI completely superseded Managed C++ as far as MS are concerned? Is COM completely avoided using this approach? At what point would the CLR be created and run, and by whom? Thanks in advance Aamir Here

Pass Managed Function Pointer As Unmanaged Callback

微笑、不失礼 提交于 2019-11-28 04:55:08
问题 I am attempting to pass a managed function pointer void (*)(void *) to my unmanaged library. My unmanaged library calls this callback with a pointer to a frame of data protected by a CriticalSection. While the managed callback is running, nothing else can modify the frame of data due to the Critical Section. However, I am getting Access Violations and Heap Corruptions just by entering the callback. EDIT : I forgot to mention. The StartStreaming() steals the thread it manages. Furthermore, it

What are people replacing the missing C++/CLI Intellisense in VS 2010 with?

扶醉桌前 提交于 2019-11-28 04:30:31
问题 I'm about to start a project where I will be likely to use a lot of C++/CLI. I really miss C++/CLI Intellisense in VS 2010. I've heard of some Resharper-like products for C++, but wonder if they provide complete Intellisense. Do they also work with C++/CLI? What are people doing to overcome this limitation? 回答1: Visual Assist X, a commercial addin for Visual Studio developed by Whole Tomato Software 回答2: Yes, Visual Assist X does support C++/CLI because we make heavy use of it. Its a good

How to pass and execute anonymous function as parameter in C++11?

天涯浪子 提交于 2019-11-28 03:41:09
The code I'm looking for is like following. bool Func1(int Arg1, C++11LambdaFunc Arg2){ if(Arg1 > 0){ return Arg2(Arg1); } } Later I'll be using this code. Func1(12, [](int D) -> bool { ... } ); Basic version, for use in a header file: template<typename Lambda> bool Func1(int Arg1, Lambda Arg2){ // or Lambda&&, which is usually better if(Arg1 > 0){ return Arg2(Arg1); } else { return false; // remember, all control paths must return a value } } More complex version, if you want to split your interface from your implementation (it has run time costs): bool Func1(int Arg1, std::function<bool(int)

What is the C++/CLI equivalent to C#'s default(T)?

∥☆過路亽.° 提交于 2019-11-28 02:42:40
问题 I'm working with some C++/CLI code (new syntax) and am trying to declare a generic type and want to set a member variable to it's default. In C#: class Class<T> { T member = default(T); } What's the equivalent in CLI? generic<typename T> public ref class Class { public: Class() : member(default(T)) // <-- no worky { } private: T member; }; 回答1: Interestingly enough the syntax makes it looks like this: T() . It does require the addition of a copy constructor. generic<typename T> public ref

Convert a String^ to wstring C++

别说谁变了你拦得住时间么 提交于 2019-11-28 02:00:55
问题 I programmed a little Application in C++. There is a ListBox in the UI. And I want to use the selected Item of ListBox for an Algorithm where I can use only wstrings. All in all I have two questions: -how can I convert my String^ curItem = listBox2->SelectedItem->ToString(); to a wstring test? -What means the ^ in the code? Thanks a lot! 回答1: It should be as simple as: std::wstring result = msclr::interop::marshal_as<std::wstring>(curItem); You'll also need header files to make that work:

How do i convert const wchar_t* to System::String?

不问归期 提交于 2019-11-28 01:35:17
问题 I need to convert my SHA1 (wchar_t*) to a normal String^ in order to use it in a certain function. Any ideas? I tried Google but all the results were the exact opposite of my question. :\ NOTE: I am using C++.NET framework and Windows Forms Applications 回答1: Use the constructor; like this: const wchar_t* const pStr1 = ...; System::String^ const str1 = gcnew System::String(pStr1); const char* const pStr2 = ...; System::String^ const str2 = gcnew System::String(pStr2); If you're using the

regasm RA0000: No types were registered

久未见 提交于 2019-11-28 01:20:34
I have a C++/CLI assembly (compiled for .NET 3.5 that comes with Windows 7). The assembly is marked as ComVisible(true) . It contains 2 classes and 1 interface. Both classes are marked as ComVisible(false) so they shouldn't matter. The interface is marked with InterfaceType(ComInterfaceType::InterfaceIsIUnknown) and a specific GUID. This interface needs to be registered. When I try to register this assembly using RegAsm.exe AssemplyName , I get this warning: RegAsm : warning RA0000 : No types were registered My assembly depends on 3 other assemblies which are in the same directory as my main

Is there any advantage to using C++/CLI over either standard C++ or C#?

烈酒焚心 提交于 2019-11-28 01:17:29
I'm not seeing any real advantages, other than the fact that you have a C++ syntax, and with it, things like pointers and destructors. If you're talking about why you would use C++/CLI over C#, I think the main reasons are that: it might be more natural for C++ developers (though I think this is probably not true) C++/CLI has very nice capabilities for bridging the native and managed environments (using the 'IJW' - It Just Works - technology) I think that Herb Sutter probably gives the best overview: A Design Rationale for C++/CLI If you want to know why you might want to use native C++ over C