Tag Archives: MFC

How to Solve Microsoft.CppCommon.targets(279,5): error MSB3073

1>*** PARSE FAILURE ***
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(279,5): error MSB3073: The command "@echo off
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(279,5): error MSB3073: setlocal...

There is no problem with local compilation, and the compilation server reports an error.

The reason is the problem of GIT line feed in Windows system. The carriage return line feed in the project is modified in the vcxproj obtained by git, resulting in the script error in vcxproj.

Modify the GIT line feed setting of windows system, and the problem disappears.

MFC:: error C2065: “IDD_DIALOG1”: undeclared identifier Sending and handling custom messages in MFC threads

Just add the resource header file.

#include "Resource.h"

Send message in MFC thread

1. Write the meaning first and accept it

#define WM_SET_FOCUS WM_USER+100



BEGIN_MESSAGE_MAP(CWriteSnDlg, CDialogEx)
    //
	ON_MESSAGE(WM_SET_FOCUS, OnSetFocus)
END_MESSAGE_MAP()



	afx_msg LRESULT OnSetFocus(WPARAM wP, LPARAM lp);


LRESULT CWriteSnDlg::OnSetFocus(WPARAM wP, LPARAM lp)
{
	UNREFERENCED_PARAMETER(wP);
	UNREFERENCED_PARAMETER(lp);
	GetDlgItem(IDC_EDIT1)->SetFocus();
	return 0;
}

2. Send message

UINT  WriteSNProc(LPVOID  lParam){
    CWriteSnDlg *pWnd = (CWriteSnDlg *)lParam; 
    PostMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
    //SendMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
}



 PostMessage(this,WM_SET_FOCUS, NULL,NULL);

[Solved] Compile Error: cannot open include file ‘afxres.h‘

Problem Description:

compilation error: cannot open include file ‘afxres h’


Cause analysis:

this is the header file of MFC class library</ font>


Solution 1:

If the MFC component is not installed, you can replace it with the next two lines

//#include "afxres.h"
#include <Windows.h>
#include <winres.h>
//Only one line winres.h is OK!

Solution 2:

Just install MFC components

VS2013 error RC2108: expected numerical dialog constant

When viewing the. RC resource file, I don’t know what’s going on. After turning it off and opening it in the resource view, this error will be reported.

I don’t remember moving anything in the. RC file. It just can’t be opened anyway

It is said on the Internet that if the cursor is positioned to the error and the XXX code is added, but if my cursor is positioned to the first line, this method is invalid
https://blog.csdn.net/liuyi1207164339/article/details/47131833

Solution: copy from the old. RC file, delete all the. RC file and replace it with the old. RC file. This should be a bug in vs2013.

Error 1 fatal error LNK1220: ‘/PGD‘ requires ‘/LTCG:[PGINSTRUMENT|PGOPTIMIZE]‘ specification

VS2008 compilation of an MFC project pop-up error, looking for a long time, did not find the problem.

  resolvent,

According to the official article:/PGD (specify database for profile guided optimizations) | Microsoft docs

  It says how to solve this problem,

  Setup steps,

1. Open the project property setting (right click on the solution project and select properties),

2. Select link = & gt; Optimization=> Profile Guided Database

3. Select & lt; inherit from parent or project defaults>, Click apply and confirm. Then compile and solve the problem.

error C4996: ‘inet_addr‘: Use inet_pton() or InetPton() instead or define _WINSOCK_D

[questions]

Vs2015 appears when writing socket client. (this is the second time I have encountered this problem. Last time vs2017, I must remember it to facilitate myself to check in the future: P)

SOCKADDR_ IN ClientAddr;
ClientAddr.sin_ family = AF_ INET;
ClientAddr.sin_ addr.S_ un.S_ addr = inet_ addr(“127.0.0.1”);
ClientAddr.sin_ Port = htons (port);
error c4996: ‘INET_ addr’: Use inet_ pton() or InetPton() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARNINGS to disable deprecated API warnings

