c++-cli

Can I use mock objects to mock a serial port?

半世苍凉 提交于 2019-12-03 16:28:48
I am developing an application in C++/CLI that communicates with a device via a Serial Port. and testing them using MS Test. I'm just reading up about mock objects and have only understood it conceptually. I face many challeneges in unit testing, primarily because the simulator I use to send data over the serial port to my app behaves in a certain way and I cant get it to change its behaviour. What I would like to know is: Can I use mock objects to mimic the Serial Port behaviour? its input buffer? Can I use the mock object to change the Serial Port behaviour(ie to pretend that the port is

unsigned char* buffer to System::Drawing::Bitmap

ε祈祈猫儿з 提交于 2019-12-03 16:15:10
I'm trying to create a tool/asset converter that rasterises a font to a texture page for an XNA game using the FreeType2 engine. Below, the first image is the direct output from the FreeType2] 1 engine. The second image is the result after attempting to convert it to a System::Drawing::Bitmap . target http://www.freeimagehosting.net/uploads/fb102ee6da.jpg currentresult http://www.freeimagehosting.net/uploads/9ea77fa307.jpg Any hints/tips/ideas on what is going on here would be greatly appreciated. Links to articles explaining byte layout and pixel formats would also be helpful. FT_Bitmap

Understanding gcroot

一世执手 提交于 2019-12-03 14:43:20
问题 I have been reading this article to understand the gcroot template. I understand the gcroot provides handles into the garbage collected heap and that the handles themselves are not garbage collected. What I don't understand is the following: When the CLR object moves with the garbage-collected heap, the handle will return the new address of the object. A variable does not have to be pinned before it is assigned to a gcroot template. Does that mean that the CLR object will be deleted by the

What are the situations or pros and cons to use of C++/CLI over C#

半世苍凉 提交于 2019-12-03 14:08:46
I have been keeping up with .NET CLR for awhile now, and my language of choice is C#. Up until recently, I was unaware that C++/CLI could produce "mixed mode" executables capable of running native and managed code. Now knowing this, another developer friend of mine were discussing this attribute and trying to determine when and how this ability would be useful. I take it as a given that native code has the capability to be more efficient and powerful than managed code, at the expense of additional development time. In the past, I resorted to strictly native C++ code libraries and used Interop

C++/CLI Inheriting from a native C++ class with abstract methods and exposing it to C#

自古美人都是妖i 提交于 2019-12-03 14:07:14
I've been googling around in circles trying to find an fully fledged example to this but to no avail. I have a C++ API that presents a number of classes that contain pure virtual methods for the developer to extend from. What I'm attempting to do is provide this interface to C# via the C++/CLI. I've managed to get the API compiled into the C++/CLI library and I've reached a sticking point as I'm new to this. I'm aware that I need to create a wrapper to expose the C++/CLI unmanaged class to a managed .net class but I've not found a solid example or discussion that shows how to do this with the

C++/CLI class wrapper for c library - callbacks

风流意气都作罢 提交于 2019-12-03 14:03:31
I am wrapping a C library using C++/CLI. The C library was designed to be used from an unmanaged C++ class. This means that the library functions accept a C++ object pointer and then provide that pointer back in callbacks. This enables the callback code to redirect requests to an appropriate event function in the calling C++ object. The actual functions are quite involved, so I have simplified the problem space to just a few basic items: // C library function signature void CLibFunc(CLIBCALLBACK *callback, void *caller); // C callback signature // Second parameter is meant to point to the

convert struct handle from managed into unmanaged C++/CLI

丶灬走出姿态 提交于 2019-12-03 13:57:04
问题 In C#, I defined a struct: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct MyObject { [MarshalAs(UnmanagedType.LPWStr)] public string var1; [MarshalAs(UnmanagedType.LPWStr)] public string var2; }; I have this struct in C++: public value struct MyObject { LPWSTR var1; LPWSTR var2; }; And in the method of C++ which is a public class to be called from C#: TestingObject(MyObject^ configObject) { // convert configObject from managed to unmanaged. } The object is

Limitations of using C++/CLI with NUnit

為{幸葍}努か 提交于 2019-12-03 13:01:34
This answer to a question about C++ unit test frameworks suggests a possibility that had not occurred to me before: using C++/CLI and NUnit to create unit tests for native C++ code. We use NUnit for our C# tests, so the possibility of using it for C++ as well seems enticing. I've never used managed C++, so my concern is are there any practical limitations to this approach? Are many of you doing this? If so, what was your experience like? We do this all of the time. We have many assemblies written with C++/CLI and use C# and NUnit to test them. Actually, since our goal is to provide assemblies

C++ CLI System.String^ to MFC LPCTSTR

本小妞迷上赌 提交于 2019-12-03 12:33:42
How would I convert a System (.net) C++\CLI String^ into a MFC C++ LPCTSTR string. It is very easy to get a LPCTSTR into String^ , but so far found nothing on doing it the other way around. If you have Visual Studio 2008 or above, you should be able to do this using the C++/CLI marshaling library, like so: #include <msclr\marshal.h> using namespace System; using namespace msclr::interop; ... String^ cliString; marshal_context context; LPCTSTR cstr = context.marshal_as<const TCHAR*>(cliString); More information on marshaling between types on MSDN: Overview of Marshaling in C++ You might want to

Create NuGet package for C++/CLI (mixed) assembly

孤者浪人 提交于 2019-12-03 12:22:43
I have created a C++/CLI (mixed) assembly which has a managed wrapper class around some unmanaged C++ code. The managed part targets .NET 4.6.1, I got a file entry.cpp with just this line to do that: [assembly:System::Runtime::Versioning::TargetFrameworkAttribute(L".NETFramework,Version=v4.6.1", FrameworkDisplayName = L".NET Framework 4.6.1")]; When I now manually include the compiled assembly in a .NET 4.6.1 project I can use the managed class as expected. This project can be build four ways: x86 or x64 as either debug or release build. It has no managed dependencies. Now I want one (or if