c++-cli

Link error linking from managed to unmanaged C++ despite linking to .lib file with exported symbols

你离开我真会死。 提交于 2019-12-02 04:11:47
Despite following various posts on using and linking to unmanaged C++ code from a C++/CLI wrapper dll, I cannot resolve these link issues. 1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000A) "public: __thiscall MyClass::~MyClass(void)" (??1MyClass@@$$FQAE@XZ) referenced in function "public: void * __thiscall MyClass::`scalar deleting destructor'(unsigned int)" (??_GMyClass@@$$FQAEPAXI@Z) 1>MyClassAdapter.obj : error LNK2028: unresolved token (0A00000B) "public: __thiscall MyClass::MyClass(void)" (??0MyClass@@$$FQAE@XZ) referenced in function "public: __clrcall WrapperLayer:

Difference between array<T> and array<T^> where T is ValueType

家住魔仙堡 提交于 2019-12-02 03:57:27
I'm writing a C++/CLI wrapper over native lib for my C# project. I'm trying to convert std::vector<unsigned char> in native c++ to System.Byte[] in C#. In C++/CLI both variants are valid auto arr = gcnew array<System::Byte>(10); auto arr = gcnew array<System::Byte^>(10); But in first case in C# code we got System::Byte[] type whereas in second case we got System::ValueType[]. So my question is why we got such strange behavior? The ^ hat should only be used on reference types. Byte is a value type so array<System::Byte> is the proper declaration. Unfortunately C++/CLI also permits an array of

Adding #pragma make_public(Type) not removing C3767 error

依然范特西╮ 提交于 2019-12-02 03:11:53
I have an Assembly(A) which defines a Managed class which has a public constructor that takes two native types. I have access to the Header files and compiled lib files which contain the native types. I created a C++/CLI project and defined a ref class which contains a single public: static method that returns a public type defined in (A). When I try to contstruct by passing in a native type I receive the `C3767 'YourType::TypeB': Candidate function(s) not accessible. I've added #pragma make_public(Type) for the native types and any type they derive from but still not joy. My class header:

Error in C++/CLI, Can't take address of function unless creating delegate instance using Pthread

依然范特西╮ 提交于 2019-12-02 03:05:42
I'm using C++/CLI on Visual C++ 2008 Professional, and since I'm using Windows Forms that means I have managed code and I'm trying to call the static function LoginAccounts, but I get an error probably because I'm mixing Managed with Unmanaged Code, but I can't figure out what to do though. I'm using PThread for Windows System::Void testing_Click(System::Object^ sender, System::EventArgs^ e) { pthread_create(&t, NULL, &Contas::LoginAccounts, this); //Error in this line } Error 13 error C3374: can't take address of 'Tester::Test::LoginAccounts' unless creating delegate instance what do I do to

Cast native pointer to a C++\\CLI managed object reference?

谁都会走 提交于 2019-12-02 02:26:07
I have a callback that is called through a delegate. Inside it I will need to treat the buffer data that arrive from a record procedure. Normally in a unmanaged context I could do a reinterpret_cast on dwParam1 to get the object reference. But in a manged context how can I cast a DWORD_PTR to a managed object ref? static void WaveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { ControlLib::SoundDevice^ soudDevice = ?cast_native2managed?(dwParam1); Here ya go, more or less what gcroot (per my comment above) does: using namespace System; using

How do you convert a 'System::String ^' to 'TCHAR'?

China☆狼群 提交于 2019-12-02 02:09:56
i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] = Company::Pins::Bank::Decryption::Decrypt::Decryption("123456"); i've googled how to solve this problem, but i am not sure why the String has a carrot(^) on it. Would it be best to change the return from String to something else that C++ would accept? or would i need to do a convert before assigning the value? That is a really rambling way to ask the question, but if

Primitive types pass template parameter between c++ and CLI

瘦欲@ 提交于 2019-12-02 01:23:40
I have a c++ templated class: template<class T> class A { void test (T temp) { } }; But i need to wrap it in CLI so it can be used in c#. Example: CLI: template<class T> ref class AWrap { private: A* a; public: void test (T temp) { a->test<T>(temp); } }; C#: Awrap blah = new AWrap(); blah<int>(3); If I make a CLI templated ref class , which call the templated c++ method, will the primitive types generate the right c++ templated code on compilation ?-> What you are using in C# are generics, not templates. There is no way of specializing a C++/CLI template from C#. 来源: https://stackoverflow.com

Wrapping managed code for unmanaged use

时光总嘲笑我的痴心妄想 提交于 2019-12-01 23:42:58
问题 We have a big C++ project that's compiled as native unmanaged code. We need to use a feature from managed code, but we don't want to compile the whole project in /clr. So I made a DLL, have a ref class named B, which is exposed in exported native class A. Problem is I get a C1190: managed targeted code requires a '/clr' option because of the vcclr.h include. I'd like to know if there is a way to create some kind of interface that will have managed code within unmanaged methods. Here's my code

Does Visual Studio 2008 support configuration (debug/release build) specific references?

柔情痞子 提交于 2019-12-01 22:45:50
问题 I've got a native C++ project with one C++/CLI file (the only file compiled with /CLI), I'd like to add a reference to a C# DLL. There are separate versions for debug and release however I can only seem to add one reference which is applied to all configurations. The reference search path dialog box contains a warning that if I attempt to use any $ConfigurationName type parameters they will only ever refer to the first configuration in the project. So my current ideas are: Join the two

Does Visual Studio 2008 support configuration (debug/release build) specific references?

十年热恋 提交于 2019-12-01 20:34:14
I've got a native C++ project with one C++/CLI file (the only file compiled with /CLI), I'd like to add a reference to a C# DLL. There are separate versions for debug and release however I can only seem to add one reference which is applied to all configurations. The reference search path dialog box contains a warning that if I attempt to use any $ConfigurationName type parameters they will only ever refer to the first configuration in the project. So my current ideas are: Join the two projects together under one solution and adding a reference to the "project" rather then the DLL assembly. My