c++-cli

Standard conformant way of converting std::time_t to System::DateTime?

血红的双手。 提交于 2019-11-28 10:30:36
I have already found several answers related to converting a std::time_t value to System::DateTime and back. However, almost all answers seem to neglect that the type of std::time_t is actually undefined in the standard. Most solutions just cast std::time_t to whatever needed or apply arithmetic operations to a std::time_t object which is possible since it's an arithmetic type, but there is no specification about the result of such an operation. I know that most compilers define time_t as an int of some size but the fact alone that it has changed from int32 to int64 in many implementations

How do I convert a System::String^ to const char*?

百般思念 提交于 2019-11-28 10:14:04
I'm developing an app in C++/CLI and have a csv file writing library in unmanaged code that I want to use from the managed portion. So my function looks something like this: bool CSVWriter::Write(const char* stringToWrite); ...but I'm really struggling to convert my shiny System::String^ into something compatible. Basically I was hoping to call by doing something like: if( m_myWriter->Write(String::Format("{0}",someValueIWantToSave)) ) { // report success } using namespace System::Runtime::InteropServices; const char* str = (const char*) (Marshal::StringToHGlobalAnsi(managedString)).ToPointer(

How can I get close to non-nullable reference types in C# today?

孤街浪徒 提交于 2019-11-28 09:41:23
I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack. However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo& ). The compiler makes this work by adding modreq(IsImplicitlyDereferenced) to the argument. Trying to call such a function from C# results in: '<FunctionName>' is not supported by the language Is there anything better then NonNullable<> ? Is there any way to (reasonably--i.e., w/o using reflection) call

c++/cli wrapper question

安稳与你 提交于 2019-11-28 09:30:13
问题 Is there a recommended way to wrap a native c++ library by c++ cli? 回答1: Not sure if one size fits all, but yeah, it is largely a mechanical process. Your ref class wrapper should declare a private member that's a pointer to your native C++ class. Create the instance in the constructor. You'll need a destructor and a finalizer to delete that instance again. Then for each function in the native C++ class you write a managed version of it. That's almost always a one-to-one call, you simply call

Is the sealed command c++ 0x or is it only microsoft who has it

为君一笑 提交于 2019-11-28 08:26:24
问题 Is the sealed command going to be in c++ 0x or is it only MS who use it? 回答1: C++0x has a special identifier final which means the same as sealed for classes in C++/CLI. It prevents a class from being derived from. Read about sealed in Wikipedia So the answer is basically: it already is but under a different name and has a different syntax. 回答2: sealed is a really .net term and so is specific to MS C++/CLI. 回答3: Sealed is used to declare a .net class that cannot be derived from. It's

Visual Studio 2012 failing to detect Visual Studio 2008 build tools

…衆ロ難τιáo~ 提交于 2019-11-28 08:11:27
I am trying to use Visual Studio 2012 to build a C++ CLI application targeting .NET 3.5. I've already gotten this working on one machine, by installing Visual Studio 2008, and specifying the v90 platform toolset. Now I am attempting this on a new machine, and I've installed Visual Studio 2008, then Visual Studio 2012. Now I get this incredibly frustrating error: Error 81 error MSB8020: The builds tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found. To build using the v90 build tools, either click the Project menu or right-click the solution, and then select "Update VC++

unmanaged var as member of managed class c++

让人想犯罪 __ 提交于 2019-11-28 08:09:36
问题 I'm novice in .net c++ and trying to create class looking like: public ref class Klient { public: Klient(){} // zmienne static DWORD klienty[41][2]; static int i = 1; static DWORD* pid; static HANDLE* handle; //funkcje }; but MSV says that: error C4368: cannot define 'klienty' as a member of managed 'Klient': mixed types are not supported What's wrong with this code? 回答1: You can have .NET basic data types as members of your managed class (static int i), or pointers to anything unmanaged

Strong Name Validation Failed

回眸只為那壹抹淺笑 提交于 2019-11-28 08:08:17
Two machines. Both with .NET 3.5 and the VS 2008 VC++ SP1 redistributables A single exe which uses two signed DLLs, one in C++/CLI and one in C# The exe loads and runs fine on one machine. On the other, I get "Strong Name Validation Failed" on the C++ executable (HRESULT 0x8013141A) Any ideas? Butsaty Open the command prompt as administrator and enter following commands: reg DELETE "HKLM\Software\Microsoft\StrongName\Verification" /f reg ADD "HKLM\Software\Microsoft\StrongName\Verification\*,*" /f reg DELETE "HKLM\Software\Wow6432Node\Microsoft\StrongName\Verification" /f reg ADD "HKLM

How to forward overloaded constructor call to another constructor in C++/CLI

独自空忆成欢 提交于 2019-11-28 07:39:17
问题 I know that there is no way to do this in pure C++, but I was wondering if it is possible to call a constructor from another constructor's initialization list in C++/CLI, same way one can do it in C#. Example: ref class Foo { Foo() {} Foo(int i) : Foo() {} } 回答1: It is called a "delegating constructor". It is not available in the language yet. But there's a formal proposal, you'll find it in annex F.3.1 of the language specification. Given Microsoft's stance towards C++/CLI, that is unlikely

Need to convert String^ to char *

五迷三道 提交于 2019-11-28 07:15:35
问题 I am using the .NET DateTime to get the current date and time. I am converting it to a string to use as part of a file name. The problem is the OpenCV command to save an image requires a char * not a string type, and DateTime will only output a String^ type. How do I make this work? Heres the code not completed String^ nowString = DateTime::Now.ToString("yyyy-MM-dd-HH:mm"); IplImage* toSave; CvCapture* capture = cvCreateCameraCapture(0); toSave = cvQueryFrame( capture ); cvSaveImage(nowString