c++-cli

How to dispose of a NET COM interop object on Release()

别说谁变了你拦得住时间么 提交于 2019-11-29 01:37:20
问题 I have a COM object written in managed code (C++/CLI). I am using that object in standard C++. How do I force my COM object's destructor to be called immediately when the COM object is released? If that's not possible, call I have Release() call a MyDispose() method on my COM object? My code to declare the object (C++/CLI): [Guid("57ED5388-blahblah")] [InterfaceType(ComInterfaceType::InterfaceIsIDispatch)] [ComVisible(true)] public interface class IFoo { void Doit(); }; [Guid("417E5293

Wrapping C++ for use in C#

情到浓时终转凉″ 提交于 2019-11-28 23:52:26
Ok, basically there is a large C++ project (Recast) that I want to wrap so that I can use it in my C# project. I've been trying to do this for a while now, and this is what I have so far. I'm using C++/CLI to wrap the classes that I need so that I can use them in C#. However, there are a ton of structs and enums that I will also need in my C# project. So how do I wrap these? The basic method I'm using right now is adding dllexport calls to native c++ code, compiling to a dll/lib, adding this lib to my C++/CLI project and importing the c++ headers, then compiling the CLI project into a dll,

Incompatibility using managed array and std:array at same time

Deadly 提交于 2019-11-28 23:20:43
I have my C++/CLI code using arrays like this (for example): array<String^>^ GetColNames() { vector<string> vec = impl->getColNames(); array<String^>^ arr = gcnew array<String^>(vec.size()); for (int i = 0; i < vec.size(); i++) { arr[i] = strConvert(vec[i]); } return arr; } It's compiling fine until I add the library "array" to the project: #include <array> Then I don't know how to use the managed CLI array, because the compiler thinks that all the declared arrays are the std::array . Errors examples: array<String^>^ arr // ^ Error here: "too few arguments for class template "std::array""

C++/CLI : Casting from unmanaged enum to managed enum

二次信任 提交于 2019-11-28 22:19:48
问题 What is the correct way of casting (in C++/CLI) from a native code enum to a managed code enum which contain the same enum values? Is there any difference with using the C# way of casting like for example (int) in C++/CLI. 回答1: Assuming your native code is enum shape_type_e { stUNHANDLED = 0, //!< Unhandled shape data. stPOINT = 1 //!< Point data. ... }; and your managed code is public enum class ShapeType { Unhandled = 0, Point = 1, ... }; You can cast from the native to the managed using

AnyCPU/x86/x64 for C# application and it's C++/CLI dependency

岁酱吖の 提交于 2019-11-28 21:23:42
I'm Windows developer, I'm using Microsoft visual studio 2008 SP1. My developer machine is 64 bit. The software I'm currently working on is managed .exe written in C#. Unfortunately, I was unable to solve the whole problem solely in C#. That's why I also developed a small managed DLL in C++/CLI. Both projects are in the same solution. My C# .exe build target is "Any CPU". When my C++ DLL build target is "x86", the DLL is not loaded. As far as I understood when I googled, the reason is C++/CLI language, unlike other .NET languages, compiles to the native code, not managed code. I switched the C

C++/CLI Support in .Net Core

倖福魔咒の 提交于 2019-11-28 21:15:09
Our project structure is like, native.dll :- This contains pure native code written in c\c++. This native.dll exposes some functions using *def file. Wrapper Library(wrapper.dll compiled with .Net framework v4.0) :- In order to use functionality of native.dll , a Wrapper lib(wrapper.dll) is written in C++\CLI using :clr\oldsyntax . This wrapper has all code of Interoperability and Marshalling . Application(Console App v4.0) directly uses wrapper.dll to use functionality provided by native.dll . Now this project needs to run in .Net Core . This means we will have an .Net Core application that

How to initialize and print a std::wstring?

匆匆过客 提交于 2019-11-28 20:02:31
I had the code: std::string st = "SomeText"; ... std::cout << st; and that worked fine. But now my team wants to move to wstring . So I tried: std::wstring st = "SomeText"; ... std::cout << st; but this gave me a compilation error: Error 1 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'const char [8]' to 'const std::basic_string<_Elem,_Traits,_Ax> &' D:...\TestModule1.cpp 28 1 TestModule1 After searching the web I read that I should define it as: std::wstring st = L"SomeText"; // Notice the "L"

Does the ^ symbol replace C#'s “ref” in parameter passing in C++/CLI code?

隐身守侯 提交于 2019-11-28 18:48:37
In C#, passing by reference is: void MyFunction(ref Dog dog) But in C++/CLI code examples I have seen so far, there is no use of ref but instead ^ symbol is used: void MyFunction(Dog ^ dog) Is the use of ^ symbol a direct replacement for ref when parameter passing? or does it have some other meaning I'm not aware of? Additional Question: I also see a lot of: Dog ^ myDog = gcnew Dog(); It looks like it's used like * (pointer) in C++.. Does it work similarly? Thanks! If Dog is a reference type ( class in C#) then the C++/CLI equivalent is: void MyFunction(Dog^% dog) If Dog is a value type (

Documenting C++/CLI library code for use from c# - best tools and practices? [closed]

ε祈祈猫儿з 提交于 2019-11-28 18:26:59
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I'm working on a project where a c++/cli library is being used primarily from a c# application. Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio? Assuming there isn't, what would be the best way to document the c++/cli code

Managed C++ to form a bridge between c# and C++

回眸只為那壹抹淺笑 提交于 2019-11-28 18:02:10
I'm a bit rusty, actually really rusty with my C++. Haven't touched it since Freshman year of college so it's been a while. Anyway, I'm doing the reverse of what most people do. Calling C# code from C++. I've done some research online and it seems like I need to create some managed C++ to form a bridge. Use __declspec(dllexport) and then create a dll from that and use the whole thing as a wrapper. But my problem is - I'm really having a hard time finding examples. I found some basic stuff where someone wanted to use the C# version to String.ToUpper() but that was VERY basic and was only a