c++-cli

Using unmanaged pointer to callback function on managed C++

元气小坏坏 提交于 2020-01-06 07:08:10
问题 I am writing C++/CLI a wrapper for some C++ libraries (static .lib, no source code available) controlling Digital I/O pins on an industrial computer. My objective is to handle the events of the DIO pins on an existing C# application using .NET CLR. The only viable option I could think of is to use a delegate in C++/CLI to fire events when the pin state changes (informed by the existing lib), and then handle these events in the C# part. I have tried the basic functionality using simpler mock

C++ hex string to byte array

谁都会走 提交于 2020-01-06 04:46:04
问题 I'm trying to send a string of hex values through udp, 11 22 33 44 37 4D 58 33 38 4C 30 39 47 35 35 34 31 35 31 04 D7 52 FF 0F 03 43 2D AA using UdpClient in C++. What's the best way to convert string^ to array< Byte >^ ? 回答1: This works for me, although I haven't tested the error-detection all that well. ref class Blob { static short* lut; static Blob() { lut = new short['f'](); for( char c = 0; c < 10; c++ ) lut['0'+c] = 1+c; for( char c = 0; c < 6; c++ ) lut['a'+c] = lut['A'+c] = 11+c; }

How to read the C++ CLI .obj files (result of compilation of a single file)

╄→гoц情女王★ 提交于 2020-01-06 04:45:08
问题 I have a small (<300 lines) C++ file in a C++ CLI project in Visual Studio 2010. I have crafted some macros which do different things depending on the Debug/Release configurations. I would like to be able to look at the resulting .obj files (when I compile in Debug and Release) and be able to compare the two. The hard part is that files are binary and I do not understand their format. I am sure there are other ways to ensure that the macro is not destructive - e.g. try it out at runtime in

C++/CLI DLL project stops linking after conversion from VS2008 to VS2010

廉价感情. 提交于 2020-01-05 07:34:15
问题 I converted a perfectly working Managed C++ DLL project that uses Unmanaged C++ LIBs from VS2008 to VS2010. Beforehand I separately rebuilt the LIBs with VS2010 (they are part of another project that I have no authority over). However, after conversion my managed DLL project stopped linking giving me few dosen of LNK2001 error messages (see the sample below). All errors about "std" entities defined within "string" and "iosfwd" headers. Which compiler/linker settings am I missing? Thanks in

Using clang-format with C++/CLI “for each”

試著忘記壹切 提交于 2020-01-05 05:45:06
问题 I currently try to format C++/CLI code using clang-format (version 9.0.0). I cannot figure how to handle for each statements. Before: for each (auto i in I) { } After (say, CTRL-K/CTRL-D in Visual Studio): for each (auto i in I) { } I read here this: ...you might want to change ForEachMacros to add "for each" I tried this: ForEachMacros: - for each - foreach - Q_FOREACH - BOOST_FOREACH then this: ForEachMacros: - 'for each' and this: - "for each" and even this: - "for\s+each" Nothing works.

Loading interdependent assemblies from C++/CLI

两盒软妹~` 提交于 2020-01-04 14:16:28
问题 I want to load two assemblies from C++/CLI; assembly A depends on assembly B, and both are VB.Net projects (3.5). I want them to load from a byte array, so I use Assembly::Load(), but when I try to instantiate a class from assembly A, the framework ignores the previously loaded assembly B and attempts to load it again, which fails because it is not in the search path. The "Name" of the assembly is the same, so I don't know why it fails. For testing purposes, my program loads the bytes

How do I check if System::Collections:ArrayList is empty / nullptr / null?

丶灬走出姿态 提交于 2020-01-04 13:42:04
问题 I'd like to know how in C++/CLI it is possible to check whether an ArrayList is existent. System::Collections::ArrayList %queue_tx I tried if ( nullptr != queue_tx ) { queue_tx.Add(msg); } but that didn't work. I'm passing queue_tx as a parameter to a function and there's supposed to be the possibility of this parameter not being set (or being set to nullptr ). The compiler throws '!=' : no conversion from 'System::Collections::ArrayList' to 'nullptr' . How do I do this? 回答1: % defines a

Stuck on calling convention calling Managed CLI method from unmanaged C++

让人想犯罪 __ 提交于 2020-01-04 09:38:10
问题 I am trying to call a managed method from unmanaged code. However, the managed code is requiring that I use the '(__clrcall) calling convention, and my unmanaged C++ code refuses to let me use the __clrcall calling convention without using the /clr option. I don't believe I want to do that as the unmanaged project is not mine to change to managed. I have gone through constructing all those delegates and function pointer marshaling in the managed side as I have seen on CodeGuru and MSDN but

Is auto_handle still the suggested method for determanistic disposal of handles?

删除回忆录丶 提交于 2020-01-04 09:24:05
问题 A colleague of mine came across an article on codeproject over the weekend which describes the use of the auto_handle method. Given that the article was written in 2006, is that still the right way to handle deterministic disposal for things like file handles? We've tended to explicitly flush and close file handles and then delete the pointers and null them to be certain the GC has no excuse not to collect them (yes, we know we're super-paranoid). Using something like auto_handle looks like

Is auto_handle still the suggested method for determanistic disposal of handles?

帅比萌擦擦* 提交于 2020-01-04 09:23:12
问题 A colleague of mine came across an article on codeproject over the weekend which describes the use of the auto_handle method. Given that the article was written in 2006, is that still the right way to handle deterministic disposal for things like file handles? We've tended to explicitly flush and close file handles and then delete the pointers and null them to be certain the GC has no excuse not to collect them (yes, we know we're super-paranoid). Using something like auto_handle looks like