Click here to Skip to main content
15,888,454 members
Everything / Programming Languages / C++/CLI

C++/CLI

C++/CLI

Great Reads

by Dark Daskin
Article describes how to build an assembly that exposes functions to unmanaged code without C++/CLI
by Stoyan Damov
Internet File System from scratch - making web services and peer-to-peer technology work together to build a virtual file system
by Nish Nishant
Demonstrates the usage of splitters, treeviews, listviews, panels, toolbars
by Alexey
The ALXGrid Control Library is a set of classes for management of data as a table.

Latest Articles

by Mark Birbeck
Easily and quickly build web services clients using XForm
by Shao Voon Wong
Consuming Your C# Library in MFC/C++ Project via C++/CLI
by Mehul Donga
Handle managed (C#) event in managed (C++/CLI)
by Abhineet Ayan Verma
Major calling conventions for Win32 and best suited functions

All Articles

Sort by Updated

C++/CLI 

4 Mar 2024 by Richard MacCutchan
See your previous question on this same subject: No instance of overloaded function Microsoft::reporting::winforms::localreport::render[^].
4 Mar 2024 by Paramu1973
Hi, Iam using VS2015 Winforms, VC++. C++/CLI With my application I try to print the rdlc report. And I get the below error. can't take address of 'PrintRDLCReport::CreateStream' unless creating delegate instance. private: static Stream^...
3 Mar 2024 by Richard MacCutchan
According to LocalReport.Render Method (String, String, CreateStreamCallback, out Warning ) (Microsoft.Reporting.WinForms) | Microsoft Learn[^], warnings should be an array of Warning Class (Microsoft.Reporting.WinForms) | Microsoft Learn[^]...
3 Mar 2024 by Paramu1973
Hi, I have small application VS2015 Visual C++, WindowsForms. And I try to print the RDLC report directly to the printer. For that when I tried, I get struck, while I render the report. Any kind advices will be enable to complete the task. Thanks...
2 Mar 2024 by Pete O'Hanlon
Try e->graphics->FillRectangle(Brushes::White, e ->PageBounds.Left - Convert::ToInt32(e->PageSettings->HardMarginX), e->PageBounds.Top - Convert::ToInt32(e->PageSettings->HardMarginY), e->PageBounds.Width, e->PageBounds.Height); instead.
2 Mar 2024 by Paramu1973
Hi, I have a small program and Iam trying to print the RDLC report from the Button_Click(). While I convert the C# code to C++/CLI, I get struck from the below areas. Any kind helps ...Thanks // Handler for PrintPageEvents public: static...
6 Nov 2023 by Member 16134338
#include "main_form.h" using namespace System; using namespace System::Windows::Forms; using System::Threading::Mutex; [STAThread] int main(array^ args) { // Set this variable to false if you do not want to request // initial...
30 Oct 2023 by Rick York
You might find this article and the others in the series helpful : Doing UTF-8 in Windows[^]. I don't think you need to encode it per se. Won't just reading and saving text written in Cyrillic be sufficient?
30 Oct 2023 by Pete O'Hanlon
You should be able to use the capabilities of System::Text::Encoding to manage this. Have a look at the documentation Encoding Class (System.Text) | Microsoft Learn[^].
29 Oct 2023 by rizla 2023
I need to encode the text entered in the textbox in Cyrillic, something like this What I have tried: label->Text = u8 textbox->Text;
25 Oct 2023 by Karl Steven Renevera
I just want to make a Windows Form in C++. After opening a template, the codeblock appears along with the designer. Then, I just want to see if the compiler works, so I tried to compile and... it gives me these. Build started... 1>------ Build...
16 Oct 2023 by Member 16116277
You need to load the form in main. My form is named: MainForm.h My main c++ program is named: mainForm.cpp In mainForm.cpp add the following code: ------------------------------------------ #include "mainForm.h" using namespace skemaProgram; ...
1 Oct 2023 by hans.sch
Silly me. In my question, I said that this line causes the exception: auto ret = method->Invoke(m_pWorker, arg_dummy/*arglist*/); Further, I said that m_pWorker was declared as Object^. This, of course, wasn't true. Actually, the declaration was...
13 Sep 2023 by Maxim Kartavenkov
I think you miss something around m_pWorker and the method also specify the nullptr or create an empty instance of the array arg_dummy here is an example which will be useful - I made it with just C# but the reflection methods which you should...
12 Sep 2023 by hans.sch
I'm trying to call a method of a class that was defined in a C# assembly. The calling code is C++/CLI. Problem: I keep getting a System.Reflection.TargetException with message "Object does not match target type." The assembly has one public...
12 Sep 2023 by Phil J Pearson
Why are you passing a parameter (arg_dummy) to a method that takes no parameters?!
25 Aug 2023 by Mark Birbeck
Easily and quickly build web services clients using XForm
18 Aug 2023 by Maxim Kartavenkov
had you try the next way: int MyCallback(int i) {} public delegate int IntCallback(int i); IntCallback^ callback = gcnew IntCallback(MyCallback); // Use callback variable as an argument
17 Aug 2023 by hans.sch
I'm playing with C++/CLI and calling into a .NET assembly. There is no specific use case, I simply want to learn. I wrote the assembly in C#. It exports a class with a few methods, and a delegate type which is used in one of the methods:...
26 May 2023 by Saurabh Ashtaputre
I have a C# WPF User Control DLL. I want to show this User Control over a C++ MFC UI. For communication between them I am using C++ COM DLL (CLR enabled for this VS project). The IDL file has an entry for the COM function like this: [local]...
26 May 2023 by JudyL_MD
I think you need to put an out on the C# method itself so the compiler knows to pass the changed value back to the caller. Without the out, the changes to the parameter variable are only visible within the method.
11 Apr 2023 by Shao Voon Wong
Consuming Your C# Library in MFC/C++ Project via C++/CLI
6 Apr 2023 by Cameron Handoe
HelloAs part of a personal project, I need to make a console based Scientific calculator.It needs to be able to add, subtract, multiply and divide a large amount of numbers per command (eg: 2+2+2+2+2+2*9/7*sin 45- 88.277) and be able to manipulate numbers correctly using BIDMAS.It...
25 Jan 2023 by WantToLearn1
C++/CLI. I can use serial port in myForm.h, but I need to send serial port messages also from file.cpp. How do I do that? myForm.h: protected: private: System::IO::Ports::SerialPort^ serialPort1; In myForm.h I can send message to serial port...
25 Jan 2023 by Richard MacCutchan
You do it exactly the same way, create a SerialPort object reference and call the relevant method(s). System::IO::Ports::SerialPort^ serialPort1; // set any speed. parity values etc. serialPort1->WriteLine(message);
25 Jan 2023 by WantToLearn1
I have a thing with 2 Basler usb-cameras and 2 lights. For power saving and educating myself I want lights to be ON only when the certain camera is running. This programs opens 2 camera view windows on Windows. Cameras are toggling, only the...
25 Jan 2023 by WantToLearn1
I changed it to work in different way. myForm.h calls only one function from test.cpp and that function does the toggling now. Works fine.
20 Jan 2023 by Rick York
I do not have answer for you but I have run into similar situations in the past and what I did was I added various trace messages so I could figure where in the code it was hanging. That helped to know exactly where I should begin looking to...
15 Nov 2022 by agoswami_84
Hi,could anyone provide me code source or mechanism for "let me google that for you". As i want to personalize the toolor if this is not the correct forum than if possible than please provide me correct forum
15 Nov 2022 by Member 15832555
It's open source, GitHub repo: https://github.com/pykler/lmgtfy
27 Oct 2022 by Mārtiņš Andžäns
LoadCursor(hModule, lpCursorName) Function Loads Cursor From Executable Resource: ����1. hModule - Module Handle To Executable [Use GetModuleHandle(NULL)] ����2. lpCursorName - Cursor Resource Name [Use MAKEINTRESOURCE Macro To Cast Cursor...
10 Oct 2022 by Zanderz McCluer
How do I draw lines on a button table? I am trying to make a tic-tac-toe game with different sizes and I am now onto the scoring part of the program. Right now, I have tried making lines on the program, but they appear on the Form behind the...
10 Oct 2022 by Mike Hankey
Look at using a GraphicsRegion[^] Quote: A region is a portion of the display area of an output device. Regions can be simple (a single rectangle) or complex (a combination of polygons and closed curves).
10 Oct 2022 by Mehul Donga
Handle managed (C#) event in managed (C++/CLI)
15 Aug 2022 by n.deny
i am trying to read and Write the data from microcontroller to c++/cli application using protocol . Write data were successfully done but i am unable to received the data. What I have tried: private: System::Void...
15 Aug 2022 by Richard MacCutchan
Take a look at Serial Port I/O[^] which explains how best to use the serial ports.
8 Aug 2022 by Denesh Neupane
i am trying to read the data from sd card in c++/CLI app using serial communication.i tried the following error but didnot get expected output. What I have tried: SD_Handle handle; uint16_t status; char readBuffer[12] SD_init(); handle =...
11 Feb 2022 by Gremz
Hi all,Hopefully the solution is very easy, but I've been searching online for the past few days for how to use/reference a custom cursor in an application without it being an external file (That is, while it's a resource of the application, itself), but I keep coming up empty.There are...
18 Nov 2021 by n.deny
I am trying to send the data using Rs232c to Toshiba TOSNUC CNC. While sending data less then 40 lines, data passes without any error but in case more than 40 lines, few line were missing. how to resolved it. serial comm. setting baudRate- 4800...
18 Nov 2021 by k5054
Additionally to what Rick York has said, check that the flow control settings on both ends of the connection agree. There are two types of handshaking, hardware (RTS/CTS) and software (XON/XOFF). The difference is that RTS/CTS raises/lowers the...
18 Nov 2021 by Rick York
I would guess you are overflowing the machine's serial port buffer. There are a few ways you can deal with it. First is let the hardware do the work. That means you need to have a cable with the control signal lines connected appropriately on...
16 Nov 2021 by Member 3648847
I have a c++/cli project and it's a windows application. In debug mode we didn't have any problems but after taking it to release mode this error start up. I searched and found some forum-answers but couldn't help me solve this problem.Please help me ....Error :An unhandled exception...
16 Nov 2021 by dleclerc
I had this problem also, but my solution wasn't any of these. It was because I had an unmanaged class with a virtual function that returned a managed pointer. class A { virtual ManagedType^ Foo(); }; Apparently the C++/CLI runtime can't...
28 Oct 2021 by n.deny
I want to sort this array with respect to x and when i tried this,same array is shown without sort .. please help struct struct Interval { double begin, end; }; bool compareInterval(Interval i1, Interval i2) { return (i1.begin
28 Oct 2021 by n.deny
I am trying to send the (x, y) co-ordinate to a CNC machine using the SerialPort. The co-ordinates will upload by user which is around 30-200 lines. While sending the co-ordinates less than 40 lines. All the data are received on the CNC machine...
27 Oct 2021 by n.deny
I am trying to use the co-ordinate array from richtextbox and use for plot a graph in c++/cli. but i have a problem to convert cli::array^ x to const double* data.please help me. What I have tried: cli::array^ x =...
27 Oct 2021 by Luc Pattyn
I did not study all that code in any detail. The successful transmission depending on the amount of data tells me something, probably inside the receiver, can't keep up; so there would a problem either with buffering, with timing, or with...
26 Oct 2021 by OriginalGriff
We can't tell - we have no idea what your code is doing when it receives the data. So start with the basics and use Hyperterminal or similar to look at exactly what is going on, what data is being sent to the receiver. If that's correct and...
20 May 2021 by Member 15134456
Recently I am making a UI asset for Unity. I used Unity 2020.1.0f1 for making and testing primarily. I now have a project in Unity 2021.1.3f1 and I want to use my UI asset. This asset is a unitypackage and contains 3 DLLs (1 C# DLL, 2 C++/CLI...
17 May 2021 by Richard MacCutchan
See Building a Windows Forms Application in C++ environment[^]. Your project should include a source file that includes the main function.
17 May 2021 by KarstenK
Set the linker warning level to verbose to see details. It sounds like you have some misconfiguration in the Configuration Type. Check that you are producing an Application and not some dll. But the MSIL is a beast so you will spend some time...
17 May 2021 by OriginalGriff
IF you get an error you don't understand, Google it: LINK : error LNK2001: unresolved external symbol _main - Google Search[^] There are loads of suggestions there, so have a look and see what fits your exact situation. We can't see your code -...
14 Sep 2020 by gssajith87
Hi ,I am trying to Relate Volume offset with the MFT Record. Need help and suggestion on the same. This is what i am trying to do exactly., I have a Metadata File that have entry say 1's and 0's for every 4096 bytes in a volume. Now i need to find out the file name where the 1's...
12 Apr 2019 by hakz.code
Hi all,I am doing an MFC Dialog based project in which i need to take text input user,after searching on net I found this article VB Like InputBox for MFC[^] and using CInputBox class.Now the problem is I want to wait and do nothing in application till the user has entered the text,then...
12 Apr 2019 by Michael Haephrati
You have several options: 1. You can capture the text when it is entered, character after character. Then when the entered text reaches a certain size, or a certain character is pressed (i.e. "Enter"), you respond. See this article[^]. 2. You can add a button next to the text box, which is...
25 Mar 2019 by kadvanimayur
i want to make small application that will redirect the particular url to another url when my application is running on that pc..e.gif i type http://www.yahoo.comthen browser should go to http://www.google.com.i find a lot but didn't get appropriate answer.vc++.net and vc++ both...
14 May 2018 by AshishVishwakarma
This book has MINIX operating system implementation given. Operating Systems Design and Implementation by Andrew S Tanenbaum https://www.amazon.com/Operating-Systems-Design-Implementation-3rd/dp/0131429388
28 Sep 2017 by Paramu1973
Hi, When I try to generate the rdlc report with enbedded manner, its giving error...But When I check it from a Local Path it's working good. Only for embedded report it's giving error... Any ideas for me?Thanks01. When I check the report1.rdlc properties, Content = False ...Is it...
28 Sep 2017 by DEW777
Paramu1973, I know this is an "old" question but can you share your C++ code on it? I'm working with trying to run RDLC report in my project and your code seems closer than mine so I'd like to see what and how you did it? Thanks! DEW
4 Apr 2017 by Abhineet Ayan Verma
Major calling conventions for Win32 and best suited functions
18 Mar 2017 by Member 12063993
How can I initialize dialog based MFC application (i.e. implicitly call MFC application InitInstance() method) when any test method defined in MFC application is called from .NET client via C++/CLI. I have dialog based MFC application and I am able to successfully call test method defined in...
18 Mar 2017 by KarstenK
You dont have to call InitInstance explicit, but some initialize code for starting up the MFC runtime with AfxWinInit. In both link are interesting code snippets which should solve your issue.To open a dialog:CMyDialog dlg;dlg.DoModal();
6 Feb 2017 by Member 11320435
I'm trying to implement my own dispatch queue to dispatch tasks in the same order they are added to a queue. The motivation for this is due to the lack of C++/CX support for dispatch queues for Windows runtime components. (https://msdn.microsoft.com/en-us/library/hh771042.aspx) is the...
5 Feb 2017 by Jon McKee
Examining some topics that often cause confusion in C++/CLI.
18 Jan 2017 by Doug Langston
A Visual Studio 2015 project that shows one way to pass information between Windows Forms
13 Jan 2017 by Prakash1206
i referred this, wrote almost same code but in different langauge, its not working as expected!i'm using winform(C++/Cli) as host & 'WPF User Control Libaray'(C#) as a child control.integrated WPF user control(PictureBox) in winforms using ElementHost component in Winform.Basically i...
13 Jan 2017 by KarstenK
The loading of an image isnt so short handed. Take a look at this documentation or other example code.
12 Jan 2017 by Espen Harlinn
I’m taking C++/CLI for a spin, and I’ve run into an annoying warning:JNIEnvWrapper.obj : warning LNK4248: unresolved typeref token (0100000C) for '_jmethodID'; image may not runJNIEnvWrapper.obj : warning LNK4248: unresolved typeref token (0100000D) for '_jfieldID'; image may not...
12 Jan 2017 by Member 2001915
edit jni.h file chang frome "struct _jfieldID" to "struct _jfieldID {}"
1 Jan 2017 by Dreamer_X
i code with C++i want to know which is the best for GUI Desktop application : Qt or Visual Studio?What I have tried:i code with C/C++ and for web Python(Django)i tried at school C#
1 Jan 2017 by VISWESWARAN1998
Well you have to decide it on your own, I'll explain the advantages and dis-advantages Qt :Advantages: 1. Qt has its own designer and designing a good GUI with the GUI designer available with Qt designer is fairly simple with the help of spacers, buttons, html editor etc., 2....
31 Dec 2016 by Dave Kreskowiak
There is no "best". It's a matter of preference. Try them both out and make your own decision.
9 Dec 2016 by Midi_Mick
In C#, I use the System.:Runtime::InteropServices::Marshal class to do this, and it works well. I would imagine in C++, it would be something likecSetup = Marshal::GetObjectFromIUnknown(IntPtr(pSetup));This will properly marshal the pointer into the .NET interop, and set the refcount...
9 Dec 2016 by SuperMiQi
Hello Everyone,I have the following questions to ask:How to cast/marshal a LPDISPATCH to System::Object^ ?LPDISPATCH pSetup)System::Object^ cSetup = nullptr;cSetup = (casting / marshalling) pSetup;Do I have to use the namespace System::Runtime::InteropServices ?Does...
9 Dec 2016 by KarstenK
At first you better use dynamic_cast for type checking.But I think casting a COM object interface to a GC object is not correct. You should handle the original (COM) object as LPDISPATCH and dont cast around. ;-)
30 Oct 2016 by Shao Voon Wong
Prototype SIMD vectorized code effortlessly.
19 Aug 2016 by Member 11472457
Hi,I'm using an aga.controls.treeviewadv component. I haven' t used it before. I have added a NodeCheckBox to the treeView nodeControls, but the check box is not selected when clicking. I set the NodeCheckBox control DataPropertyName to the name of System.Windows.Forms.CheckState property on...
19 Aug 2016 by KarstenK
There a different bugs possible. One is that the controls is that some other controls is above your checkbox, or mouse input in the box is disabled or is routed to some other control like connected to another control. Maybe some typo.The easiest solution is most to delete the checkbox and...
27 Jul 2016 by naecotor
Hi everybody,Here is my question. I have a native project with many headers and class that i try to wrap using c++/cli in order to have a dll that i could reference in my c# project.In some moment i only have headers file (without the corresponding class) that contains only mathematical...
27 Jul 2016 by naecotor
Hi Karstenk,Thanks for your reply. My idea is build a C++/CLI wrapper. I try something some hours ago that it seems work without having to rewrite all declarations in c#.Here is the "possible" solution i wrote (i don't know if is correct).So what i did is the following :For my native...
27 Jul 2016 by KarstenK
You cant avoid the work to write all declarations in C#. Take a look at my article Calling all Stations.The point is to declare the C functions as undecorated.
26 Jul 2016 by Yochai Timmer
Debugging C++ projects in release. Finding the lost object information
19 Jul 2016 by Christian Koberg
Console output, general applicable to all executables on a Windows system
4 Jul 2016 by Prakash1206
I am using andriod app (IP webcam) as ip camera. i'm running below code in separate thread. because if i run in main thread it crashes the program. VideoCapture cap; Mat img; cap.open("http://192.168.0.101:8080/video?x.mjpeg"); while(waitKey(33)!=27) { try{ ...
4 Jul 2016 by KarstenK
If you read and understand the error message it told you the truth: you worked on barbaged memory.Such textes are the golden trail for finding the problems. Learn to Google after such error textes!!!You cant "restart" a thread, because it is a "Zombie". Free the objects and reate new...
3 Jul 2016 by Prakash1206
I'm new to Dock Panel suiteBasically i'm having run time error when it comes to loading layout from xml file. saving layout works fine.I have 2 forms, 1st one is main form. 2nd form is child formpublic ref class MyForm2 : DockContent //2nd form (child form)in main form, i have following...
3 Jul 2016 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null -...
22 Jun 2016 by NILADRI SEN
Well, I am intended to apply Marshalling between managed and unmanaged codes. That is, to retrieve the result from a c++ code to c# code. I am not intended to know the definition about managed and unmanaged code here, rather am willing to find the proper way out of doing so.Section:...
22 Jun 2016 by Sergey Alexandrovich Kryukov
What you do makes no sense at all.It would make sense if you used C++ targeted to unmanaged code. Then you would use P/Invoke to call unamanged functions.But you are using C++/CLI, which I could spot by gcnew :-). Most likely, your C++/CLI project is a mixed-mode project (managed +...
11 Jun 2016 by harishkharvi
i want to know how to concatenate two string (Eg: str1 & str2)
12 Apr 2016 by Member 10185036
I need to access my C++ API via CLR method from C# application.C++ method:int CreateEntity(double* Points);Equivalent CLR wrapper method: int CreateEntity(double% Points); I need to fill a number of doubles in C# app and pass it CLR method. A list of doubles from a XML sample...
12 Apr 2016 by Richard MacCutchan
See Passing Arrays Using ref and out (C#)[^].
24 Mar 2016 by Member 12311158
I have an API ( containing DLLs , libs, and Headers) ( in C++ /MFC)I cannot access the source code.I am trying to wrap those header files with C++/CLI to use them later in C#. It tells me DWORD / BYTE /BOOL … not defined It also shows me this error : IntelliSense :...
24 Mar 2016 by KarstenK
The windows.h error is typical and correct (in bigger abstract sense), so you shouldnt or cant use this header. You need to include the needed headers in an other manner, or define some values yourself.My advice: Make a wrapper dll without ANY external MFC class in its interfaces and link...
21 Mar 2016 by farhad Najib
Floppy = CreateFile("\\\\.\\A:", GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL );if( hFloppy != INVALID_HANDLE_VALUE ){ bRes = DeviceIoControl( hFloppy, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dummy, NULL ); if(...
21 Mar 2016 by ameyakoshti
Hello I am doing computer engineering and i needed some guidanceregarding my project.1st of all i want to know whether it is possible to disable usb portsand CD rom "POWER" through VC++.If yes then could you please guide me on it?Thanks
6 Feb 2016 by Philippe Mori
As you are already using a background worker, the easiest way to fix the problem would be to use it properly!private: System::Void backgroundWorker1_DoWork_1( System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) { while (true) { int data =...
3 Feb 2016 by Sergey Alexandrovich Kryukov
It's way to easy to blame Microsoft in all sins, including your own. At the same time, the exception message is crystal clear and explains what you did wrong: tried to works with some object in some non-UI thread, but this object is part of UI and was created and added to UI in a UI thread. This...
3 Feb 2016 by Member 10657083
I seem to be having an issue where my program forces an error.http://puu.sh/mUq0l/600ed167c1.pngI am not certain to how to fix it as I only have experience with the standard multi threading in C++.[code]void setText(int data) { pingOutbox->Text =...
30 Jan 2016 by Dave Kreskowiak
Don't use the C methods of manipulating files. Use the .NET System.IO classes instead.