c++-cli

create a namespace in c++/cli?

霸气de小男生 提交于 2019-12-24 02:52:17
问题 I have seen many examples of using .NET Framework namespaces in c++/cli like the following: using namespace System; using namespace System::IO; But I haven't seen any examples of creating my own. So I was wondering if there is a way to declare/create my own namespace as I would in C#: namespace Animals { public class Dog { public Dog() {} } } Thanks for your time :) 回答1: Same syntax for single namespaces. Nest for multiples, e.g. for First.Second.Third: namespace First { namespace Second {

Embedded Unmanaged DLLs don't load in ASP.NET

杀马特。学长 韩版系。学妹 提交于 2019-12-24 02:47:11
问题 I'm working on an ASP.NET host for a WCF service. The service references a C++/CLI wrapper library, which itself references an unmanaged DLL. Based on this question I've embedded the unmanaged DLL in the ASP.NET DLL. I then extract it like this: string[] dlls = new [] { "myDLL.dll", "myDLLD.dll" }; Assembly assembly = Assembly.GetExecutingAssembly(); string location = Path.GetDirectoryName(assembly.Location); Dictionary<string, Stream> streams = (from dll in dlls select new KeyValuePair

C++/CLI double pointer typecasting to ref IntPtr for C# access

柔情痞子 提交于 2019-12-24 02:15:06
问题 I am writing a wrapper around C DLL in C++/CLI so that it can be accessed in C# through a managed assembly. Using direct P/Invoke to access C functions via C# is not possible because C DLL raises exceptions which cannot be correctly caught using P/Invoke (exception message is lost when moving across C/C# boundary). So the idea is to create a managed CLI DLL which internally calls C DLL and wraps the exception to Exception class of CLI. So the C DLL function has this declaration. void InitDB

Wrapping a c#/WPF GUI around c++/cli around native c++

纵饮孤独 提交于 2019-12-24 01:53:36
问题 This is kind of a complicated situation. I'm refactoring (ground-up) c++ that must be used as both a CGI script and the core of a standalone app. Unfortunately I haven't written C++ since college, and am more familiar with c#/Java. So I'm going to use WPF for the GUI. From what my research has revealed, this means that I will be: 1) Refactoring the base code in unmanaged C++ (yay for intellisense support, eh?) 2) Wrapping that base in a managed class library 3) Wrapping step 2 in a C#/WPF GUI

How to specify a callback from C# to C++/CLI

白昼怎懂夜的黑 提交于 2019-12-24 01:29:37
问题 I would like to pass a function pointer (or similar) as a callback function to the constructor of a C# class, called from C++/CLI. The C# class is a sub-module; the C++ side is the main program. I'm getting errors reported by Visual Studio 2017, and I can't work out the correct syntax to use. (I'm a C++ programmer, but have close to zero experience with CLI and C#.) I find plenty of examples on how to set up callbacks the other way around, but from C# to C++/CLI I find little information. Can

Unable to set breakpoints in C DLL used by C++/CLI called from C#

◇◆丶佛笑我妖孽 提交于 2019-12-24 00:37:45
问题 I have a native C DLL being invoked by a C++/CLI object which is the ViewModel for a WPF progam in C#. I want to set breakpoints in the C DLL. When I try to set them they are grayed out and the help balloon says the breakpoint will not currently be hit. No symbols have been loaded for this document. To get the program to run OK I had to add a custom build step which copies the DLL, PDB, ILK and LIB files to the intermediate directory of the C# main program. I suspect that has something to do

C++/CLI: linker gives “unresolved token” for win32 function

牧云@^-^@ 提交于 2019-12-24 00:34:01
问题 Folks, I just created my first C++/CLI project (Visual Studio 2008), it's a Library to allow my C# app access an point of sale tally printer. My library builds well and trivial functions work when called from a C# exe. However as soon as I include a WinGDI call (DeleteObject in this case), the linker complains with “unresolved token” errors. Error 2 error LNK2028: unresolved token (0A000088) "extern "C" int __stdcall DeleteObject(void *)" (?DeleteObject@@$$J14YGHPAX@Z) referenced in function

How to best avoid double thunking in C++/CLI native types

本秂侑毒 提交于 2019-12-24 00:18:59
问题 Tradionally, I've been using MFC extension dll's and importing/exporting using dllimport/dllexport. However, when the dll is changed to use /clr, this method becomes costly as calls can result in a double-thunk. I'm taking a massive performance hit at the moment and need to stop the double-thunks. The solution I've seen described suggests making sure everything is using __clrcall convention, but this does not work with dllexport. Microsoft's own section on double-thunking suggests: Similarly,

Visual Studio 2010 randomly says the command line changed, and rebuilds

被刻印的时光 ゝ 提交于 2019-12-23 19:51:17
问题 Visual Studio sometimes decides to rebuild my entire huge project because of one small change. I turned build logging up to Diagnostic to see what was the problem, and here's what I'm seeing: < Bunch of spam > Outputs for C:\<snip>\PRECOMPILEDHEADERS.CPP: C:\<snip>\PRECOMPILEDHEADERS.OBJ All outputs are up-to-date. Forcing rebuild of all source files due to a change in the command line ... and then it rebuilds my precompiled headers, then everything else. This happens when I change a single

C++/CLI/C# BadImageFormat Exception when loading form

我与影子孤独终老i 提交于 2019-12-23 19:18:50
问题 I created a C++/CLI assembly that creates a wrapper around native C++ code. The resource compiles and the assembly loads fine into my C# project when I add it as a resource. I can access my objects and intellisense from within my application, but when attempting to build, it crashes with the exception: BadImageFormat Could not load file or assembly 'MyCLI, Version=1.0.3680.28432, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an