[reason]

In the version after vs2013, INET is added_ New functions such as Pton () and inetpton () are used for IP address conversion between “dotted decimal” and “binary integer”, and can handle IPv4 and IPv6. And INET_ Addr is an old function. Higher version vs uses a new function by default when compiling, so this error will be reported.

[solution 1]

Replace INET with the new function suggested_ Addr function.

[solution 2]

Modify the vs configuration and tell it I want the old function

1. Modification method: Item – & gt; attribute – & gt; C / C + + – & gt; general – & gt; SDL check, change “yes” to “no”.
2. Property page of file_ CRT_ SECURE_ NO_ “Warnings” plus
– – –
copyright notice: This is CSDN blogger Rani_ The original article of “ZZ” follows CC 4.0 by-sa copyright agreement. Please attach the link of original source and this statement.
Link to the original text: https://blog.csdn.net/weixin_ 42731241/article/details/96143934

0xc0000005: an access conflict occurred while reading location 0x00000020

0x in.exe… Unhandled exception at: 0xC0000005: Access conflict occurred while reading position 0x00000020

Error: : PostMessage (AfxGetMainWnd () – & gt; M_hWnd, UM_XX, 0, 0);

or: : sendMessage (
AfxGetMainWnd()-> M_hWnd, UM_XX, 0, 0);

How to solve it?
Verify that afxGetMainWnd () returns NULL

int k = (int)(& (((CWnd*)NULL)-> m_hWnd));
The value of k is 0x20

In general: afXGetApp ()-> GetMainWnd (); AfxGetMainWnd() is used only on the main thread;

How: foreground thread and background thread, afxGetApp ->; GetMainWnd() differs from AFXGetMainWnd ()

AFXGetMainWnd () is an example of a window handle that can be used to retrieve a window handle. AFXGetMainWnd () is an example of a window handle that can be used to retrieve a window handle. Clever you must have already understand, if you have been tracking AfxGetMainWnd () call, will find that it earned a AFX_MODULE_THREAD_STATE threading module save active threads in the window handle, and a background thread since no window, then obtains the window handle is you from??(maybe someone’s understanding of the background is not display window, even with all the window, as long as it doesn’t show is a background thread, strictly speaking is not the case, the window is mainly used to interact with the user, a window is hard to avoid jam, And the background thread is often used to carry out some behind the operation or processing, is through the foreground information or data to carry out the corresponding operation, if the window is hidden to talk about what information transfer?The case can not be done in the background like other threads. The key is to know the difference and how to use it.)
AfxGetApp()-> GetMainWnd () is the main window handle, no matter in that thread calls are no problem, because it is first obtained the main thread handle, to achieve the main thread of the active window (such as switch view can lead to replacement, I am not sure this kind of circumstance), if there is no active window is the main window, any program must have a main window, so it calls there is no problem, if you want to achieve the program’s main window suggested AfxGetApp () – & gt; GetMainWnd().
Note that the console program has no window and its window handle is always 0. Second, the background thread is actually a desktop control program, just not the main thread. Also, threads created using functions such as API CreateThread cannot generate CWinThread objects. So if you want to use CWinThread object function, and some of the global function, as AfxGetMainWnd (), you must use CWinThread object CreateThread function, or use the AfxBeginThread () function creates a thread, or may be an error, because the MFC to the management of the thread is done through the CWinThread object, it is not hard to see through the tracking code below you. I remember that there was a predecessor once mentioned this problem, but I do not know whether it understands the reason
Here is the trace code:
_AFXWIN_INLINE CWnd* AFXAPI AfxGetMainWnd()
{ CWinThread* pThread = AfxGetThread();
return pThread! = NULL ?pThread-> GetMainWnd() : NULL; }

