Just found, I haven't finished yet

xiaoxiao2021-03-06  59

Sender: lynn (Mao Xiong), Letter Area: VC Title: [ON_TOP] FAQ_2003_11_15_build3 Send Station: 海星 云 (November 15, 2003 18:27 Saturday), station letter ******* **************** 1.une neypected endy limited ==> Page12. Generating 0 - 1 uniform distribution random number ==> Page23.Link2001 Error: unresolved External Symbol "Symbol ==> Page34.MFC Application ==> Page85. Get system time in the program ==> Page17btw: Page (n) Continuous Press N-1 Sub-space (change page symbol) arrive / **************************** ** RANK: ★★★★★★ ☆ ☆☆ *************************************************** / Q: UNEXPECTED End of File While Looking for Precompiled Header Directive prompts this Error, how would this? A: 1. At all .c .cpp files, start in all .c .cpp file #include "stdafx.h" 2. Also in VC IDE Project-> setting-> C / C -> category- > Precompiled Headers for pre-translated set / **************************** *** RANK: ★★★★★ ★ ☆ ☆ ** ***************************************** How to generate even distribution between 0 and 1 among VCs Random A: The following is a routine: example / * rand.c: this program seeds the random-number generator * with the Time, The Time, The THE n displays 10 random integers. * / # include #include #include void main (void) {Int i; / * seed the random-number generator with current Time SO That * The Numbers Will Be Different Every Time We Run. * / Srand (NULL); / * Display 10 Numbers. * / for (i = 0; i <10; i ) Printf ("% 6F / n ", (float) Rand () / rand_max);} / **************************** ** RANK: ★★★★★★★★★ ☆ ***************************************** / Q: unresolved External Symbol "Symbol" (Uncertain external "symbol) prompts such a mistake, how would this?

A: Some people often ask a link2001 error, a common solution: Learn the link error LNK2001 when learning VC , this error is very annoying, because the most important error for the programmer is more compiled, Generally speaking, compiling is passed. There are very many reasons for generating connection errors, especially the LNK2001 is wrong, often unknown. If you don't learn and understand VC in depth, you want to correct the connection error. LNK2001 is very difficult. In the process of studying VC , the beginner is mainly: unresolved external symbol "Symbol" (Uncertain external "symbol"). This error message will be generated if the connection program cannot find the referenced functions, variables, or tags in all libraries and destination files. In general, there are two reasons for incorrect: First, the variables are not existed, spelling is incorrect, using errors; secondly, different versions of connection libraries may be used. The following is a cause of the LNK2001 error: one. The LNK2001 caused by the encoded error. 1. Unpredictable program code or module definition (.def) file can cause LNK2001. For example, if a variable "var1" is declared within the C source file, it is attempted to access the variable in the variable "var1" in another file. 2. If the inline function used is defined within the .cpp file, not the definition within the header file will cause the LNK2001 error. 3. When the function is called, if the type of parameter type with the function declaration does not match the function declaration, LNK2001 will be generated. 4. Trying to call the virtual function from the constructor or description function of the base class. The LNK2001 will be caused. 5. Pay attention to the publicity of functions and variables, only global variables, functions are public. Static functions and static variables have the same range limit. When trying to access any static variables not declared within the file from the file, it will cause compilation errors or LNK2001. Variables (local variables) declared within functions can only be used within the range of this function. The global constant of C has only static connection performance. This is different from C, and the LNK2001 error will also be generated if the global variable is used in multiple files of C . One solution is to add the initialization code of the constant in the header file, and contain the header file in the .cpp file; another method is used to assign the variable to the constant. Two. The LNK2001 1 caused by the settings of compilation and links. If the / nod (/ nodefaultlib) option is used, the runtime and MFC library required by the program are written to the target file module when the compiler is connected, unless these libraries are not included in the file. Will be linked into the project file. In this case, the use / NOD will result in an error LNK2001. 2. If there is no program entry for WwinMainCrtStartup, "UnreSolved External ON _WINMAIN @ 16" will be obtained when using Unicode and MFC. 3. When compiling using the / md option, since all the runners are retained within the dynamic link library, "FUNC" is referenced in the source file, the reference to "__Imp__func" in the target file. If you try to use a static library libc.lib or libcmt.lib, LNK2001 will occur on __Imp__func; if you do not compile / MD option, LNK2001 will occur when using the MSVCXX.LIB connection.

