Click here to Skip to main content
15,879,096 members
Everything / Programming Languages / VC++

VC++

VisualC++

Great Reads

by Eugene Balabanov
A tiny sandbox primer
by jurhas
A small simulator for a 6 axis articulated robot
by Marius Bancila
Using managed COM objects in C++ without registering the server in Windows Registry
by Petrov Vladimir
Weiler-Atherton algorithm in MFC codes demo implementation

Latest Articles

by Ștefan-Mihai MOGA
Task Manager shows you the programs, processes, and services that are currently running on your computer. You can use Task Manager to monitor your computer’s performance or to close a program that is not responding.
by Ștefan-Mihai MOGA
This article is about the IntelliFile application which is a free alternative Windows version to Total Commander and uses many components that have been published on CodeProject.
by Ștefan-Mihai MOGA
You can use IntelliPort to transfer large files from a computer onto your portable computer using a serial port rather than going through the process of setting up your portable computer on a network.
by Tough Developer
How to compile WinQEMU v0.10.2 in VS2008 and VS2012

All Articles

Sort by Score

VC++ 

2 Aug 2017 by Marius Bancila
Using managed COM objects in C++ without registering the server in Windows Registry
25 Feb 2018 by Petrov Vladimir
Weiler-Atherton algorithm in MFC codes demo implementation
19 Feb 2016 by pasztorpisti
An advice to make your DLL interface more attractive and easier-to-maintain even in cross-platform projects
30 Mar 2015 by Eugene Sadovoi
Integrating third party tools and libraries into Visual Studio (MSBuild) configuration environment.
19 May 2015 by Yohamnes Hernandez
How to free blocked files, inclusive if they are mapped in memory. Something that many tools are missing.
1 May 2017 by Arthur V. Ratz
This tip/trick introduces the basic ideas on how to avoid memory mismatched allocation/deallocation issues detected by Intel® Inspector XE for Visual Studio 2015
6 Nov 2014 by Orjan Westin
Simplifying the use of dynamically sized C structs
5 Mar 2017 by Jose A Pascoa
27 Jun 2012 by Chuck O'Toole
It is one of the oddities of Windows Naming that "SendMessage()", unlike TCP/IP "send()", is not a "fire and forget" message passing mechanism.SendMessage() is an immediate dispatch to the target window's (HWND) message handling and does not return until the message processing is complete...
16 Apr 2015 by Daniel Rose
Explanation of the different SAL annotations for function parameters for Visual Studio Code Analysis
12 Dec 2011 by jackyxinli
This article demonstrates how to use mplayer as an audio decoder and display real time spectrum during playback process
27 Jun 2012 by Albert Holguin
Messaging is the basic way within the MS framework to get information between windows (of course, you don't have to necessarily be a window to get/send a message).The two basic methods, SendMessage() and PostMessage() are similar (in prototype) but very different in behavior. SendMessage()...
27 Feb 2016 by John Jiyang Hou
A List data structure implementation in MASM Assembly with C function realloc
29 Sep 2011 by André Kraak
If there is any risk it is that the caller of the function may not delete the returned object, creating a memory leak.So document the function properly (which you should always do) and state that the caller is responsible for cleaning up the returned object.
12 Dec 2013 by Aescleal
They're synonymous - "a function pointer" and "a pointer to a function" describe an object that can hold the address of a function.
16 May 2014 by Bartlomiej Filipek
Description of my emitter and generator module for particle system
12 Jul 2016 by David A. Gray
Share Win32 string resources without the risk of conflicting resource IDs
29 Sep 2011 by Richard MacCutchan
Looking at the description of the new[^] operator, I would say you are doing it correctly. Since you are returning an object of the type that the Create() function says it will return, you will not need any casting within this code.
20 May 2012 by OriginalGriff
Windows timers generally run off the hardware timer, which has a resolution of 10 - 15ms (depending on the hardware, most run at 15.6ms intervals) so when you ask for a lower interval, you get an accuracy of 10ms in teh timer value, but a resolution of 15ms in the timer interval.There is an...
20 Jun 2012 by OriginalGriff
The break statement causes execution of the loop to end immediately:while(1==1) { xxx(); if (condition) { break; } }[edit]Typo: "1=1" instead of "1==1". Thanks johannesnestler! - OriginalGriff[/edit]
12 Dec 2013 by Stefan_Lang
Some of the truth has been revealed in Solutions 1 and 2 (please ignore 3), but one of the reasons is that this allows you to pass things that can be converted or evaluated to your class type, such as expressions, without having to provide a temporary variable yourself.class cVec...
8 Feb 2015 by tkontos
A WTL based, XML driven shortcut replacement
1 Nov 2020 by Rick York
A Handy Memory Allocation Tracking Macro and Header for Visual Studio C++ Code
17 Feb 2012 by potluri_suresh
Raw Audio data is encoded to AMR-NB audio using opencore-amr library
2 May 2012 by Itai Basel
A macro that gets current function's return type on visual C++
17 May 2012 by Pablo Aliskevicius
This behavior is by design ;)It has something to do with allowing the user to drag things from one application and drop them on another.There are other mouse messages that may do the trick for you. You may start here:WM_MOUSEMOVE[^]; you can check the flag MK_LBUTTON and see when it is...
13 Jun 2012 by Aescleal
htons() is your friend. And portable. It converts from the byte order of the host to a a network formatted short.There's an htonl if you ever need to do the same thing with 32 bit data.
13 Jun 2012 by Niklas L
When transmitting data over a network, you should use host-to-net functions to make sure you always send it in a systematic way. Look here htons()[^] and here ntohs()[^] to get it back again.
13 Jun 2012 by Aescleal
You're doing pointer manipulation on pointers to dynamically allocated memory. This has a couple of effects: - you're orphaning blocks of memory - you couldn't free R1, even if you wanted to - as Albert said you're overrunning an array somewhere. You're not assigning xa anywhere for one...
14 Jun 2012 by Espen Harlinn
Have a look at:Dialog Painting in MFC[^] - this shows how trigger the paint event for your dialog.This shows how to do the drawing:GDI Circle-Based Shapes[^] - see the "Pies" example.Best regardsEspen Harlinn
3 Jul 2012 by OriginalGriff
Why are you assigning a new, empty CString to the buffer and then reading into it?CString* databuf; //buffer to hold the data from the file.databuf = NULL;databuf = new CString;...int iRead = my_file.Read((void*)databuf, my_file.GetLength());//error hereSurely, assigning a buffer...
3 Jul 2012 by barneyman
you're using CString incorrectlyIt does not represent an object with a buffer that you can scribble into ...change it tochar *databuf=new char[my_file.GetLength()];inside the .Open clauseand make sure you delete it on the way out
5 Jul 2012 by Eugen Podsypalnikov
// How to load jpeg and bmp both type of images in Visual c++ 6 in MFC dialog based application?Try CImage::Load(..)[^] :)
8 Jul 2012 by Jochen Arndt
You may connect a 'DVI Dummy' (Google for it) that simulates a monitor to be attached to the graphics card.For a VGA port see this VGA Dummy[^] solution.You may also try ZoneScreen which is designed to extend desktops over network connections. It contains a virtual graphics card with...
11 Jul 2012 by Richard MacCutchan
You seem to be confused about what binary data actually is. If you read a PDF as a byte array and store it in the database, then you must retrieve it in exactly the same way (and write it as such to any new file). Converting it into a string just destroys the structure so it becomes unreadable...
17 Sep 2012 by Kuthuparakkal
Follow:Win32 Thread Pool[^]Also MS way:http://msdn.microsoft.com/en-us/magazine/hh335066.aspx[^]
17 Sep 2012 by Espen Harlinn
As of Vista, Windows has built in support for thread pools. Take a look at CreateThreadpool[^]Best regardsEspen Harlinn
20 Dec 2012 by CPallini
In a C++ program using MFC you may use either the Windows API function MessageBox[^] or the MFC method CWnd::MessageBox[^].The former takes four parameters, the latter may take three, two or just one parameter (because it has two optional parameters). In your dialog application you are...
26 Mar 2013 by nv3
Instead of painting directly to your control you could create an equally sized memory DC and bitmap and paint into that. Then, when ready, just bitblt the currently visible part to the DC of the control. That has several advantages:- drawing to a memory bitmap is faster than drawing to the...
8 Apr 2013 by Steve44
I think this will not work the way you tried it, using set within the cmd.exe shell, the change will not be globally visible.Try the setx.exe command, this will provide a change of the environment variable that is available to other processes.See...
2 May 2013 by Jochen Arndt
See GetErrorInfo[^] in the MSDN:Quote:Obtains the error information pointer set by the previous call to SetErrorInfo in the current logical thread.If you got the return valueQuote:S_FALSE There was no error object to return. , no error info has been set by a COM function which is obvious...
18 Jun 2013 by Jochen Arndt
You are reading a single character (byte) into Buff. So you can't pass Buff where a NULL terminated string parameter is expected without appending the NULL terminator. Your code snippet indicates also that you are using a Unicode build. So the characters read from the serial port must be...
8 Jul 2013 by pasztorpisti
To be honest I haven't checked out all your code just check out what synchronization primitives are you using in coda_concorr and that is already suspicious. The same is true for your thread funcs that use ugly lockings and antipaterns like "try". You are not using the right synchronization...
8 Sep 2013 by pasztorpisti
This is a function pointer declaration. typedef void (*_PVFV)(void); defines _PVFV as a function pointer type. The __cdecl keyword is there to define the calling convention of the function to use C calling convention[^].
26 Jun 2014 by zdf
A solution for conversion of a non-undoable application to an undoable one.
17 Sep 2014 by BlueMaple_chief
To make a simple auto updater demo, I use webclient 'interfaces' to download the file and monitor the progress.
30 Nov 2014 by David O'Neil
I needed an 'Update' solution for a project, and modified Geert van Horrik's 'Updater' to do so. This is the solution in Visual Studio Community Edition
2 Feb 2015 by Sergey Alexandrovich Kryukov
Unfortunately, you created dependency on the Visual Studio specific libraries. First thing you did wrong is: you created an application in Debug configuration (I can see it from the DLL name) and deployed it. You should not do it; always build Release configuration to deploy. Please...
7 Mar 2015 by OriginalGriff
Yes.A const char* can't be converted to a char* because it would open up the possiblity of changing the value of constants: in this case potentially changing (say) a user prompt from "hello user!" to "HeLlO UsEr!" and making the fixed prompt change half way through the program.If you need to...
15 Apr 2015 by D4rkTrick
Get manifest support with VC6
26 Jul 2015 by Afzaal Ahmad Zeeshan
Read my comment to the question, continuing from there. Remember, constructors are also functions. So, when you create a custom constructor logic you are basically trying to set up the underlying objects. If they are exposed to some errors and would work in a condition only, then yes. You need...
26 Jul 2015 by Sergey Alexandrovich Kryukov
In addition to Solution 1: The answer could be more certain: yes and no. :-)First of all, from your question, it is not clear what you are talking about. You are talking about handling exceptions, and in other place you are talking about throwing. Let's discuss throwing first.Of course,...
24 Jan 2016 by nv3
I think you are confusing a few things here.DeclarationIn a declaration you just tell the compiler what the data type of a member, variable or function is, or which members and functions a class consists of. For example: int i; void MyFunction (int i, double d); class...
1 Nov 2021 by Michael Haephrati
I stumbled upon this question while trying to understand why I get gibberish text when I convert PDF files into text, as part of this [^] project. This question is still relevant today, and there is no real answer. An ideal answer would be the...
18 Sep 2022 by Mikhail Semenov
This article proposes a mapping algorithm, called Segmented Map, which is almost as fast as Flat Map is random access and enumeration of elements and close to std::map in insertion of elements.
24 May 2015 by JPhelps
Using CFolderPickerDialog
13 Jun 2011 by TRK3
The problem probably isn't in the code you posted. It's probably in how/when you are calling it. I would suspect that the printer hdc may not point to what you think it's pointing to at the time you call your routine.You don't say what the error is that you are getting. (That...
10 Jul 2011 by Ashish Tyagi 40
I guess you already have that list of blocked sites and you are writing code for block them and redirect to your default redirecting site.. It is a very basic functionality of a standard firewall... Well for blocking or allowing any site requested from the browser you must capture those...
26 Jul 2011 by Eugen Podsypalnikov
Some parent could close its children members as well... :)/*afx_msg for WM_CLOSE*/void CParentDlg::OnClose(){ // CChildDlg CParentDlg::m_cChildAlert if (m_cChildAlert.GetSafeHwnd()) { m_cChildAlert.SendMessage(WM_COMMAND, IDCANCEL); } CDialog::OnClose();}
11 Oct 2011 by André Kraak
Building on Mehdi solution.If you indeed have a memory leak have a look at this on Visual Leak Detector - Enhanced Memory Leak Detection for Visual C++[^] how to solve it.
7 Jan 2012 by ThatsAlok
Simple tip and trick for Mail Slot
22 Jan 2012 by Espen Harlinn
Now it is mandatory to install the same * application to a windows XP computer without the service pack 2 installed and it seems that I can't install that service pack there.I'd try to convince the customer to upgrade XP to service pack 3. MS has made a serious effort when it comes to...
1 Feb 2012 by Espen Harlinn
My advice would be to move it to VS2010.Start out by planning - it just might be that you would like to refactor some of your code, and if you're moving the code to a more modern version of C++, you should proably think things through.Before you start, there are a few libraries that I...
24 Feb 2012 by Chandrakantt
You can find LSP sample in windows SDK at location "(Drive Letter)\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp" if you have 7.1 Microsoft SDK. If you have Vista SDK then it will be at location "(Drive Letter)\Program Files\Microsoft...
11 Apr 2012 by Sergey Alexandrovich Kryukov
The path "c:\projects\my_app\.\Debug" is perfectly legal and is equivalent to "c:\projects\my_app\Debug".Try the following commands:cd c:\projects\my_app\.\Debugand cd c:\projects\my_app\DebugYou will see that they change working directory to the same place, if the path exists.If...
30 Apr 2012 by OriginalGriff
That is because strtok matches any of the characters as delimiters, rather than all of them: http://www.cplusplus.com/reference/clibrary/cstring/strtok/[^]Have a look at strstr instead: http://www.cplusplus.com/reference/clibrary/cstring/strstr/[^] - you will have to call it repeatedly, but...
4 Jun 2012 by Richard MacCutchan
You can start by reading the documentation for the CDialog[^] class, which will give you the basics. Then try the CodeProject articles[^] for lots of useful samples.
20 Jun 2012 by Sergey Alexandrovich Kryukov
I hope this CodeProject article can help you:Serial library for C++[^].Basically, you need to use the class CSerial. Do you use it? This CodeGuru article provides a short overview of its...
20 Jun 2012 by Jochen Arndt
A serial port can be opened by only one thread/application at time. So an attempt to open COM1 by your write application will fail if the port is already opened by the read application. It is always good practice to check the return value of CreateFile() for INVALID_HANDLE_VALUE and call...
26 Jun 2012 by Espen Harlinn
Multi column listbox is not what you want:Item1 Item4 Item7item2 Item5Item3 Item6Try using a CListCtrl[^] or perhaps the MFC Grid control 2.27[^]Best regardsEspen Harlinn
4 Jul 2012 by Code-o-mat
Call UpdateData only from the same thread that created the dialog and its controls (the GUI thread), not from any worker threads. If you want to update your dialog regularly, either use a timer (SetTimer[^]/CWnd::SetTimer[^]) or send/post (SendMessage[^]/PostMessage[^]) messages towards your...
9 Jul 2012 by shankha2010
Hi All, I want to extract some data from a flash website by OCR[Optical Character Recognition] programmatically.By taking Internet explorer handle and navigating to apage and taking screenshot of it.Everything went fine until I scheduled it in a server that have no monitor.Any Idea...
24 Jul 2012 by Jochen Arndt
Your code fails because there are two versions of the function: An ANSI version and an Unicode version. According to the Unicode setting, you must pass 'GetVolumePathNamesForVolumeNameA' or 'GetVolumePathNamesForVolumeNameW' to GetProcAddress().
1 Oct 2012 by Richard MacCutchan
You seem to be struggling with some of the basic concepts here and getting a bit confused about what needs to be done. There is no need to keep copying data from one place to another just so you can write it out. Try something like:char szDateTime[12];int recordLength = 138; // this...
17 Oct 2012 by Quirkafleeg
Hello there.Simple answer is no - you can't add an xml file to the windows registry... at least not in the way you are thinking.What you can do is add the xml file content to the registry, as a string value. For such a task, using RegSetValueEx is the way to go:1) Read the content of your...
4 Feb 2013 by CPallini
If you need to change the content of a file (that is overwrite it) then you have to:Read the file content into memory.Modify memory content.Write back modified memory content to the original file.You may use the C++ fstream to read/write a binary file, see, for instance Input/Output with...
12 Feb 2013 by Albert Holguin
I place GUIs in dlls all the time... you just have to set the resources handle correctly when you create the windows within the dll and everything else pretty much works the same.Here's some...
11 Mar 2013 by Prasad_Kulkarni
Try this:#include #include "boost/date_time/gregorian/gregorian.hpp"namespace bdt = boost::gregorian;int main(void){ bdt::date today(bdt::date(2010, bdt::Jun, 13)); bdt::date electionDay(bdt::date(2010, bdt::Nov, 2)); bdt::date_period range(today,...
26 Mar 2013 by Sergey Alexandrovich Kryukov
The technique of elimination flicker is called "double buffering".Please see this CodeProject article: Flicker Free Drawing In MFC[^].See...
3 Apr 2013 by Sergey Alexandrovich Kryukov
You can do it, if you use the process handle returned by each ShellExecute; then you can use the function WaitForMultipleObjects:http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025%28v=vs.85%29.aspx[^].This function call will be a blocking call. Your calling thread would be...
11 Apr 2013 by CPallini
The following code typedef long int int32_t;typedef int32_t cell;#include cell foo(){ int xz; xz = 150; return xz;}int main(){ printf("%ld\n", (long)foo()); /* long int ! */ return 0;}outputs: 150
12 Apr 2013 by Jochen Arndt
I did not see the source for the heap error but you also asked for the right or simpler way. At first you should know that the HTML clipboard format must contain UTF-8 encoded text. So the input text must be converted to UTF-8 and prefixed with the HTML format header. A snippet from one of my...
23 Apr 2013 by CPallini
Such a string does not represent 'weird characters', in my opinion (it represents the following character sequence "000T102 000").You have to: convert the string into an array of unsigned chars (each ordered pair of characters of your string represent an unsigned char)write the unsigned char...
2 May 2013 by Ian A Davidson
http://msdn.microsoft.com/en-us/library/t8xe60cf(v=vs.80).aspx[^]
13 May 2013 by H.Brydon
The week number comes from the %W spec. For example: CString sDir = COleDateTime::GetCurrentTime().Format( "\\%Y\\%W" ); [without looking] I think you will get further information if you look at the help for strftime().
14 May 2013 by Ian A Davidson
Of course, looking at my WHS diary, I realised that the first of January is not always in week 1, but is sometimes week 52/53 of the previous year, and also the last few days of December may be counted as the first week in the next year.Thus all the solutions given so far, while some of them...
11 Jun 2013 by Maximilien
you can use _makepath[^].
19 Jun 2013 by JackDingler
Most of it can be done in OpenGL.Loading and saving images isn't an OpenGL function though.To do this you need to load the bitmap into memory.Create a destination bitmap in memory.Set Open GL to render to your destination bitmap.Apply the original bitmap as a texture to a square...
2 Jul 2013 by Ron Beyer
Part of your problem is here: int num=0; s=new students[num];you are creating a new array of students that's zero elements long. So every time you advance the pointer you are corrupting memory. You need to allocate as many elements as you are going to use, or use some sort...
28 Jul 2013 by pasztorpisti
My opinion is that using simple stupid and open formats is the better choice. The binary closed office only document format would be my last choice if I have other better choices. The binary format also has the disadvantage that even different office versions display it differently in contrast...
31 Jul 2013 by shailesh91082
This article explains how to implement Common Versioning Mechanism which helps in easy maintenance of product
16 Aug 2013 by pasztorpisti
This is basically a NULL pointer exception. Its 0x10 and not zero because you are using the NULL pointer as a pointer to a struct/class and you are trying to access a member of that struct/class that is on offset 0x10 inside the struct/class. Still it is a NULL pointer "exception".The bug is...
17 Sep 2013 by Philippe Mori
Since POD struct can be copied directly, why not uses the simpler code:UESim.S = *SE;This is generally safer to write the code that way as you don't have to bother to know if the structure is bitwise copyable as the compiler will do the proper thing (bitwise copy for any member that do...
15 Oct 2013 by User 59241
ExitThread is the preferred method of exiting a thread in C code. However, in C++ code, the thread is exited before any destructors can be called or any other automatic cleanup can be performed. Therefore, in C++ code, you should return from your thread function.From msdn:TerminateThread...
6 Nov 2013 by Bill_Hallahan
You can have the launched thread routine contain code that causes the thread routine to return. This will automatically cause ExitThread to be called. Your code can wait on the thread handle using the WaitForSingleObject function and when EndThread is called, WaitForSingleObject will unblock. ...
23 Oct 2013 by Captain Price
Yes it is possible to declare constructors as private. When you declare the constructor as private, you cannot directly instantiate the class from outside. And from only the inside of the class you can create an object of itself. You use static functions for this.Some examples: 1....
27 Nov 2013 by User 59241
It is always easier if you post your own code. This is straight out of the documentation:cv::Mat img = cv::imread("lenna.png", 0);if(img.at(y,x) == 255)etchttp://docs.opencv.org/doc/user_guide/ug_mat.html[^]