c++-cli

“LNK2022: metadata operation failed” driving me insane

匆匆过客 提交于 2019-11-26 23:01:07
问题 I have a big solution with lots of projects, using VS2008 SP1, and at least once a day I encounter the LNK2022 error. If I do a full rebuild of the solution it builds fine, but this is not fun. It happens when a dependent DLL is changed 'insignificantly' (i.e. without changing any methods or classes), and the referencing project is later built. It fails when merging the metadata - whatever that means. First thing to note is that the shared DLL is referenced with #using from multiple .CPP

regasm RA0000: No types were registered

不羁岁月 提交于 2019-11-26 21:53:27
问题 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

C++/CLI wrapper for native C++ to use as reference in C#

泄露秘密 提交于 2019-11-26 21:22:57
Title explains. I have native C++ dlls that I'm writing C++/CLI wrappers for, which will in turn will be imported in C# as reference. The problem is that in C# I don't see the classes I have in wrapper (imported from DLL). What keywords should I use and HOW to re-declare my native C++ objects to become visible in C#? Ok, tutorial. You have a C++ class NativeClass that you want to expose to C#. class NativeClass { public: void Method(); }; 1) Create a C++/CLI project. Link to your C++ library and headers. 2) Create a wrapper class that exposes the methods you want. Example: #include

Implementing an interface declared in C# from C++/CLI

风流意气都作罢 提交于 2019-11-26 21:06:09
问题 Say I have a C# interface called IMyInterface defined as follows: // C# code public interface IMyInterface { void Foo(string value); string MyProperty { get; } } Assume I also have a C++/CLI class, MyConcreteClass , that implements this interface and whose header is declared as follows: // C++/CLI header file ref class MyConcreteClass : IMyInterface { public: }; How does one implement the method Foo and the property MyProperty in the C++/CLI header? My attempt results in the following compile

LNK2022 metadata operation: Inconsistent layout information in duplicated types

只愿长相守 提交于 2019-11-26 20:56:28
问题 I'm having a new-to-me linker error in a project I'm working with: 1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200004e). 1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std:

Convert from C++/CLI pointer to native C++ pointer

别等时光非礼了梦想. 提交于 2019-11-26 20:14:30
问题 I have run in to this problem of converting a C++/CLI pointer to a native C++ pointer. Heres the background: I'm writing a windows forms application using C++/CLI. The application makes call into a number of COM Interfaces. When creating an instance (inside of a C++/CLR class) of a object through the COM interface, i pass in (void**)(&provider) as the last argument to CoCreateInstance , as in: HRESULT CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, (void**)(&provider)); However, i get

How to initialize and print a std::wstring?

我与影子孤独终老i 提交于 2019-11-26 20:08:57
问题 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

Best workaround for compiler error C2158: make_public does not support native template types

﹥>﹥吖頭↗ 提交于 2019-11-26 18:34:24
问题 I have two c++/cli dlls (i.e. compiled with /clr) where A.dll references B.dll. In assembly B, I have a method, GetMgdClassB, I'd like to call from assembly A. Here is the code in assembly B (B.cpp): namespace B { public class NativeClassB { public: NativeClassB(); // ... }; public ref class MgdClassB { public: static MgdClassB ^ GetMgdClassB(const std::vector<NativeClassB *> & vecNativeBs) { // ... vecNativeBs; return gcnew MgdClassB(); } }; } Notice that the method GetMgdClassB takes a std:

How to call a C# library from Native C++ (using C++\\CLI and IJW)

喜你入骨 提交于 2019-11-26 18:27:56
Background: As part of a larger assignment I need to make a C# library accessible to unmanaged C++ and C code. In an attempt to answer this question myself I have been learning C++/CLI the past few days/ weeks. There seems to be a number of different ways to achieve using a C# dll from unmanaged C++ and C. Some of the answers in brief appear to be: using Interlope services, Using .com. and regasm, Using PInvoke (which appears to go from C# to C++ only), and using IJW in the C++/CLR (which appears to be Interlope services). I am thinking it would be best to set up a library that is perhaps a

Change C++/CLI project to another framework than 4.0 with vs2010

谁说胖子不能爱 提交于 2019-11-26 18:26:21
Since I upgraded my project to visual studio 2010 project format, my C++/CLI project is targeted to .net framework 4.0. It is easy to switch the framework version to another version from a C# project, but I have no clue how to do this in a C++/CLI project, I see no setting for this in the project property pages. This shows up when you press F1 in the Framework and References dialog: By default for new projects, the targeted framework is set to .NET Framework 4. The IDE does not support modifying the targeted framework, but you can change it manually. In the project file (.vcxproj), the default