4. When compiling using the / ml option, if the LNK2001 occurs on _ERRNO with the libcmt.lib link. 5. When compiling the debug version of the application, the LNK2001 will be generated if the release model is used, and also, the same problem is also generated when using the debug version of the formation library to connect the release application. 6. Mixing use of different versions of libraries and compilers can also generate problems because the new version of the library may contain symbols and descriptions of the previous version. 7. Use the inline and non-inline compilation options in different modules to cause the LNK2001. If the function inline (/ OB1 or / OB2) is turned on when the C library is created, but the function inline (no inline keyword) is turned off in the corresponding header file described, and the error message will be obtained. To avoid the occurrence of this problem, the inline keyword flag should be used in the corresponding header file. 8. Incorrect / subsystem or / entry settings can also cause the LNK2001. In fact, there are many reasons for the production of LNK2001, and the above reasons are only part of it. These for beginners are enough to understand a while. However, the purpose of analyzing the cause is to avoid errors. Although the LNK2001 error is more difficult, as long as the above problem is noted, can it be avoided and solved? / ************************************ ** ** rank: ★★★★★★★★ ☆ **************************************** / MFC application Using the pointer in the program (reproduced - Source Vccode Dragon Tang Forum) 1) Get a DOC pointer in ViewDidoc * pdoc = getDocument (); one can have a document.

2) obtaining MainFrame pointer CWinApp the m_pMainWnd variable is MainFrame pointer may be in the App: CMainFrame * pMain = (CMainFrame *) AfxGetMainWnd (); 3) obtained MainFrame pointer CMainFrame * pMain = (CMaimFrame *) AfxGetApp in View ( ) -> m_pmainwnd; 4) Get View (established) pointer cmainframe * pmain = (cmaimframe *) AFXGetApp () -> m_pmainwnd; cyouview * pView = (cyouview *) PMain-> getActiveView (); 5) Get the current document pointer CDocument * pCurrentDoc = (CFrameWnd *) m_pMainWnd-> GetActiveDocument (); 6) obtained with the toolbar status bar pointer CStatusBar * pStatusBar = (CStatusBar *) AfxGetMainWnd () -> GetDescendantWindow (AFX_IDW_STATUS_BAR); CToolBar * pToolBar = (CtoolBar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_TOOLBAR); 7) If you join the toolbar and status bar variable (CMAINFRAME *) getParent () -> m_WndToolBar; (cmainframe *) getParent () -> m_wndstatusbar; 8) Mainframe gets menu pointer cmenu * pMenu = m_pmainwnd-> getMenu (); 9) gets the application class MFC global function AFXGetApp () in any class. 10) From the document class, I learned, I learned, from the document to get the view class pointer to control the positioning of multiple views of the same document, my experience is particularly text processing CEDITVIEW when generating multiple views This feature is very needed when class. CDocument class provides two functions for the positioning of the view class: GetFirstViewPosition () and GetNextView () virtual POSITION GetFirstViewPosition () const; virtual CView * GetNextView (POSITION & rPosition) const; Note: GetNextView () parentheses are parameters Reference mode, therefore the execution rate may change. GetFirstViewPosition () is used to return the first view location (the returned non-view class pointer, but a position value), getNextView () has two functions: Returns the next view class pointer and change with reference calls. The value of the incoming Position type parameter.

