c++-cli

Access violation on static initialization

时间秒杀一切 提交于 2019-11-26 18:13:45
问题 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

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

白昼怎懂夜的黑 提交于 2019-11-26 17:52:36
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 the .Net AppDomain stuff seems to require a lot of stuffing around. So what is the nicest/simplest

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

天涯浪子 提交于 2019-11-26 17:51:20
问题 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" <-

Why C# is not allowing non-member functions like C++

五迷三道 提交于 2019-11-26 17:33:43
C# will not allow to write non-member functions and every method should be part of a class. I was thinking this as a restriction in all CLI languages. But I was wrong and I found that C++/CLI supports non-member functions. When it is compiled, compiler will make the method as member of some unnamed class. Here is what C++/CLI standard says, [Note: Non-member functions are treated by the CLI as members of some unnamed class; however, in C++/CLI source code, such functions cannot be qualified explicitly with that class name. end note] The encoding of non-member functions in metadata is

How to implement a unmanaged thread-safe collection when I get this error: <mutex> is not supported when compiling with /clr

…衆ロ難τιáo~ 提交于 2019-11-26 17:28:38
问题 I have a C++ application which consists of unmanaged C++, managed C++ and c#. In the unmanaged part I'm trying to create a thread safe collection using std::mutex. However when I use the mutex I get the following error; error C1189: #error : <mutex> is not supported when compiling with /clr or /clr:pure. Any idea why I can't use the mutex? Can someone recommend a replacement for it so that I can create a thread-safe unmanaged collection? 回答1: It is not supported because the std::mutex

Best workaround for compiler error C2158: make_public does not support native template types

元气小坏坏 提交于 2019-11-26 17:26:13
问题 I have two c++/cli dlls (i.e. compiled with /clr) where A.dll references B.dll. In assembly B, I have a method, GetMgdClassB, I'd like to call from assembly A. Here is the code in assembly B (B.cpp): namespace B { public class NativeClassB { public: NativeClassB(); // ... }; public ref class MgdClassB { public: static MgdClassB ^ GetMgdClassB(const std::vector<NativeClassB *> & vecNativeBs) { // ... vecNativeBs; return gcnew MgdClassB(); } }; } Notice that the method GetMgdClassB takes a std:

No IntelliSense for C++/CLI in Visual Studio 2010?

ぐ巨炮叔叔 提交于 2019-11-26 16:33:50
I just moved from Visual Studio 2008 to Visual Studio 2010 (final) and noticed one major flaw: When I try to use AutoComplete in a C++ source file for managed C++, a small note in the footer appears: IntelliSense for C++/CLI is not available Uh, has IntelliSense for C++/CLI been dropped from Visual Studio 2010? Is there any way to get this back? It is rather useful... Ivan Zlatanov You are correct. Unfortunately it has been dropped. You can check this opened issue on Microsoft's Connect website . I'll just quote them for the sake of the answer: Unfortunately in this release we had to cut the

C++CLI. Are native parts written in pure C++ but compiled in CLI as fast as pure native C++?

天大地大妈咪最大 提交于 2019-11-26 15:58:20
问题 I want to delegate audio computing to a C++ layer, but handle and edit audio content through a WPF GUI. I have had a brief look at C++/CLI, and I wanted to know: should I use C++/CLI as an intermediate layer between C# GUI and C++ audio management or should I simply put my code in C++/CLI and expect it to be compiled the same way, thus as efficient. EDIT: as the flaming war may begin. This is a link that goes to the benchmarks game, that clearly states the C/C++ as a speed winners. I am

How do I call C++/CLI from C#?

匆匆过客 提交于 2019-11-26 14:54:55
I have a class implemented in C++ that's responsible for the arithmetic computation of the program, and an interface using WPF. I process the input with C# but then how can I use my C++ class? I've seen some comments about making a managed C++ wrapper class to interact with it, but I don't know where to start. Nor do I know how I'd go to compile it along with all the other code. I can't really find a tutorial on this, and the stuff google shows on managed C++ doesn't really seem helpful. Anything out there to help me out? This doesn't seem unreasonable to me. EDIT Tried m3rLinEz solution but

In C++/CLI, what does the hat character ^ do? [duplicate]

巧了我就是萌 提交于 2019-11-26 13:22:48
This question already has an answer here: What does the caret (‘^’) mean in C++/CLI? 7 answers I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main: int main(array<System::String ^> ^args) I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really means, but couldn't find one. Obviously it means the same as the standard int main(int argc, char *argv[]) , but I'd like to know when and why that ^ is really used, and why it even exists (does it do something that pointers *