c++-cli

How to explicitly/implicitly implemented interface members in C++/CLI?

佐手、 提交于 2020-01-04 09:08:02
问题 What's the equivalent in C++/CLI of this: class Explicit : IClonable { void IClonable.Clone() { } } class Implicit : IClonable { public void Clone() { } } 回答1: As nobugz says, you can't explicitly implement IDisposable. So, assuming that the title of your question is accurate, and you want to have explicit implementation of interface members (or explicit overrides which are supported in C++/CLI but I don't think are possible in C#, C++/CLI also provides more flexibility to override multiple v

C++/CLI pin_ptr

☆樱花仙子☆ 提交于 2020-01-03 21:09:13
问题 Is C++/CLI's pin_ptr the equivalent of C#'s fixed statement? 回答1: Yes, pretty much. Some differences: A fixed statement creates its own scope block. pin_ptr 's scope is from its initialization to the end of the enclosing block. fixed is an explicit language feature. pin_ptr is a use of a general language feature (C++ templates). (See comments.) There are probably more differences like the above. But, when translating between the two languages, they are generally equivalent. 来源: https:/

Mixed-mode C++/CLI crashing: heap corruption in atexit (static destructor registration)

纵饮孤独 提交于 2020-01-03 15:17:24
问题 I am working on deploying a program and the codebase is a mixture of C++/CLI and C#. The C++/CLI comes in all flavors: native, mixed ( /clr ), and safe ( /clr:safe ). In my development environment I create a DLL of all the C++/CLI code and reference that from the C# code (EXE). This method works flawlessly. For my releases that I want to release a single executable (simply stating that "why not just have a DLL and EXE separate?" is not acceptable). So far I have succeeded in compiling the EXE

C# and C++ class inheritance intermingling

可紊 提交于 2020-01-03 11:50:28
问题 I have an interesting stack of assemblies I want to put together: Common Assembly (C# or C++-CLI) public class MyBase { public void MethodA() { ... } private void MethodB() { ... } protected virtual MethodC() { ... } } Test Code Assemblies (all C++-CLI) public class MySpecific : public MyBase{ protected: override MethodC(); }; Test Simulator (C#) MySpecific obj = new MySpecific(); obj.MethodC(); While assembly 1 could be C++-CLI to keep things simpler, I'd really like to keep assembly 3 in C#

Prevent garbage collection for managed reference which is used in unmanaged code

三世轮回 提交于 2020-01-03 07:24:12
问题 My C# application uses wrapped C++ code for calculations. C++ header: __declspec(dllexport) void SetVolume(BYTE* data, unsigned int width); C++/CLI wrapper: void SetVolume(array<Byte>^ data, UInt32 width) { cli::pin_ptr<BYTE> pdata = &data[0]; pal->SetVolume(pdata, width); } C# : public startCalc() { byte[] voxelArr = File.ReadAllBytes("Filtered.rec"); palw.SetVolume(voxelArr, 490); //GC.KeepAlive(voxelArr); makes no sense } The C++ SetVolume function starts asynchronous calculations.

Why can't i see some C++ DLL ( support CLR ) in C# project ?

放肆的年华 提交于 2020-01-03 05:10:38
问题 I wrote simple C++ Dll ( win32 ) and i change the properties to be 'Common Language Runtime Support (/clr)' - I created new Simple winform project ( C# 4.0 ) and i created reference to the C++ project ( the C++ DLL ). Now i can't see the C++ dll in the C# project - i cant use it and i dont know why. 回答1: If you have, for example, this unmanaged function: bool fooFunction(int firstParameter, int secondParameter); If you want to make it visible to managed code you have to wrap (as first, simple

C++ Convert Sytem::String^ to LPCOLESTR

社会主义新天地 提交于 2020-01-03 04:53:08
问题 I write in mixed mode (C++/CLI) and I can not resolve this problem: String ^progID = "Matrikon.OPC.Server"; CLSID clsid; HRESULT result = CLSIDFromProgID(progID, &clsid); error C2664: 'CLSIDFromProgID' : cannot convert parameter 1 from 'System::String ^' to 'LPCOLESTR' How can I convert String^ to LPCOLESTR ? Thanks! 回答1: First, lets convert System::String to char* IntPtr p = Marshal::StringToHGlobalAnsi(progID); char *pNewCharStr = static_cast<char*>(p.ToPointer()); second, casting char * to

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

这一生的挚爱 提交于 2020-01-03 03:37:17
问题 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:

Can a managed ref-class directly implement a COM interface?

社会主义新天地 提交于 2020-01-03 02:54:17
问题 Is there a built-in way to allow a managed ref-class to implement and expose a COM inerface that is safely callable from native code? Looking at the C# side, this is easily done by decorating the target interface with the proper COM-interop attributes, for example: Native Interface interface ISampleGrabberCB: public IUnknown { virtual STDMETHODIMP SampleCB( double SampleTime, IMediaSample *pSample ) = 0; virtual STDMETHODIMP BufferCB( double SampleTime, BYTE *pBuffer, long BufferLen ) = 0; };

How do I make a vector/array of System::Windows::Forms::Checkbox^

人走茶凉 提交于 2020-01-03 02:41:06
问题 Couldn't find any answer to this problem, or not even any questions asked. So what I'm trying to do, is a std::vector, maybe just a normal array, of Checkboxes. std::vector< System::Windows::Forms::CheckBox^ >m_items; m_items.push_back( myCheckbox ); That's what I currently have, and it clearly ain't working. So does anyone have any ideas, on how to get it working, cause I've tried everything I can, but vectors don't seem to support Checkboxes. Incase you need the error code: c:\Program Files