c++-cli

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

痞子三分冷 提交于 2019-12-17 19:29:04
问题 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

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

守給你的承諾、 提交于 2019-12-17 19:09:41
问题 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

Strong Name Validation Failed

守給你的承諾、 提交于 2019-12-17 18:34:33
问题 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? 回答1: 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\*,*"

Tracking reference in C++/CLI

蓝咒 提交于 2019-12-17 18:24:39
问题 Can someone please explain me the following code snippet? value struct ValueStruct { int x; }; void SetValueOne(ValueStruct% ref) { ref.x = 1; } void SetValueTwo(ValueStruct ref) { ref.x = 2; } void SetValueThree(ValueStruct^ ref) { ref->x = 3; } ValueStruct^ first = gcnew ValueStruct; first->x = 0; SetValueOne(*first); ValueStruct second; second.x = 0; SetValueTwo(second); // am I creating a copy or what? is this copy Disposable even though value types don't have destructors? ValueStruct^

How to link C# and C++ assemblies into a single executable?

强颜欢笑 提交于 2019-12-17 17:58:14
问题 I have VS2008 solution containg a project that generates a C# executable that references a project that generates a dll containing both C++/CLI and unmanaged C++. I would like to merge these into a single executable, as the C++ dll contains security code that I want to embed in the main executable. I cannot use ILMerge, as the dll contains both managed and unmanaged code. The suggested solution seems to be to use link.exe to link the C# assembly with the C++ object files. This is what I am

Call C# dll function from C++/CLI

ε祈祈猫儿з 提交于 2019-12-17 16:34:13
问题 I have a C# dll. The code is below: public class Calculate { public static int GetResult(int arg1, int arg2) { return arg1 + arg2; } public static string GetResult(string arg1, string arg2) { return arg1 + " " + arg2; } public static float GetResult(float arg1, float arg2) { return arg1 + arg2; } public Calculate() { } } Now, I am planning to call this dll from C++ on this way. [DllImport("CalculationC.dll",EntryPoint="Calculate", CallingConvention=CallingConvention::ThisCall)] extern void

C++/CLI-Question: Is there an equivalent to the C# “is” keyword or do I have to use reflection?

☆樱花仙子☆ 提交于 2019-12-17 16:07:16
问题 I've read somewhere on MSDN that the equivalent to C#'s "is" keyword would be dynamic_cast, but that's not really equivalent: It doesn't work with value types or with generic parameters. For example in C# I can write: void MyGenericFunction<T>() { object x = ... if (x is T) ...; } If I try the "equivalent" C++/CLI: generic<class T> void MyGenericFunction() { object x = ... if (dynamic_cast<T>(x)) ...; } I get a compiler error "error C2682: cannot use 'dynamic_cast' to convert from 'System:

How can I call to a C++ function from C#

亡梦爱人 提交于 2019-12-17 15:34:36
问题 I have C++ code. That code contains Windows mobile GPS enable/disable functionality. I want to call that method from C# code, that means when the user clicks on a button, C# code should call into C++ code. This is the C++ code for enabling the GPS functionality: #include "cppdll.h" void Adder::add() { // TODO: Add your control notification handler code here HANDLE hDrv = CreateFile(TEXT("FNC1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (0 ==

Does Mono .NET support and compile C++ / CLI?

人走茶凉 提交于 2019-12-17 07:27:31
问题 Does Mono .NET support and compile C++ / CLI? If not, do you know if they have any plans of supporting it? 回答1: We don't have a compiler for C++/CLI, it would be a very large undertaking for a very small userbase. Consider also that the C++/CLI spec is inherently flawed and non-portable, so being able to compile it wouldn't help much in the general case. You can compile using the MS .NET compiler and run in mono with these restrictions: run with mono on any system if the C++/CLI app is pure

How to get the application executable name in WindowsC++/CLI?

こ雲淡風輕ζ 提交于 2019-12-17 03:41:11
问题 I need to change the functionality of an application based on the executable name. Nothing huge, just changing strings that are displayed and some internal identifiers. The application is written in a mixture of native and .Net C++-CLI code. Two ways that I have looked at are to parse the GetCommandLine() function in Win32 and stuffing around with the AppDomain and other things in .Net. However using GetCommandLine won't always work as when run from the debugger the command line is empty. And