Obviously, in the Test program, there is only one view class, so you only need to call the two functions to get the CTestView pointer as follows (you need to define a Position structure variable to assist the operation): CTestView * PtestView; position pos = getFirstViewPositionPosition (); PTestView = getNextView (POS); you can go to the CTestView class pointer PTestView. After the completion of the sentence, the variable POS = NULL, because there is no next view class, nature does not have the next view class Position. But These statements are too simple, do not have too strong versatility and security features; when you want to return a pointer to a specified class in multiple views, we need to traverse all view classes until Find the specified class. When it is determined if a class pointer points to an instance of a class, you can use the iskindof () member function to check, such as: pView-> iskindof (runtime_class (ctestView)); you can check if the PVIEW refers to whether it is a CTestView class. With the above foundation, we can already get any type of pointer from the document class. For convenience, we use a member function of a document class, which has a parameter that means which type of pointer to get. To achieve the following:! CView * CTestDoc :: GetView (CRuntimeClass * pClass) {CView * pView; POSITION pos = GetFirstViewPosition (); while (! Pos = NULL) {pView = GetNextView (pos); if (pView-> IsKindOf (pClass )));} If (! PView-> iskindof (pclass)) {AFXMessageBox ("Connt Locate the view./r/n"); return null;} return pView;} A member function of two view classes Iskindof () is judged because there are three possibilities of exiting the While loop: 1.pos is null, that is, there is no next view class for operation; 2.PVIEW has met the requirements. 1 and 2 are satisfied. This is because the function of getNextView () is to change the current view pointer to the location of a view, and then return the current view pointer, so POS is the top of the PVIEW's top view class, which is all possible to be both pOS == null is PVIEW. . When the desired view is that the last view is the last view class. Therefore, two judgments are required. Use this function to follow the following format (to get the CTestView pointer as an example): ctestView * PTestView = (ctestView *) GetView (runtime_class (ctestView)); runtime_class is a macro, you can simply understand its role: Transform the name of the class For CruntimeClass as a pointer. As for the mandatory type conversion is also for security features, since the pointer type between the same base class is compatible with each other. This mandatory type conversion may not be necessary, but can avoid some cumbersome possible. 3. Number of pointers 1 and 2 from one view class, it is easy to obtain a method of obtaining a pointer between the view classes: It is to transfer the document class with a document class. Use 2 method to obtain another view class with the view positioning function of the document class.

Similarly, it can be implemented as a function: (Supplementation to get the pointer to other view classes from CTestaview) CView * ctestaview :: getView (cruntimeclass * pclass) {ctestdoc * pdoc = (ctestdoc *) getDocument (); cView * pVIEW; Position POS = PDOC-> getFirstViewPosition (); while (pOS! = Null) {pView = pdoc-> getNextView (POS); if (! PView-> iskindof (pclass)) Break;} if (! PView-> iskindof) PCLASS)) {AFXMessageBox ("Connt Locate the View."); Return Null;} Return PView;} This function is more than the first sentence than the GetView (), one is the first sentence to obtain a document pointer, and the other is Add a document class pointer to GetFirstViewPosition () and getNextView () to indicate that they are document class members. With this function; when you want to get the CTestbView pointer from CTestaview, you just need to follow: ctestbview * ptestbview = (ctestView *) GetView (runtime_class (ctestbview)); 11) You can also add multiple document templates for single documentation, However, the general development uses the MDI mode to develop multi-document templates, which is very close to the acquisition method of the above view. Here is a slight explanation. If it is unclear, please refer to MSDN (11, 12, 13, 14) Source: http://sanjianxia.myrice.com/vc/vc45.htm You can use cwinapp :: getFirstDoCTemplatePost to get the location of the first document template for the application; use this value to call the cwinapp :: getnextDocTemplate function, get the first A CDOCTemplate object pointer .Position getFirstDOCTemplate () const; cdoctemplate * getnextdDoCtemplate (position & pos) const; second function Returns a document template that is identified by POS. Position is an MFC definition for iteration or object pointer retrieval. Through these two functions, the application can traverse the entire document template list. If the retrieved document template is the last one in the template list, the POS parameter is set to null.12) A document template can have multiple documents, each Document templates have retained and maintained a list of pointers for all correspondence documents. Get the location of the first document in the document collection related to the document template with the cdoctemplate :: getFirstDocposition function, and use the POSITION value as the parameters of CDOCTemplate :: getNextDoc to repeat the list of documents related to the template.

转载请注明原文地址:https://www.9cbs.com/read-82753.html

New Post(0)