c++-cli

Calling C# function from C++/CLI - Convert Return C# string to C String

坚强是说给别人听的谎言 提交于 2019-12-11 08:15:41
问题 I have a C# function that I made into a DLL: public static string Test(string name) { return "Hello " + name; } In C++/CLI project I successfully import that DLL, now I want to have a way to call that function and make it available for normal unmanaged C++. So I want to export the C++/CLI function like this: extern "C" __declspec(dllexport) void __stdcall Example(char* name, char* greet) { // name will be passed to C# Test(...) function // and greet will contains the returned value // call to

Replacing bookmarks in docx file using OpenXml SDK and C++/CLI

孤街浪徒 提交于 2019-12-11 07:58:44
问题 I am trying to replace bookmark in docx with text in c++\cli using open xml SDK concept. The below piece of code will fetch bookmarks from word document and checks whether the bookmark matches the string “VERSION” if it is true, it is replaced with the string “0000” in the docx file. Paragraph ^paragraph = gcnew Paragraph(); Run ^run = gcnew Run(); DocumentFormat::OpenXml::Wordprocessing::Text^ text = gcnew DocumentFormat::OpenXml::Wordprocessing::Text(“0000”); run->AppendChild(text);

Declaring a struct, usable from C#, in managed C++

耗尽温柔 提交于 2019-12-11 07:50:19
问题 I have a scenario where a C# library is consuming a mixed mode C++ library. The use case is as follows: 1) The C# code initializes a listener from the library (managed c++), which initializes a listener from native C++. 2) The native code receives a message and parses it, then passes it to the managed c++ via IJW code 3) The managed c++ calls a delegate from the C# code with the message This all works fine, except for the very last part - actually including the message. The C# code can't

How to compile a program using .NET Framework compilers at command line.?

久未见 提交于 2019-12-11 07:47:11
问题 i want to compile a c++ program using .NET2.0 compiler. so i navigate to c:\windows\Microsoft.Netframework\2.0.57\ and uses csc compiler to compile. It shows lot of errors. But it compiles csharp file. But in visual studio it compiles. so i think that in visual studio c++ copiler installed i think so. filename test.cpp using namespace System; class test { void disp() { Console::WriteLine("Hello"); } }; void main() { test *t=new test(); t->disp(); } so plz tell me is it possible to compile c++

How to set the text in a TextBox control from native code?

不羁的心 提交于 2019-12-11 07:44:47
问题 Is it possible to manipulate .net controls from native code? Particularly, I'd like to set the text of a TextBox from some native code. I want it done this way to keep the business logic separated from the user interface, but it is precisely the native code which only knows how to appropriately format the data (some bytes received within a protocol). I know I could get the window handle through the Handle property, but once there, how would I call the desired method? Is string handling my

change XmlElement Name property

我怕爱的太早我们不能终老 提交于 2019-12-11 07:43:21
问题 I would like to change the Name property of an XmlElement in c++/cli. I would like to do myXmlElem.Name = "xyz" , but the compiler tells me that I can't do a set operation on the Name property. i.e. <abc/> changed to <xyz/> How can I achieve this? Thanks! 回答1: you can't change the Name property of an XmlElement like that (Name is read only). you can however do something like the following (example in C#). XmlElement xyz = myXmlElem.OwnerDocument.CreateElement("xyz"); myXmlElem.ParentNode

Change label text from different header file, Visual C++ 2010?

荒凉一梦 提交于 2019-12-11 07:41:41
问题 I am using Visual C++ 2010 Express. I have a form ( Form1.h ) that contains a button ( btn1 ) and a label ( label1 ). When I click the button, I would like to call a function from a different header file ( testing.h ) that will then proceed to change the text in the label. What I have is something like this... Form1.h #include "testing.h" ... standard form code generated by Visual Studio private: System::Windows::Forms::Label^ label1; ... private: System::Void btn1_Click(System::Object^

How can I enable the intellisense on my c++/cli project?

左心房为你撑大大i 提交于 2019-12-11 07:38:01
问题 I am using visual studio 2008 and I have a native c++ project that loads a managed c++ dll, but on the last one, the intellisense doesn't work anymore only for the managed code. This project (dll) has a mixed code (native and managed) and if I write only "::" on a clean line, the intellisense gives me the methods inherits from the base class, like regular, not for the managed code, for example array <String^>^ ContactListToChat; I need help, otherwise I´ll have to fly blind. 回答1: Taken from

Writing C# managed code in native C++

狂风中的少年 提交于 2019-12-11 07:31:02
问题 I am developing a managed lib (using Microsoft Web Services) and I am including it into a c++ project. The project doesn't use /clr option, so when I include my library's header file VS2005 show me an error saying I have to use /clr option. Doing this I have a incompatibility with /EHs command line option (error D8016), but changing from EHs to no exception handling not solving problem and keep showing me same error . Any suggestion is welcome. Thank you in advance. 回答1: If you have unmanaged

How to use Namespaces of .Net in C++?

柔情痞子 提交于 2019-12-11 07:29:03
问题 How do I make use of the .NET framework namespaces from C++? 回答1: C# will be using System; using System.Configuration; C++ will be using namespace System; using namespace System::Configuration; Don't forget to reference the libraries in your C++ project properties. 回答2: You can do this in managed C++. Use #using directive and use the namespaces like you normally do. 回答3: Start Here: Pure C++: Hello, C++/CLI 来源: https://stackoverflow.com/questions/736786/how-to-use-namespaces-of-net-in-c