Click here to Skip to main content
15,887,683 members
Everything / Programming Languages / VC++

VC++

VC++

Great Reads

by Naveen
How local static variable is implemented in VC++
by Paolo Messina
Class library to make development of resizable windows a easier for the MFC developer and pleasant for the user
by Marc Richarme
Could be used to create a Visual C++ like search combo for CHtmlViews... With the update, you can highlight all matching words!
by The Ænema
This article brings you a very detailed but easy to learn experience on creating your own x64 PE packer/protector using only VC++!

Latest Articles

by Paolo Messina
Class library to make development of resizable windows a easier for the MFC developer and pleasant for the user
by David 'dex' Schwartz
Old style printf format strings ported to an ostream shim class
by The Ænema
This article brings you a very detailed but easy to learn experience on creating your own x64 PE packer/protector using only VC++!
by The Ænema
Learn how to convert any code to a stable shellcode using Visual Studio 2019 and VC++ in easy steps!

All Articles

Sort by Score

VC++ 

13 Jan 2016 by CPallini
Quote:Msg_t *new_node[10];The above line create an array of 10 pointers. Fine.Quote:new_node[0]->message_id = ...In order to make the above line work, new_node[0] must point to a valid Msg_t instance while it is pointing to garbage.You have to write something likenew_node[0] = new...
4 Mar 2019 by Richard MacCutchan
The server is sending all the data in a single transmission, so there is no more work for it to do. The client needs to build the file by writing each block to disk as it receives it. The only problem for you is that the client has no way of knowing when all the data has been received. You need...
7 Sep 2020 by Michael Haephrati
To convert an Integer into a CString, the best way would be: CString MyString; int MyInt; MyString.Format(L"%d",MyInt); Another way is to use the std library's to_wstring[^], and then cast the result to CString. In that case, your code will...
13 Feb 2016 by CPallini
As Richard pointed out, if you want to do socket programming then you have to use IP addresses (or hostnames, and anyway, you haven't to worry about the IP address assigned to your own ethernet card). In order to start with socket programming you have to read the f#*?+° (fantastic)...
25 Feb 2016 by Jochen Arndt
CArchive is not intended to read common text files. It is used to save and store a binary representation of the data used by your application (commonly the data hold by your CDocument class). If you use the CArchive string functions, they will use Unicode strings with Unicode builds and...
4 Apr 2016 by Jochen Arndt
Really VC 5? For which Windows version?Since Windows NT normal applications have no direct access to hardware. You always need a driver.Because parallel ports are outdated, it is difficult to find still working examples. But this site may be a good starting point: Jan Axelson's Lakeview...
6 Apr 2016 by Jochen Arndt
The rightmost parameters are for the source which is probably the original (not zoomed image). So you have to calculate the destination parameters (the left most ones).To support zoom in/out you must track the actual zoom factor in a variable that is initialised with 1. Then adjust this upon...
27 Feb 2017 by Jochen Arndt
You tagged your question with MFC. Then precompiled headers are used by default which requires including stdafx.h.So I guess that you forgot to include stdafx.h in your source file. Then stdafx.h very likely includes atlbase.h already (directly with an include statement or indirectly by...
24 Mar 2017 by Jochen Arndt
There is no simple solution to get the list of startup programs because there are multiple locations where startup programs are defined.But you can retrieve a list using WMI or PowerShell. So the simplest solution would be executing those as command line processes, redirecting the output to...
17 May 2017 by Jochen Arndt
Check line 88 in the file winocc.cpp (it is usually installed with VS) to know at which function the assertion occurrs. If it is the function CWnd::GetDlgItem(), you have called it from a CWnd derived class while the window is not yet created. If it is the CWnd::EnableWindow() function, there...
15 Dec 2017 by Jochen Arndt
Full code line in header: GenericValue& SetInt(int i) { this->~GenericValue(); new (this) GenericValue(i); return *this; } The technique is called "placement new". It seems to be a Visual Studio problem: Make DEBUG_NEW work with placement new – Visual Studio[^]: If DEBUG_NEW is defined in...
21 May 2018 by Maciej Los
Follow this: C++: Convert base64 string into Image[^]
30 Jan 2019 by Stefan_Lang
There are several problem I see with your code. 1. Your variable, command_header, is not initialized completely: only the command is assigned, but you never fill its DataBuffer. Did you mean to read the data from SourceFile into that buffer? If so, you need to copy it from buffer, and make sure...
18 Sep 2019 by Dave Kreskowiak
Unless you've got some kind of server running on the target machine that will retrieve the contents of memory and send it to your client, it's impossible to get the memory of a remote machine.
26 Jan 2020 by Richard MacCutchan
TCHAR is not a type, so there is nothing to convert. TCHAR is defined at compile time as either char or wchar_t depending on whether your project is set for ASCII or Unicode.
8 Feb 2020 by Richard MacCutchan
1. The Platform Toolset is used to define the various library and platform versions required to generate the correct code for the application, e.g x86, x64, Windows version etc. 2. These environment settings are used only within Visual Studio, or in a batch process where you invoke the compiler...
17 Jun 2020 by Richard MacCutchan
Most likely because the co-ordinates in the point structure are outside of the client Window. You need to convert them from screen to client co-ordinates. See the references: GetCursorPos function (winuser.h) - Win32 apps | Microsoft Docs[^] and...
7 Jan 2016 by CPallini
You know you might convert screen coordinates to client ones (or viceversa).As an alternative, you might detect when the mouse pointer 'exits' from your application window (see WM_MOUSELEAVE message[^]).
7 Jan 2016 by Sergey Alexandrovich Kryukov
You can get the position of the mouse cursor, no matter where it is. To transform the coordinates in the coordinate system of your window, you can use the screen coordinates of your window.But the problem is: what event would trigger your code? You respond to mouse events outside of your...
17 Jan 2016 by Richard MacCutchan
Yes you could, but you need to provide the code to do the lookup of the default path when it enocunters the '~' sign.
2 Feb 2016 by Dave Kreskowiak
"CodeProject" did not write the control. The person who wrote the article you got the control from wrote the control.There is a forum at the bottom of the article your got it from. Post your question there and the author should support the code he wrote.
13 Feb 2016 by Dave Kreskowiak
You obviously have no idea what a MAC address is or what it's used for.You can NOT use a MAC address to talk to a device from your application. It is a hardware address used to uniquely identify a device on a physical network segment and ensure a physical signal gets to the correct device on...
14 Feb 2016 by Richard MacCutchan
Yes it is possible, but you need to do all the work of drawing the button yourself. See owner draw button - Google Search[^].
14 Feb 2016 by CPallini
Let's see if we have one or two articles on such a topic, here at CodeProject[^].
21 Feb 2016 by Richard MacCutchan
That is because you have not added a null character to tell cout where the end of the buffer is. Try:int filesize = myfile.tellg();char *content = new char[filesize + 1]; // add space for null charactermyfile.seekg(0, ios::beg);myfile.read(content, filesize);content[filesize] =...
21 Feb 2016 by Richard MacCutchan
The problem occurs because you are reading a textfile, and as fstream processes the content it replaces CR-LF sequences with the single newline character '\n'. Thus your actual content will be shorter than the length of the file on disk. You should use the getline method to read each line of the...
3 Mar 2016 by OriginalGriff
Any of the encryption algorithms should work, provided they are implemented correctly, and the data is passed between the systems without modification. So start looking at what standard algorithms are implemented on the linux system, and see if they have equivalents implemented already for...
20 Mar 2016 by ptr_Electron
HiI am getting warning at below line in strsafe.h could you please help me to fix typedef unsigned long DWORD;Warning 1 warning C4114: same type qualifier used more than once C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\strsafe.h 56 Warning 2 warning C4091: 'typedef ' :...
23 Mar 2016 by Jochen Arndt
You are creating a CTest instance on the stack and trying to delete it aftwerwards. That will of course crash because you can only delete objects that has been allocated on the heap using new.So you would probably want to do something like this (depending on the type of the second std::pair...
14 Apr 2016 by Jochen Arndt
It is not quite clear what you are looking for but I will try to answer.If you want to make updating the list items faster, you can disable redrawing while inserting and changing items:// Disable redrawing while updating the listSetRedraw(FALSE);// Add or update items...
26 Apr 2016 by Jochen Arndt
This has been asked and answered multiple times. It is just a question of finding the correct search term. I used "c++ parse ip string" and got a lot of useful results:C++ how to convert ip address to bytes? - Stack Overflow[^]c - parsing ip adress string in 4 single bytes - Stack...
26 Apr 2016 by CPallini
There are several ways to accomplish such a task. You can, for instance, use the Tokenize[^] method to extract all (the string representations of) the octects ant then convert each string to the corresponding byte (e.g. using itoa[^]).
9 May 2016 by OriginalGriff
The return value is 0 when an error has occurred: WriteFile function (Windows)[^] - you then use the GetLastError function (Windows)[^] to get the error code which will tell you why it happened.I would expect that value to be 0x27 or 0x70, but not the return value from WriteFile.
9 May 2016 by Richard MacCutchan
You should satart by studying the documentation for WriteFile function (Windows)[^].
18 May 2016 by Richard MacCutchan
See the explanation of how to use these options at Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE (Windows)[^].
18 May 2016 by Richard MacCutchan
Most likely because you are using ListView states rather than TreeView ones. See Tree-View Control Item States (Windows)[^] for the correct values.
24 May 2016 by Richard MacCutchan
That is not going to work; as soon as you process a WM_PAINT message, then whatever you have put to the screen will be cleared or overwritten. You should save the information you want to display, and call the InvalidateRect function[^] to force a repaint of your window. Then in your WM_PAINT...
30 May 2016 by Richard MacCutchan
The server needs to build a table containing the client IP addresses. Then when a client sends a message, the server passes it on to every client in the table.
2 Jun 2016 by Richard MacCutchan
I already responded to this question at How do I restore window position and size?[^]. Please do not repost.
8 Jun 2016 by CPallini
See I want to add/remove ES_PASSWORD(CEdit) style, dynamically.[^].
8 Jun 2016 by Richard MacCutchan
See also EM_SETPASSWORDCHAR message (Windows)[^].
14 Nov 2016 by Richard MacCutchan
Two days wasted doing what? It is clearly described at Static Control (Windows)[^].
19 Feb 2017 by Richard MacCutchan
See C-language Interface Specification for SQLite[^].
26 Feb 2017 by Jochen Arndt
When you create a new MFC project there will be a call to SetRegistryKey() placed at InitInstance. Change the string to your company name. This will use the registry instead of INI files for profile settings. The used registry path will be HKCU\Software\\.Then...
28 Feb 2017 by CPallini
In order to write, you may either use a loop, calling at each iteration SetWORDValue or SetQWORDValue (as appropriate) or, without the loop, calling just one time SetBinaryValue (see CRegKey Class[^]).You may read back the data in a similar way.You might also have a look at one (or more)...
28 Feb 2017 by Jochen Arndt
It would be good to know what is not working.First, read the documentation of the used functions.Then check the return value of each function call and report the error code (at least in debug builds to be detected during development):LONG err = reg.Create(m_hKeyParent,m_myKey);if...
9 Mar 2017 by Jochen Arndt
You are creating a modeless dialog. In this case you must track the state of that dialog. Your existing code can be used as starting point:void CMy3D_Med_ViewerDlg::OnBnClickedShowDicomTag(){ m_DCMTagDlg.Create(IDD_DICOM_Tags, this); m_DCMTagDlg.ShowWindow(SW_SHOW); ...
3 Apr 2017 by Jochen Arndt
You did not tell us what kind of runtime error occurs. A possible source of the error might be that that your calculation of the BITMAPINFOHEADER[^] biSizeImage member is wrong. See "Calculating Surface Stride" at the above link.
20 Apr 2017 by Jochen Arndt
It is common to use a typedef for such functions because it makes it easier to declare pointers. For your case see PWINBIO_CAPTURE_CALLBACK function pointer (Windows)[^]: typedef VOID ( CALLBACK *PWINBIO_CAPTURE_CALLBACK)( _In_opt_ PVOID CaptureCallbackContext, _In_ ...
23 Apr 2017 by Jochen Arndt
You have to reverse the check and the return value. See CWnd::PreTranslateMessage[^]: Quote: Nonzero if the message was translated and should not be dispatched; 0 if the message was not translated and should be dispatched. You have to return TRUE if a message should be filtered out. To check...
25 Apr 2017 by Jochen Arndt
See the documentation: DragQueryFile function (Windows)[^]. Call DragQueryFile first with iFile set to 0xFFFFFFFF. That call will return the number of file names. Then use a loop to get each file name: UINT fileCount = DragQueryFile(hDrop, 0xffffffff, NULL, 0); for (UINT i = 0; i
18 Jul 2017 by Richard MacCutchan
The compiler messages should be enough to help you. LPLVINSERTMARK* lvim =NULL; //iItem //
18 Jul 2017 by Jochen Arndt
You have to pass a pointer to an LVINSERTMARK structure (which is an LPLVINSERTMARK; the LP indicates that it is a pointer): // Structure as local variable LVINSERTMARK lvim; // [EDIT] // Must set the cbSize member lvim.cbSize = sizeof(LVINSERTMARK); // [/EDIT] // Pass the address of the...
19 Jul 2017 by Patrice T
Quote: "Expression : ("Buffer too small",0); You try to store a '/0' terminated string of size 6 in a buffer of size 6. A '/0' terminated string of size 6 is 6+1, so it is 7. Just for checking, try to use a larger buffer.
24 Jul 2017 by Jochen Arndt
You have to calculate the width according to the available width, the number of controls, and the spacing between the controls and to the borders. Assuming you have a left and right space to the borders and a space between the controls the width of a single control can be calculated as: int...
3 Aug 2017 by OriginalGriff
Look at your regex: [!/\[]:;|=,+*]* It contains the characters to start and end the "any character in this set" within the set of characters, as well as the Escape character! Try this: [!/\\[\]:;|=,+*]* But... that will match no special characters at all - try this: [!/\\[\]:;|=,+*]+ ...
5 Sep 2020 by Member 13089825
If I bring up the GUI, and then I resize and close it, when I start it up again it reverts back to the original size. it should remember the old values What I have tried: the below method will get intiate while closing GUI and it will write the size void CMainFrame::OnDestroy() { ...
5 Nov 2017 by Jochen Arndt
It looks like your bitmap IDB_BITMAP1 is monochrome while your PNG image is not. CBrush::CreatePatternBrush[^]: A brush created using a monochrome bitmap (1 color plane, 1 bit per pixel) is drawn using the current text and background colors. Pixels represented by a bit set to 0 are drawn with...
11 Dec 2017 by CPallini
Download it[^] and try (using at first a C++ Console project) to compile and run some of the examples.
21 Jan 2018 by Richard MacCutchan
This will not work because sret is a local pointer, so the calling application will still have it pointing somewhere else. You need the address of the pointer, something like: __declspec(dllexport) int Function(wchar_t* s, wchar_t** sret, int len) { int sLen = wcslen(s); *sret =...
21 Jan 2018 by CPallini
In addition to Richard solution, have a look at c++ - Is it bad practice to allocate memory in a DLL and give a pointer to it to a client app? - Stack Overflow[^]. Unfortunately mismatches between allocator and deallocator do happen and are not pleasant.
8 Feb 2018 by Dave Kreskowiak
You don't. UDP has no guarantees of delivery nor in the order that packets show up at the receiver and the possibility of duplicate packets also exists! There is NO WAY around this. If you want "reliable" data transfer, UDP is the LEAST reliable transport there is. You're going to have to use...
17 Mar 2018 by OriginalGriff
Depends: if these are the passwords that people will use to log into your application, then you should not encrypt them at all: they should be hashed instead. There is an explanation of why and what the difference is here: Password Storage: How to do it.[^] - the code is C#, but it's pretty...
20 Mar 2018 by Jochen Arndt
Besides using the correct length what is written to file depends also if your project is Unicode or not. The correct solution to write the CString content "as it is" is: fwrite(data.GetString(), sizeof(TCHAR), data.GetLength(), stream); With Unicode builds, the CString content is stored...
24 May 2018 by Jochen Arndt
A CString is a sequence of TCHAR characters. A TCHAR is a char or a wchar_t depending on the project character set setting (ANSI/multi-byte or Unicode). You can cast the pointer to the data in the CString to BYTE*: const BYTE *pByte = reinterpret_cast(str.GetString()); Note that I...
31 May 2018 by KarstenK
Important: You must build the dll in debug mode and use the TRACE macro. I know different options sorted by usability: a) in Visual Studio, set the exe in the Debug Settings as Command. This launches the app and the dlls also are debugable. b) use Debug View c) last option is to write debug...
3 Aug 2018 by Richard MacCutchan
If you draw objects outside of the function that responds to the WM_PAINT message, then it will not work. As soon as the dialog is shown it will erase the background and redraw all controls in the resource. You should add the rectangle into your resource settings.
15 Jan 2019 by MadMyche
Read through the sample on the MS website Obtaining Directory Change Notifications - Windows applications | Microsoft Docs[^]
21 Jan 2019 by OriginalGriff
Quote: This is what I get in lBytesRead in debugging "lBytesRead 44 unsigned int" So what has been read is 44 bytes out of a possible max of 50. So 44 bytes will be transferred to yoru buffer, and the remaining elements will not be affected in any way; their previous content - random according...
28 Jan 2019 by Richard MacCutchan
You do not need a struct in either case. Your command header is a single value (byte?) which you transmit on its own, followed by a character buffer read from the input file. You also need to modify your read code as you are doing things in the wrong order. It should be: typedef enum { ...
30 Jan 2019 by CPallini
Quote: int nfRet = SockConnection.Send((char*)&command_header, sizeof(command_header)); nfRet = SockConnection.Send(command_header.iDataBuffer, sizeof(command_header.iDataBuffer)); The above calls don't make sense. On my system sizeof(command_header)=8 ...
12 Apr 2019 by Michael Haephrati
You should read this article[^] to know which files are needed in general. Your "setup" can be any program you write or a 3rd party "setup creator" and you just need to make sure all the necessary files are copied during the installation process and are removed upon uninstallation. See also:...
23 May 2019 by Richard MacCutchan
You should do all your painting/drawing to the screen in the function that handles the WM_PAINT message. Each time this function is called it should redraw all the shapes. When a shape is deleted you just remove it from the list of items to draw, and then call InvalidateRect to force a repaint...
3 Jul 2019 by CPallini
Have a look at this code samples: MFC Sockets[^]. Have also a look at this CodePrject article: Sending & Receiving UDP Datagrams with MFC's CAsyncSocket C++ Class[^].
13 Jul 2019 by Richard MacCutchan
See CListBox Class | Microsoft Docs[^].
21 Jul 2019 by OriginalGriff
Fill is a "blocking call" - it doesn't return until the DB has assembled all information and returned it to your application (or the SQL timeout expires, whichever happens first). So if your stored procedure takes a long time, you can't do anything else on that thread - including use the...
16 Sep 2019 by Richard MacCutchan
It is all described at Hooks Overview - Windows applications | Microsoft Docs[^].
26 Sep 2019 by CPallini
A quick and dirty search result: TIP: Adding a typelibrary as a resource to a project[^].
20 Dec 2019 by Richard MacCutchan
It is a reasonable guess that your application needs much more testing before release. The first thing you need to do is to find out where the failures occur, and what causes them. Adding some decent exception handling and logging would possibly help. In terms of your list of things you have...
27 Jan 2020 by CPallini
Quote: i have a string value and i want to convert string value to TCHAR value. A string is a sequence of characters, while TCHAR is a single character (either char or wchar_t as already pointed out by Richard), so you cannot convert. As a wild guess, I suppose you need to convert from a string...
30 Sep 2020 by OriginalGriff
We can't tell you exactly what string to use - we have no access to your system, the network it's relying on, or the server instance you wish to connect to; you need all those to even begin assembling a connection string. Have a look here:...
30 Sep 2020 by Richard MacCutchan
Take a look at ConnectionStrings.com - Forgot that connection string? Get it here![^].
30 Sep 2020 by Maciej Los
Start by reading MSDN documentation: Database Support, MFC Application Wizard | Microsoft Docs[^] You've got 2 options to connect to your sql server instance, via: OleDb or ODBC. A proper connection string for Microsoft ODBC driver: ...
30 Aug 2021 by Maciej Los
As per documentation, a ListObject.Add function requires to define a sheet in which the list is added. For example: Set objListObject = ActiveWorkbook.Worksheets(1).ListObjects.Add(SourceType:= xlSrcExternal, _ Source:= Array(strServerName,...
7 Sep 2020 by Member 11490990
Hi everybody It is interesting, I could do any conversion in MFC Ver.6, But I receive compiler error on itoa! Could you please give me a sample. What I have tried: Every time I get POSIX Error and _itoa give me SECURE Error.
3 Oct 2023 by Richard Deeming
Don't post this under "quick answers" - it assumes that the author of the project will be constantly monitoring the list of questions, and recognise that the extremely vague title and description from your question relates to their code. ...
8 Apr 2009 by Naveen
How local static variable is implemented in VC++
5 Jan 2016 by narmadha_s
HI,I am working on meeting collaboration application development. In that while desktop sharing, i have to filter that specific meeting app (i.e my app WPF transparent window).I used magnification, it is working up to windows 7 (DWM disabled condtion only.)It is not supporting on...
6 Jan 2016 by Kishor-KW
When I try to ad variable to the list control on dialog box by right clicking on list control and select class wizard then select tab of Member Variable and Add variable to list control then it fire following error after click on apply button. Error hresult e_fail has been returned from a...
6 Jan 2016 by Jochen Arndt
You can try the other method described here: Adding a Member Variable[^].If this does not help do it manually by adding the variable definition to the dialog header file and map the list control to the variable in the dialog class DoDataExchange[^] function using DDX_Control.
7 Jan 2016 by Vijay533
I have a small problem, i am trying to drop some file from my application to outside of the application, here how i can get the cursor position when it goes outside of the application, i used getcursorposition, but with that coordinate i can't able to identify it is in my application or not.
8 Jan 2016 by Kishor-KW
I am implementing Project in vc++ 12 MFC. back-end is access database. I want to select all four columns values in one row into four variable.My query is:m_txt = "select CompanyName As m_CompanyName, Model As m_Model, OrderNo As m_OrderNo, StreetAddress As m_StreetAddress , Phone As...
7 Jan 2016 by Maciej Los
As i mentioned in the comment to the question, all you need to do is to concatenate string!Go back to C++ basics!On the other hand, here is a tutorial about Developing Access 2007 Solutions with Native C or C++[^]How To Invoke a Parameterized ADO Query Using VBA/C++/Java[^]More...
11 Jan 2016 by Vijay533
Is there any way can i get the path based on cursor position, what i mean suppose i open 3 folders like D:\vijay\temp, c:\system\data, E:\data\directory, if i move the cursor from my application to any of these folders, can i get the directory path?, based on cursor position. My application...
12 Jan 2016 by KarstenK
Looks like you have a similar question as I answered here.What have coded so far?
13 Jan 2016 by Kishor-KW
I want to display Logo on my document like other data which I retrieve from database are store into variable and then those are passes to print on document. I am storing path of related bitmap in database and it is also retrieve into variable I know following:hbit = (HBITMAP)...
25 May 2018 by Lekshmi KR
I am doing a simple application to define a structure and place data in tha structure to learn the concept of structures. But when trying to insert data to structure i am getting an access violation. Following is the code portions.In Test.h filetypedef struct...
13 Jan 2016 by OriginalGriff
This is a common problem and a moments thought will tell you what the problem is.Look at the address that it's complaining about: "0x00000000" - or "zero" as it's also known. How likely is it that anything you need to use is going to be located at the first possible address in memory?...
15 Jan 2016 by SandipG
Are you using CListCtrl? if Yes see visual c++ - How to detect a CListCtrl selection change? - Stack Overflow[^]
21 Jan 2016 by Revati513
Hello,We are migrating a product from VB6 to VB.NET and facing an issue. This product interacts with a function defined in VC++ component (.ocx).1. VB6 & VB.NET function call: result = TestFunc(Param1, Param2, Param3)2. VC++: a) Function definition in .CPP file: long...