c++-cli

c++/cli c# winforms cross-thread operation sometimes possible

不打扰是莪最后的温柔 提交于 2019-12-11 17:46:37
问题 I am using c++/cli (should also apply to c#) and creating a winforms program. I have some lines of code that edit data in a DataGridView. The code is executed by an FileSystemWatcher event, but it could be executed by a background worker or a simple thread. However, it is NOT executed by the UI thread. The DGV is placed on a tab of a TabControl. When the code is executed while the DGV-containing tab has the focus, the code fails with the well-known and expected exception " Cross-thread

C++ .NET - how to dispose a bitmap?

老子叫甜甜 提交于 2019-12-11 16:26:25
问题 I want to load a bitmap from file, perform some operations on it, and save it back under the same file name. The pattern is this: Bitmap in = gcnew Bitmap(fileName); Bitmap out = gcnew Bitmap(in.Width, in.Height, in.PixelFormat); fill [out] with data from [in] out.Save(fileName); but this doesn't work. That's obvious. I cannot save to a file which is still opened (because of bitmap in). The question is: how the heck do I close bitmap in?! I've tried many ways but nothing works. Calling

How to create a global handle in C++-CLI

懵懂的女人 提交于 2019-12-11 14:58:25
问题 I am trying to use a C# class in a C++-CLI project, but Visual Studio will only let me declare a handle (^) to a C# object in a local scope, just inside a function. The only way I got it working was declaring a global pointer to a handle: SUTAdapter::Form1^ *ptForm1; But if then I create an object inside a function and give its address to the global pointer: SUTAdapter::Form1^ form1; form1 = gcnew SUTAdapter::Form1(); ptForm1 = &form1; (*ptForm1)->incCounter(0); When the function exits and I

Stackoverflow on calling native c++ from c#

こ雲淡風輕ζ 提交于 2019-12-11 14:57:14
问题 I am trying to call native C++ code from C# project. To do that I followed the steps from this post. But I get a stackoverflow exception when I create a huge array in the C++ file. Here is the code: //CSharpTest.h using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpTest { class Program { static void Main(string[] args) { CpTest.Class1 instance = new CpTest.Class1(); Console.WriteLine(instance.DoSomething());

SafeArrayPutElement method throws System.AccessViolationException

吃可爱长大的小学妹 提交于 2019-12-11 14:22:10
问题 I am trying to pass an array of ints from C# to C++/CLI. Here's my code: // SafeArrayTesting_PlusPlus.cpp #include "stdafx.h" #include <comdef.h> using namespace System; namespace SafeArrayTesting_PlusPlus { public ref class MyCppClass { public: MyCppClass(); ~MyCppClass(); void SetMyInts(array<int>^ myInts); }; MyCppClass::MyCppClass(){} MyCppClass::~MyCppClass(){} void MyCppClass::SetMyInts(array<int>^ myInts) { // Create safearray SAFEARRAY *safeArrayPointer; SAFEARRAYBOUND arrayDim[1]; //

Customize msiexec progress bar?

℡╲_俬逩灬. 提交于 2019-12-11 13:26:32
问题 My application call msiexec to run uninstall. logger->LogDebug("Actions: MsiUninstallExec()!"); System::Diagnostics::Process ^p = gcnew System::Diagnostics::Process(); p->StartInfo->FileName = "msiexec"; p->StartInfo->Arguments = "/x " + AppSetting::ProductCode; p->Start(); /// -->>> Uninstall /// -->> Choose restart or not. /// -->>> Application Exit When uninstallation is done, users have to choose restart or not to complete this process. But my customer request : "The progress bar of

cannot convert parameter 2 from 'mxArray **' to 'mwArray &'

*爱你&永不变心* 提交于 2019-12-11 13:10:33
问题 I want to create a C++ Shared library from Matlab using deloytool and use it in MVS. I compile a function name 'foo.m', as the result I got list of files (.h,.cpp,.lib,...) and I found the function in 'fooCpplib.h' is as follow: extern LIB_fooCpplib_CPP_API void MW_CALL_CONV foo(int nargout, mwArray& y, const mwArray& x); Then I create a MVS project (2010), window form application, with 2 textbox and 2 click button, one textbox named inBox, and another named outBox. The code inside button

How to make Stack.Pop threadsafe

一笑奈何 提交于 2019-12-11 12:21:08
问题 I am using the BlockingQueue code posted in this question, but realized I needed to use a Stack instead of a Queue given how my program runs. I converted it to use a Stack and renamed the class as needed. For performance I removed locking in Push, since my producer code is single threaded. My problem is how can thread working on the (now) thread safe Stack know when it is empty. Even if I add another thread safe wrapper around Count that locks on the underlying collection like Push and Pop do

0xC0000005: Access violation reading location 0xffffffffffffffff

让人想犯罪 __ 提交于 2019-12-11 11:54:31
问题 I have: An unmanaged C++ app A C++/CLI Wrapper A C# GUI I am seeing this crash occur only in Release and not debug. The crash also does not occur on neither debug or release when the unmanaged C++ app is run by itself. All I can say is the crash occurs in this line of code: if ((std::find(vstrEEDRRMachines.begin(), vstrEEDRRMachines.end(), m_sFrame.strSourceAddress) != vstrEEDRRMachines.end() && std::find(vstrEEDRRMachines.begin(), vstrEEDRRMachines.end(), m_sFrame.strDestAddress) !=

Unable to use Custom .dll (C#) from C++/CLI

限于喜欢 提交于 2019-12-11 11:47:44
问题 Thanks In advance for you time and Help. Goal : I am trying to use my C# library within a C++ project What I did : Created a simple .dll file with my C# project. named: ClassLibrary1.dll Created a C++ console application named: CppClr (Common Language RunTime Support Changed to: /clr) Copied ClassLibrary1.dll to the root off CppClr project Following is my ClassLibrary1(C#) code: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ClassLibrary1 {