c++-cli

Access violation on static initialization

最后都变了- 提交于 2019-11-27 12:52:25
I am working on an application with Visual Studio 2015 on Windows 7. The application has a C# frontend, a C++ CLR wrapper and C++ native code. My application crashes with an access violation while initializing a static variable at function scope with C++ native code. But only on Windows Server 2003 Enterprise SP2 and not on Windows 7 or Windows Server 2012. I know Windows Server 2003 is out of support, but I have to target that platform for a few additional months and Visual Studio 2015 provides a platform toolset to target it. I created a small reproducible example which you find at the end.

How can I make my managed NuGet package support C++/CLI projects?

不羁岁月 提交于 2019-11-27 10:04:40
问题 I have made a NuGet package that works well when I use it from a C# project. It contains a DLL in the lib/net40 directory, and the DLL gets added as a reference. Now that NuGet supports C++, how do I actually modify my package so that the DLL can be added as a managed reference in a C++/CLI project? I can't find any tutorials explaining this. If I try to just add the package as is, I get the following error: You are trying to install this package into a project that targets 'Native,Version=v0

Why does the WPF designer fail to load libraries that call into unmanaged DLLs?

守給你的承諾、 提交于 2019-11-27 09:33:11
I am using Visual Studio 2008, .NET 3.5 SP1, and have a test application with the following modules: a C++ DLL a C++/CLI DLL that uses #1 a C# WPF application that uses #2 When I try to use classes from #2 as resources in the WPF XAML, the designer won't let me: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lib1="clr-namespace:ClassLibrary1;assembly=ClassLibrary1" <- ERROR The error is: "Assembly 'ClassLibrary1' was not found. Verify that you are not missing an assembly

Custom Marshaler for PInvoke with std::string

微笑、不失礼 提交于 2019-11-27 08:49:09
问题 Disclaimer: C++/CLI Noob question I'm attempting to use a PInvoke on a C++ DLL that has a std::string in the signature. At the moment I just testing: my goal is to pass a string to the native DLL, and return it. The native export looks like this: #define NATIVE_CPP_API __declspec(dllexport) NATIVE_CPP_API void hello_std(std::string inp, char* buffer) { const char* data = inp.data(); strcpy(buffer, data); } I'm attempting to PInvoke it in the normal way, with a custom marshaler: [DllImport(

Optional parameters in managed C++/CLI methods

ぐ巨炮叔叔 提交于 2019-11-27 07:43:41
问题 How can I declare a managed method in C++/CLI that has an optional parameter when used from C#? I've decorated the parameter with both an Optional and a DefaultParameterValue attribute (see: How default parameter values are encoded), but only the Optional attribute seems to be honored. C++/CLI: public ref class MyClass1 { public: MyClass1([System::Runtime::InteropServices::Optional] [System::Runtime::InteropServices::DefaultParameterValue(2)] int myParam1) ↑ { System::Console::WriteLine

Using C# extension methods from managed C++/CLI

跟風遠走 提交于 2019-11-27 07:38:58
问题 Forgive me if my terminology is a little off. My knowledge of managed C++/CLI is very limited. I have an MFC application that uses a dll with the /clr option enabled. This dll uses a couple of C# dlls to communicate with a server using WCF. For the most part this works fine. In one of the C# dlls, I've added an extension method to the System.Net.IPAddress class that will retrieve the subnet mask for the IPAddress object (using the UnicastIPAddressInformation class and its IPv4Mask). The

Windows Phone 7 and native C++/CLI

牧云@^-^@ 提交于 2019-11-27 06:53:23
Microsoft recently released tools and documentation for its new Phone 7 platform, which to the dismay of those who have a big C++ codebase (like me) doesn't support native development anymore. Although I've found speculation about this decision being reversed, I doubt it. So I was thinking how viable would be to make this codebase available to Phone 7 by adapting it to compile under C++/CLI. Of course the user interface parts couldn't be ported, but I'm not sure about the rest. Anyone had a similar experience? I'm not talking about code that does heavy low-level stuff - but there's a quite

Lambda expressions as CLR (.NET) delegates / event handlers in Visual C++ 2010

倖福魔咒の 提交于 2019-11-27 06:50:18
问题 Is it possible to use the new lambda expressions in Visual C++ 2010 as CLR event handlers? I've tried the following code: SomeEvent += gcnew EventHandler( [] (Object^ sender, EventArgs^ e) { // code here } ); It results in the following error message: error C3364: 'System::EventHandler' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function Am I attempting the impossible, or is simply my syntax wrong? 回答1: No can do, the C++/CLI compiler didn't

C++ CLI error C3767: candidate function(s) not accessible

流过昼夜 提交于 2019-11-27 05:04:43
I'm new to C++ CLI coming from unmanaged C++ world. I'm getting this error: candidate function(s) not accessible when I pass a std::string as part of the method argument. Here's the exact code: Lib Project (compiled as .dll project) //Lib.h #pragma once public ref class Lib { public: Lib(void); public: void Extract( std::string& data_ ); }; //Lib.cpp #include "Lib.h" Lib::Lib(void) { } void Lib::Extract( std::string& data_ ) { data_.empty(); } LibTest Project (compiled as application.exe) // LibTest.h #pragma once ref class LibTest { public: LibTest(void); }; // LibTest.cpp #include "LibTest.h

How to properly access c++/CLI initonly TimeSpan field?

本秂侑毒 提交于 2019-11-27 04:41:59
问题 The following code compiles with warning and intellisense error: ref class Test { initonly static TimeSpan Delay = TimeSpan(1,1,1); Test() { long long ticks = Delay.Ticks; // << problem } }; The problems are: warning C4395: 'System::TimeSpan::Ticks::get' : member function will be invoked on a copy of the initonly data member 'Test::Delay' IntelliSense: taking the address of an initonly field is not allowed How to access Ticks properly? 回答1: Well, that's pretty major fail-whale. The warning is