Previous post: EditPlus configuration VC + + (1) and related precautions
VC + + has two implicit compilation options /d1reportsingleclasslayout and /d1reportallclasslayout /d1 reportsingleclasslayout and/d1 Reportallclasslayout or will/change-All right
Like what
Cl.exe/d1reportsingleclasslayoutClassName//ClassName Front no spaces // or Cl.exe/d1reportallclasslayout
However, ClassName is the substring of the class name, and any class name that matches it will be output. For example, if you want to see Class A, you enter/d1reportsingleclasslayouta, but you will find that the compiler outputs many unrelated classes, such as struct aBC, class ina ttribute Class dbA... Because their class names contain the letter a .
You might say it's because of the library, like #include<iostream>, to get rid of it ... Try it, you will find it not yet ... Cl.exe has a lot of compilation options, such as/x ignoring the standard include directory, but I tried it all, it's useless ... The following batch of call "%vs120comntools%vsvars32.bat" to go is also not possible (to get rid of the statement can speed up the start speed, but not recommended, because it does not contain the library, if the class contains the class object in the library, cl.exe how to correctly calculate the layout of the Class)
As for,/d1reportallclasslayout compared to/d1reportsingleclasslayout, useless output only a lot more, so here do not use it ...
Since it's not working, you can only capture the standard output and then filter out useless information. Still in the VC + + directory to create a bat file, the content is as follows:
@echo Offcall"%vs120comntools%vsvars32.bat"if "%2"=="" GotoErrorif "%1"=="" GotoErrorcl.exe/NOLOGO/W/zs/d1reportsingleclasslayout%2%1Goto: Eof:errorecho error: Wrong parameter-is the class name delimited? Goto: EOF
In fact, nothing is called the next cl.exe just. The /zs option is to check only the syntax, not the. obj. exe files, etc...
How to capture the compiled output, which requires the use of anonymous channels in Windows to redirect the standard output. Here we write a console program ClsLayout.exe, which will be called by EditPlus. In ClsLayout.exe, the channel is created and the child process is created to perform the batch process. Then capture the standard output of the batch and filter the content, just output the desired ...
Here directly paste the code, as below, where the CmdLine function is I find on the Internet, directly to modify the
#include <iostream>////#include<fstream>#include <string>#include<windows.h>using namespacestd;Charg_name[101] = {};BOOLCmdLine (std::stringcmd) {security_attributes sa; HANDLE Hread,hwrite; Sa.nlength=sizeof(security_attributes); Sa.lpsecuritydescriptor=NULL; Sa.binherithandle=TRUE; if(! CreatePipe (&hread,&hwrite,&sa,0) ) {cout<<"createpipe Failure"<<Endl; return false; } startupinfo si; Process_information Pi; ZeroMemory (&si,sizeof(SI)); ZeroMemory (&PI,sizeof(PI)); SI.CB=sizeof(STARTUPINFO); Getstartupinfo (&si); Si.hstderror=Hwrite; Si.hstdoutput=Hwrite; Si.wshowwindow=Sw_hide; Si.dwflags=startf_useshowwindow |Startf_usestdhandles; if(! CreateProcess (NULL, (Char*) Cmd.c_str (), Null,null,true,0,null,null,&si,&pi)) {cout<<"CreateProcess Failure"<<Endl; return false; } closehandle (Hwrite); Charbuffer[ -]={0}; DWORD Bytesread; BOOLBfindit =false; BOOLBfindend =false; Char*pbegin =NULL; ////ofstream ofile ("C:\\out2.txt", ios_base::binary); cout<<"Waiting ..."<<Endl; //WaitForSingleObject (hread,infinite); while(ReadFile (Hread, (LPVOID) &buffer,127,&bytesread,null)) {Buffer[bytesread]=' /'; ////ofile<< (char*) buffer; ////continue; if(!bfindit && (Pbegin =strstr (buffer, g_name))) {System ("CLS"); Bfindit=true; Char*pend = Strstr (Pbegin,"\r\n\r\n\r\n");//minimum of 3 per class if(pEnd) {* (pend+6) =' /'; Bfindend=true; } cout<<"class"<<Pbegin; Continue; } if(Bfindit &&!)bfindend) { Char*pend = strstr (buffer,"\r\n\r\n\r\n"); if(pEnd) {* (pend+6) =' /'; Bfindend=true; } cout<< (Char*) buffer; } } ////ofile.close (); if(false==bfindit) cout<<"class not found"<< g_name << Endl <<Endl; return true;}intMainintargcChar*argv[]) { if(ARGC! =3) Gotoend; Char*cpppath = argv[1]; while(*cpppath) Cpppath++; if(cpppath-argv[1] <5|| _STRNICMP (cpppath-4,". cpp",4)) Gotoend; if(*argv[2] ==' /') Gotoend; Else_snprintf (G_name, "%s\t", argv[2]); Charcmd[201] = {}; _snprintf (cmd, $,"d:\\vs\\vs2013\\vc\\bin\\classlayout.bat \ "%s\" \ "%s\"", argv[1], argv[2]); CmdLine (CMD); return 0; End:cout<<"error: The input parameter is incorrect"<<Endl; return 0;}
- The ofile used to output all the captured content to the file, want to open it, cancel the inside of the////comment!!!
- The inside of the _snprintf (G_name, "%s\t", "argv[2"), is to find the class name as much as possible, if changed to "Class%s\t", sometimes can not find, because ReadFile is read by block, two blocks may be from " Class%s "Middle break ... We have reduced this possibility, and of course, just a reduction.
- This will also filter error warning etc.
- The memory layout output prefix of the struct is also "class"
After compiling the build ClsLayout.exe, add the tools in EditPlus as follows:
$ (Cursel) is the text selected by the mouse ...
Can also be configured in Visual Studio by: Tools-External Tools-add ... This is a little bit.
Use: before calling the tool, you must first use the mouse box to select the class name you want to see !! Then click on the tool icon or press the shortcut key ctrl+5 and so on.
To use a motion diagram:
EditPlus Configuration VC + + (2) and/d1reportsingleclasslayout