c++-cli

extern “C” char** environ - Windows - C++/CLI

丶灬走出姿态 提交于 2019-12-08 16:26:26
I have some old linux code I'm trying to port to Windows. When I first built it as a straight native DLL, I go no issues with this piece of code, but when I tried making it a mixed-mode C++/CLI DLL, I got an unresolved external object error on this: extern "C" char** environ; Why would this work for native and not CLI? Any idea how to work around this, or what it even does? That holds the environment variables (PATH, etc, etc). The C standard (if i recall correctly) requires environ to point to an array of these variables. They're also passed as the 3rd argument to the main entry point

Identifying problematic dependencies in C++/CLI project

流过昼夜 提交于 2019-12-08 15:50:19
问题 My application compiles fine, but I get the following runtime error: System.IO.FileNotFoundException was unhandled HResult=-2147024770 Message=Could not load file or assembly {Wrapper} or one of its dependencies. The specified module could not be found. The reference to Wrapper in the calling Application looks correct. The Wrapper dll exists in the correct location. This project used to build and run on someone else's system, I saw it demonstrated several times. That person/computer is no

Why don't protected C++-Cli destructors cause compilation errors?

匆匆过客 提交于 2019-12-08 15:40:27
问题 If I compile and run the following: using namespace System; ref class C1 { public: C1() { Console::WriteLine(L"Creating C1"); } protected: ~C1() { Console::WriteLine(L"Destroying C1"); } }; int main(array<System::String ^> ^args) { C1^ c1 = gcnew C1(); delete c1; return 0; } ...the code compiles without an error and runs giving me this: Creating C1 Destroying C1 Press any key to continue . . . If I do the same in C++ I get an error along the following lines: 1>ProtectedDestructor.cpp(45):

Is there a way to detect whether #pragma unmanaged is in effect in C++/CLI?

只愿长相守 提交于 2019-12-08 15:16:49
问题 I have a project that includes some performance sensitive native C++ headers making heavy use of templates. For this project we also wrap the headers and add some glue code to expose the functionality to c# and other .NET languages. We'll call this header "layout.h", and we'll assume it's a third party header that I can't change. In a mixed mode C++/CLI assembly it is relatively easy to make a mistake and #include from a place in the code where #pragma unmanaged (or #pramga managed(push,off)

array<Byte>^ TO unsigned char* :: Marshall class - Interop Issue

こ雲淡風輕ζ 提交于 2019-12-08 14:23:31
I wanted to convert array< Byte>^ to unsigned char*. I have tried to explain what i have done. I donot know how to proceed further. Please show me the right approach. I am using MS VC 2005. //Managed array array<Byte>^ vPublicKey = vX509->GetPublicKey(); //Unmanaged array unsigned char vUnmanagedPublicKey[MAX_PUBLIC_KEY_SIZE]; ZeroMemory(vUnmanagedPublicKey,MAX_PUBLIC_KEY_SIZE); //MANAGED ARRAY to UNMANAGED ARRAY // Initialize unmanged memory to hold the array. vPublicKeySize = Marshal::SizeOf(vPublicKey[0]) * vPublicKey->Length; IntPtr vPnt = Marshal::AllocHGlobal(vPublicKeySize); // Copy the

Changing co-ordinate system

若如初见. 提交于 2019-12-08 13:18:49
问题 I need to switch from the XY co-ordinate system shown above to the X'Y' co-ordinate system using System::Drawing::Drawing2D (i.e. GDI+). This is what I have in mind: float rotation = // +90 below is because AB is the new vertical... Math::Atan2(pB.Y - pA.Y, pB.X - pA.X) * 180.0 / Math::PI + 90.0f; Matrix m; m.Translate(pA.X, pA.Y); m.Rotate(rotation); m.Invert(); array<PointF> points = gcnew array<PointF>{ pC }; m.TransformPoints(points); Is there a way to do this while minimizing rounding

How to append text to file in a UWP app

僤鯓⒐⒋嵵緔 提交于 2019-12-08 11:25:51
问题 I need to create a simple log class (just a "save to file" method) in a UWP app for debugging purpose but AppendTextAsync is much different from ofstream and I don't know how to use. This is my class #pragma once ref class winRTLog sealed { public: winRTLog(); void save(Platform::String^ log); private: Platform::String^ myFilename = L"myLog.txt"; Windows::Storage::StorageFolder^ myFolder; Windows::Storage::StorageFile^ myFile; Windows::Foundation::IAsyncOperation<Windows::Storage::StorageFile

How do I create a custom Find method for a Generic::List<T> in C++/CLI?

旧城冷巷雨未停 提交于 2019-12-08 11:22:59
问题 I wanted to post an answer to this question because the MSDN Network Example only lists C# and VB and the answer is a bit different in C++/CLI. This answer is derived from this post: Using "->Find" on a "List" in Visual C++ 回答1: Following the guidance of the post link above... First I created a class to use as my Predicate delegate: public value class FindComponentView { String^ Value; public: FindComponentView(String^ value) { Value = value; } bool IsMatch(ComponentDrawingData^ compDD) {

Wrapping class with pure virtual methods

天涯浪子 提交于 2019-12-08 10:25:09
问题 I have an unmanaged dll which contains a class with pure virtual methods only (kind of callbacks): class PAClient { public: __declspec(dllexport) virtual void SetCalculationStarted() = 0; __declspec(dllexport) virtual void SetCalculationStopped() = 0; } Now I have to send these function calls to the managed C# code and decided to use interface for that. This is what I've done: public interface class IPAClientWrapper { void SetCalculationStarted(); void SetCalculationStopped(); }; private

Developing C++/CLI project for Windows 8 Tablet on Windows 7

≡放荡痞女 提交于 2019-12-08 10:15:47
问题 I have a code base of native C++. Recently I incorporated a Windows 8 tablet into the system that we deploy to. I have a .NET managed DLL that accesses the Tablet orientation sensor. This managed code is wrapped by an unmanaged class that I can access from the native C++. The problem is that I cannot run and debug the code on my Windows 7/VS2010 box without getting an Access Violation at the outset. No breakpoints are even hit before the exception. Is there a way to ignore the managed DLL