CWinThread* AFXAPI AfxGetThread()
{
// check for current thread in module thread state
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
CWinThread* pThread = pState-> m_pCurrentWinThread;
// if no CwinThread for the module, then use the global app
if (pThread == NULL)
hread = afxGetApp ();
return pThread;
}
You can see that calling afxgetMainwnd () on the main thread is not a problem (except for console programs) because it returns the main thread handle if the fetched thread handle is empty.
_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp()
{ return afxCurrentWinApp; }

CWnd* CWinThread::GetMainWnd()
{
if (m_pActiveWnd ! = NULL)
return m_pActiveWnd;// probably – place in active
// when not inplace active, just return main window
if (m_pMainWnd ! = NULL)
return m_pMainWnd;
return CWnd::GetActiveWindow();
}
I don’t need to worry about AFXCurrentInApp.
Hey hey, all finished, if your program exists similar to the above problems can be sure to change back oh.

Problems in using vs2017

Problems encountered in the use of VS2017. Only take notes, if there is infringement contact delete.
1. The default default.js or.vbs is missing when MFC adds classes to the interface. Microsoft Visual Studio2017\Community\Common7\IDE\VC\VCWizards\CodeWiz\MFC Move on to the great essay.
2. In the process of learning, the problem of “unable to start the program, denied access” suddenly appeared. After searching, it was found that it was because a game was started. After rebooting, it was fine.

3. Create new forms and pass values between forms.
1. Adding a class after adding a form is a good way to create a new form.
Open the new form code:

FileInformation dlg = new FileInformation();
dlg.DoModal();

2. Passing values between Windows should pay attention to:
1) use extern keyword to redefine the file in which the function is to be called;
2) Cannot assign initial values to variables.

How to solve fatal error C1010!

 

in compiled VC++6.0 is, appears

fatal error C1010: unexpected end of file while looking for precompiled header directive

problem explanation in detail:

fatal error C1010, the file did not end as expected while looking for a precompiled indication header file. The header file where the precompiled indication information was not found.

problems generally occur in:

adds some CPP files to an MFC program by adding files, but the CPP file is not MFC, is standard C++.

solution 1:

, right-click the CPP file in the Project Project and set it to the first item: Not using preheaders, from the C++ Header on the Project Settings page.

solution 2:
Add the include file stdafx.h at the beginning of the.cpp file.

# include “stdafx. H”

from: MSDN

Visual C++ Concepts: Building A C/C++ Program

Fatal Error C1070

mismatched #if/#endif pair in file ‘filename
An #if, #ifdef, or #ifndef directive has no corresponding #endif. The following sample generates C1070:

// C1070.cpp
#define TEST

#ifdef TEST
// use the line below to resolve the error
// #endif

#ifdef TEST

#endif

int main() {
}
// C1070

0xc015000f: the activation context being deactivated is not recently activated

While the program was running, this error popped up, calling functions on the stack, and it was very confusing.

After searching on the Internet, I found a prompt to disable the ActivationContext:
afxAmbientActCtx= FALSE in CApp::InitInstance().
this “solves” the problem, but upon closer inspection it turns out to be a hidden problem.
Junfeng Zhang in their blog to the comparatively detailed explanation (http://blogs.msdn.com/b/junfeng/archive/2006/03/19/sxs-activation-context-activate-and-deactivate.aspx). Basically, this error occurred because an exception was thrown in the code, which skipped the Deactivation corresponding to Context Activation, leading to subsequent Deactivation and the discovery that the Context in the stack was incorrect.
the MSDN BBS, net friend MMDev in response to someone else’s post (http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c3feab0f-601b-4ca6-beb2-8d4d615438cc/) gives a better solution:
in Visual Studio, the choice of the Debug | Exceptions menu items, in the pop-up dialog, check all the Win32 Exceptions to this exception is thrown in Win32, the program will interrupt, so you have the opportunity to () before the exception handling in the first time to see what happened in your own code error exception is thrown, so as to correct errors, eliminate hidden dangers in the program.