** Software Company Software Development Norm (Trial Edition) In the case of company team collaboration, an important aspect of programming should emphasize is an easy-to-readability of the program, and in the case of ensuring performance indicators to meet user needs. , Let other programmers easily read your program. A set of distinctive programming styles allows collaborators, successors and themselves at a glance, seeing the structure of the program, understanding the idea of design in a short period of time. Great to improve code readability, reusability, program robustness, portability, and maintenanceability. The purpose of this programming specification is to improve the company's software development efficiency and the maintenanceability of the software developed, and improve software quality. This specification consists of the program style, naming rules, annotation specification, program robustness, portability, error handling, and software modular specification.
I. Program style: 1. Strictly use the ladder hierarchical program code: The indented points of each hierarchy use VC's default style, that is, each hierarchy is 4 grids, and parentheses are located in the next line. The parentheses required to match in the same column, and the contingent is required to renew 4. For example: void main () {... long li; // loop variable long lsum; // is used to record and float Favg; // is used to seek average value ... // logarithm Accumulated. For (Li = 0; Li <10; Li ) {lsum = lsum li; ...} // seeks average. FAVG = lsum / 10.0; ......}
2. The location of the prompt information is required to be given in the program, in order to support the development of multiple languages, all other prompt information must be defined in the resource in addition to some temporary information given to the debug. 3, the definition of the variable is as possible to the beginning of the function. Second, naming rules: 1. Naming rules of the variable name 1, the naming rules of the variable require the "Hungarian rules". That is, the 开 字 字 变 变 英 部分 写 写 写.. 字.............................. That is: the variable name = variable type variable English meaning (or abbreviation) to non-universal variables, add an comment instructions when defined, and the variable definition is as possible to place the function. See below: Bool (Bool) Bisparent Byte (BYTE) with the beginning of the BYFLAG SHORT (INT) with N starting NSTEPCOUNT long (long) with the beginning lsum char (char) with c head ccount float (float) F beginning fAvg double (DOUBLE) beginning vVariantunsigned short with v with d beginning dDetavoid (VOID) (WORD) with w beginning wCountunsigned long (DWORD) dwBroadHANDLE start with dw (the HINSTANCE) with h beginning hHandleDWORD with dw beginning dwWordLPCSTR (LPCTSTR) start with str STRSTRING is used with 0 ends of the SZFileName
The naming recommendation to the technical committee is given to the number of variable types not given.
2, the basic principle of pointer variable name is: the basic principle of a heavy pointer variable is: "P" variable type prefix naming, such as a float * type should be represented as the basic rules for PFSTAT to multiple pointer variables as: two pointers: "PP" variable type prefix named triple pointer: "PPP" variable type prefix name ... 3, global variables start with G_, such as a global long variable is defined as g_lfailcount, ie: variable = G_ variable type variable English meaning (or abbreviation) 4, static variable starts with S_, such as a static pointer variable is defined as s_plperv_inst, ie: variable name = S_ variable type variable English meaning (or Abbreviations) 5, the member variable starts with M_, such as a long member variable is defined as m_lcount; ie: variable name = m_ variable type variable English meaning (or abbreviation) 6, for enumeration type (enum) Variables require prefix with enumeration variables or their abbreviations. And require capitalization. Such as: enum cmemday; emdays_tuesday; ......}; 7, naming requirements for Struct, Union, Class variables. And to add a prefix, the naming rules of its internal variables are consistent with variable naming rules. Structure generally uses Steres such as: Struct SCMnPoint {INT NX; // point x position int NY; // point Y position}; the consorted body is generally used as the beginning such as: union ucmlpoint {long lx; long l;} class Express with C, such as: float fpoint;}; for general structures should be defined as class templates, for future scalability, as: Template
For example, a function of an image editing that is taken from the dynamic library is defined as imgfunctionName (where IMG is image abbreviation). Now give the naming prefix of the three libraries: 1, the general-purpose library, using cm prefix. 2, for the three-dimensional function library, using VR-based prefix. 3, to the image function library, use IMG as a prefix. For macro definition, the results code use the same prefix. 5. Naming specification (including dynamic libraries, components, controls, engineering files, etc.): The name requirement of the file name expresses the content of the file, requiring the length of the file name to be less than 5 letters, strictly forbidden to use the like File1, Myfile File names. Third, Note Specification: 1, the comment of the function head For functions, you should use the following format from "Function", "Parameters", Return Value, "Main Ideas", "Call Method", "Date" six aspects: // Program Description Start / / ============================================= ===================== //// function: Remove another String from a string. // Parameters: strBydelete, Strtodelete // (inlet) strBydelete: Deleted strings (original strings) // (export) Strtodelete: String to be removed from the previous string. // Return: Find and delete it to return 1, otherwise return 0. (To list an error code) for the return value with error code. // Main ideas: This algorithm mainly uses a cycle comparison method to find // with StrByDelete, which matches STRTODELETE, has multiple StrByDelete substrings in multi-match StrByDelete substrings.
See: // Name ... // Call Method: ... // Date: Start Date, such as: 2000/8 / 21.9: 40--2000 / 8 / 23.21: 45 / / =========================================================================================================================================================================================== ================= // Function name (...) // Site, for some functions, the partial parameters are incoming values, and some parameters are outgoing Value, so the parameter should be described in detail. This parameter is an entry parameter or an export parameter. For some meaningless parameters, it is necessary to do a detailed description (for example, when an angle is used as a parameter, the angle parameter is in an arc (Pi) ), Or units), the variables that are both inlet and exports should be indicated at the same time at the entrance and exit. and many more. 2, the comment of the function should be placed in the header file of the function, and the implementation portion of the function in the implementation file should be placed at the same time. 3, in the comment, the main implementation of the function should be described in detail, especially to indicate some of your thoughts, if necessary, should be written by the idea. For some mimic functions, you should comment on the source of the function. 4, in detail in detail, indicate the appropriate call method of the function, and the processing method of the return value, etc. Where you want to emphasize the danger of call during the comment, you may be wrong. 5. Note on the date requires the date between the test from the start write function to the end function. 6. The function comment begins to the function name between the function name should have a special string used to identify. If the algorithm is complicated, or the variable definition in the algorithm is related to the location, the definition of the variable is required to illustrate. Algorithms that are difficult to understand can illustrate as much as possible. 2. Note: The annotation of the variable is followed by the function of the variable after the variable. In principle, for each variable, it should be annotated, but there are very significant variables, such as: I, J and other cyclic variables may not comment. For example: the root of Long LlineCount //. 3. Note: The file should be added to the following annotation in the beginning: /// Engineering: The item name where the file is located. // Author: **, modified by: ** // Description: Feature Description file. // Main functions: ............ // Version: Description file version, complete date. // Modify: Describe the modification of the file, modify the reason, and the date of modification. / / Reference: ... / For the header file being repeatedly included to define the desired header file as follows: #1fndef __filename_h __ # define __filename_h__ where filename is the name of the header file. 4. Other Note: We don't need to comment every line of statement in the function. However, you must add block annotations before each of the function modules, annotate each group of statements, each branch of the loop, process, etc., as much as possible. The cycle, condition, and selective position must be annotated. For the case where the order of the front and rear, it is recommended to add the serial number in the comment.
For example: ... // 1, ...... Note for (...) {} if (...) {// ... Comment} Else {// ... Note} // ... Comment Switch (...) {Case: ... // ...... note .. .... Case: ... // ...... Note ... Default: // ... Note ...} Performed in other order In the program, every 3-5 line statement must be added, and a note must be added to the function of the small module composed of this statement. For some of the unique ideas requirements, it is launched in the comment. Fourth, program robustness: 1. Return value specification for functions: For the return position of the function, try to keep a single system, that is, a function is trying to do only one return position. (Single-in-one exit). Ask everyone the return value of the unified function, and all the return values of all functions will return in a coded manner. For example, the code is defined as follows: #define cm_point_is_null cmmakehr (0x200):: The suggested function implements the following: long function name (parameter, ...) {long LRESULT; / / Keep error number LRESULT = cm_ok; // If the parameter has an error, return an error IF (parameter == null) {LRESULT = cm_point_is_null; goto end;} ... end: return LRESULT;} 2, About GOTO Application: Application to goto statement, we require minimize GOTO statements. The required place for a certain amount of place can only be transferred backwards. 3. Processing of resource variables (resource variable refers to the variable of consumption system resources): The initial value must be assigned to the resource variable. The allocated resource must be released immediately after the use, and re-assaptuous values. Example: long * flatocmem; // Defines a variable allocated in memory. PLALLOCMEM = (long *) Calloc (40, sizeof (long)); // Assign a memory. // Process allocation memory error if (planocmem == null) {LRESULT = cm_mem_alloc_failed; goto end;} ... use memory ... // Release resource variables and re-assapt. IF (PallocMem! = NULL) {free (PLALLOCMEM); PallocMem = NULL;} 4, judging complicated conditions, for program readability, should be used to use parentheses. Example: IF ((SZFileName! = Null) && (LCOUNT> = 0))) || (Bisreaded == True)) 5. Portability: 1. High quality code requirements can be cross-platform, so our code Support for different platforms should be considered, especially for Windows98 and WindowsNT. 2. Since the C language is better, the C code is required for the algorithm function, and C code cannot be used. 3. Do different processing for different hardware and software functions. V. Error handling: 1. Error report processing. The various executions of the function are required to consider the functions of the function, and all process conditions can be handled as much as possible. The function is divided into two categories: a class is not related to the display of the screen, (not with the user exchange information), is related to the display of the screen. (Function with the user exchange information) Reports an error by the return value for functions independent of the screen display. For functions related to the screen display, the function is responsible for issuing a warning to the user and performs an error handling. Error handling code is typically separately established a universal processing function.
As follows: void cmdeal_with_ERROR (long errcode) {copy 1: // Note ... case 2: // Note ... default: // Comment ...} } 2, find out the error in the program as soon as possible: 1, pay attention to the warning information in the compiler. For warning messages generated by the compiler, we should attach enough attention, in fact, many warning information indicate potential errors in the program. So we must carefully check each warning message to see if there is a hidden danger. Try to eliminate warning information. 2, using assertions to check the error for some assumption in the program, or prevent the illegal value of certain parameters, using assertions to help find the error is a good way. For example, the following functions: long cmmemcpy (void * pvfrommiem, size_t wsize) {... if (pvtomememmmmem == null || pvfrommem == null) {LRESULT = cm _point_is_null; goto: end;} while (wsize -> 0) {* PVTOMEM = PVFromMEM ;} end: return LRESULT;} Adoption of the incoming pointer error, but this judgment is that the final compiletable code becomes large, while reducing the performance efficiency of the final release program . Since the incoming empty pointer is obviously the error of the program that calls this function, instead of this function error, we can consider using the assertion instead of the pointer check, that is, use Assert (pvtom! = Null && pvfrommem! = Null) instead of IF (PVTOMEM == Null || pvfrommem == null) {LRESULT = CM_POINT_IS_NULT = CM_POINT_IS_NULL; GOTO: END;} This will only produce check code in the debug version, and these code will not be included in the formal release. And it can be convenient for us to find errors during program debugging and testing, while do not affect the efficiency of the program. In some cases below, you must have a step: a, number of parameters, especially the pointer parameters must be confirmed by assertion. b, using the correctness of various assumptions in the assertion check program. c. Don't easily think that something impossible in the programming is not possible. If you think it is impossible, it must be confirmed by an assertion. In order to make the assertion in the program functions, all dynamic libraries for testing or debugging inside the development must adopt a debug version. Explanation: In the program efficiency requirements, or call more frequent functions, the error checking for the entrance parameters, the advantages are as described above, but their robustness is not strong, so in other cases, the use of traditions The inspection method is to enhance the robustness of the program, of course, for the convenience of debugging, can simultaneously use the assertion mode. 3, strict test: Strict tests are required for each code, especially for some functional functions to test their various critical points (such as zero value, infinity values, etc.). Try to do a zero error in each section. Sixth, modular specification: in order to improve software reuse, reduce the workload of repeated development. At the same time, in order to improve the readability of the program, it is easy to maintain the maintenance of the program, and the modular work of the software must be strengthened. Modularity should follow the following basic specifications: 1, a function should be flexible, the code of the function should be controlled in a moderate scale, each function code is generally not more than 150 lines, if exceeding this size, should be performed Modular work.
For some special functions, it is indeed more than 150 lines, and it should be submitted. After passing, the writer is required to more detailed a more detailed payment, and the cause of the function is superficial, as well as design ideas. 2, a function, if you repeatedly implement more than three times, you should consider modular, write it into a general function. And released to the developer. And request the interface documentation and implementation function file. 3. Each developer uses the ready-made module from others as much as possible to reduce duplication development. 4. When performing a function of function, consider the hierarchical relationship of the function, especially when adding a new functional module, the original function code should be carefully adjusted, and the different functions of the same function are not repeated, this requirement The purpose is to facilitate code maintenance. Examples are as follows: The following functions: // Repair from the SZFileName file ... long ... c_szfilename, ...) {cfile * pfile; // To save the address of the file pfile = new cfile (c_szfilename, cfile :: modeRead); // Create a read-only file if (pfile == null) {LRESULT = cm_point_is_null; goto end;} // read from the file ............ // Close the file delete pfile; end: return LRESULT;} If you need to increase the new function of the following interface now: long ... cmreadsomething (cfile * pfile) {if (pfile == null) {LRESULT = cm_point_is_null; goto end;} // Read from the file ... ... end: return LRESULT;} requires the following: Will .... ..cmgetsomething (const char * c_szfilename, ...) is changed to long ... cmgetsomething (const char * c_szfilename, ...) {cfile * pfile; // Used to save open Document address long LRESULT = cm_ok; // Error return code // Open file Pfile = new cfile (c_szfilename, cfile :: modeRead); if (pfile == null) {LRESULT = cm_point_is_null; goto end;} // Read ... LRESULT = cmreadsomething (pfile, ...); if_error_goto_end // Close the file delete pfile; end: return LRESULT;}
Some of the modular precautions: 1, design the module interface, use object-oriented perspective, including: function interface and variable interface. 2, do not change easily after the interface is defined, and explain it in the beginning of the module (the beginning of the file), so when defining the interface, it must be repeatedly pondered and keep the style. 3, pay attention to global variables is also an interface. If it is not necessarily necessary, we should use less global variables. 4, in the function interface, try to make the interface interface easily and use, where each input / output parameter represents a type of data, do not mix the error value and other dedicated values in other input output parameters of the function. 5, strive to write a function that is always successful, so that the caller does not have to perform corresponding error processing. This specification is a trial version, and the right to interpret belongs to the technical committee of the ** software company! When the employee is writing a program, see FuncTemplate.h and FuncTemplate.cpp
FuncTemplate.h
//// Engine: functemplate.h ////////> Description: Use to process some algorithms for the binary tree, and matrix memory allocation. //// version: FuncTemplate version 1.0. ////
Typedef struct _node // Define a node {structure _node * PleftChild; // node left child struct _node * pRightchild; // node's right kid} node;
/ / =========================================================================================================================================================================================== ================== /// / function: use loop to implement the left sequence traversal of the binary tree /// / / parameter: pnode //// (entry) PNODE: binary tree The entrance address, that is, the address of the root node. //// (export) is not. / // Return: Long's function return code, if the return value is cm_ok, the table is successful, and the table is returned to the //// cm_point_is_null table two fork pointer is empty. / / / =============================================== ==================== // long cmwalktreeusecycle (const node * pnode);
/ / =========================================================================================================================================================================================== =================== // / function: allocate memory in the matrix //// Parameters: wrowsize, wcolsize, ppplmatrix //// (inlet) WROWSIZE: matrix Number of rows; //// (inlet) WCOLSIZE: Matrix number; /// (inlet) PPPPLmatrix: The address of the matrix to be assigned; //// (export) PPPLmatrix: Allocated matrix address; / /// Return: Long's error number, if the return value is cm_ok, the table allocation is successful, the return /// cm_pointer_is_not_null table matrix is not empty. / / / / CM_MEM_ALLOC_FAILED system is insufficient /// / ===================================== =========================================================================================================== # .cpp
//// project: FuncTemplate.cpp //// Author: ** //// modified by: **, *** //// Description: The algorithm used to deal with some of the binary tree, and a matrix memory allocation. // Main functions: cmwalktreeusecycle, cminitmatrix // version: FuncTemplate version 1.0. // Completion date: 2000-8-26 /// / modification date: 2000-8-27, 2001-12-21 //// Reference literature: Graphics Developer Guide (Machinery Industry Press) //
#define strict # include "stdio.h" #include "stdlib.h"
#ifdef __cplusplusextern "c" {#ENDIF / * __CPLUSPLUS * /
#include "makehresult.h" #include "memory.h" #include "funcTemplate.h"
#define cm_mem_pointer_is_null cmemakehr (0x100) / / Indicates the pointer does not empty error #define cm_mem_pointer_is_not_null cmemakehr (0x101) / / indicates an error that the pointer is not empty
#define max_pushed_nodes 100 // Defines the maximum number of stacks
Program function description start / / ============================================== ====================== // function: use loop to realize the left sequence traversal of the binary tree // parameter: cpnode //// (entry) CPNODE: binary tree The entrance address, that is, the address of the root node. // (export) is not. /// Return: Long's function return code, if the return value is cm_ok, the table is successful, and the back // ms_point_is_null table two-fork pointer is empty. // Call method: Before calling this function, you must initialize the binary tree // think: If you are accessing a node, if the node has left branches, you will first access left branches. / / The node is then accessed if the node also has a right branch. Enter the right branch again. // When accessing left branches, tag is made in the stack, and this is accessed when the left branch is processed. After each node is accessed, if the node does not have the right child, and the stack has been // is empty, the access to the node is completed, and the code is repeated to each node to //. //// See: Graphics Developer Guide (Machinery Industry Press) Page: 927 / / Date: 2000/8 / 26.9: 40--2000 / 8 / 26.21: 45 / / ======== ============================================================================================================================================================================================================= =========
// Graphic: // Root node @ @ @ @ 孩子 @ @ @ @ / / 左Child left child right child
HRESULT CMWALKTREEUSECLECLE (const node * cpnode) Program function Description End {HRESULT LRESULT; // Used to save the returned error number. Node * pnodestack [max_pushed_nodes]; // is used as a stack of nodes. Node ** PPNODESTACK; / / The pointer used to indicate the node stack. LRESULT = cm_ok; // Judging whether the tree is empty. IF (cpnode! = Null) {pnodestack [0] = null; // Setting the stack is empty. PPNODESTACK = PNODESTACK 1; for (;;) {// If the current node has left children, the current point is stack. / / Move the current point to the left child, start traversing the left sub-tree, //, until you find the node without your left child. While (cpnode-> Pleftchild! = null) {* PPNODESTACK = (Node *) cpnode; cpnode = cpnode-> Pleftchild;} // We are now there is no left child's node, so access // node, if there is a right tree , Then access the right child. Or // The subsequent node. Duplicate node out of the stack until we find / / have a node of the right child, or all node outlets for (;;) {// access node (call other functions, no implementation) CMVisitNode (cpnode);
/ / If the node has a right child, make the child become the current festival // point and start traversing the subtree, otherwise the return of the return node / / until we find a node with the right tree, or // Point has been accessed. IF (cpnode-> pRightchild! = Null) {cpnode = cpnode-> pRightChild; Break;}
/ / Out a node out of your stack, we can access it and determine whether there is a right child. IF ((cpnode = * (- ppnodestack)) == null) {// Stack is empty and the current node does not have a right child, over // spread. LRESULT = CM_OK; goto end;}}}} // If the pointer sets the return value information to MS_POINT_IS_NULL. Lresult = cm_pointer_is_null; end: return LRESULT;}
Program function description start / / ============================================== ====================== // function: allocate memory // parameters: CWROWSIZE, CWCOLSIZE, PPPLMATRIX / / (入口) CWROWSIZE: Matrix line Number; // cwcolsize: Matrix column; // PPPLmatrix: The address of the matrix to be assigned; // (export) PPPLmatrix: Assigned matrix address; // Return: long error number, if the return value is cm_ok, The table allocation is successful, the return // cm_pointer_is_not_null table matrix is not empty. // cm_mem_alloc_failed system's memory // call method: You must first assign the incoming value before calling this function. A reference value is referenced. // such as: long ** pplmatrix; 即: // pplmatrix = null; call is: cminitmatrix (10, 10, & pplmatrix); // Idea: All rows of memory is allocated, and then each The columns corresponding to the row allocates memory. // See: No // Modify: / / Date: 2000/8 / 29.16: 40--2000 / 8 / 29.16: 45 / / =================== ========================================================= HRESULT CMINITMATRIX (const size_t cwrowsize, const size_t cwcolsize, long *** ppplmatrix) Program function description ends {hResult LRESULT; // Stores the return value. LRESULT = Cm_ok;
Word Wi; // Removal of the incoming value null. If (** ppplmatrix! = Null) {LRESULT = CM_POINTER_IS_NOT_NULL; goto end;} // The row of the matrix is allocated ** PPPLmatrix = Long *) Malloc (CWROWSIZE * SIZEOF (long *)); // returns if the assignment fails. IF ((** ppplmatrix) == null) {LRESULT = cm_mem_alloc_failed; goto end;} // allocate memory. For (wi = 0; wi #ifdef __cplusplus} #ENDIF / * __CPLUSPLUS * / Error handling extension: MakehResult.h //// Author: ** // Description: // main function is to return to uniform regulations code: // References: COM Technology Insider (Microsoft's Component Object Model); [US] Dale Rogerson with // #ifndef __ERRORDEFINE_H __ # Define __ERRORDEFINE_H__ #include "Winerror.h" // Figure / 3 3 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // - ---------------------- ---- ------- ------------------- // | SEV | C | R | Equipment Code | Code | Return Code | // - - - ---------------------- ------- ------------ // / / =========================================================================================================================================================================================== ================================== / Definition of device code // Defined device code for universal function #define Facility_cm 0x80 // Defined device code for virtual reality function #define facility_vr 0x81 // Device code defined for image function #define facility_img 0x82 / / =================== ============================================================================================================================================================================================================= =============== // Define class encoding (the first 6 digits in the latter 16) // from 0x00 ~ 0x3f /////, 0x38 ~ 0x3f is reserved for the programmer Temporary classification. // Standard class code from 0x00 ~ 0x37 # Define memory_class 0x01 # define file_class 0x02 / * # Define TEMP_CLASS1 0X38 # define TEMP_CLASS2 0X39 # define TEMP_CLASS3 0X3A # define TEMP_CLASS4 0X3B # define TEMP_CLASS5 0X3C # define TEMP_CLASS6 0X3D # define TEMP_CLASS7 0X3E # define TEMP_CLASS8 0X3F * / // ============ ============================================================================================================================================================================================================= ===================== // The top 3 shields of the temporary resource time bits (ie 8 temporary classes are saved), temporary resources from 0x0000 ~ 0x1FFF ( Programmer input value) // actually 0xE000 ~ 0xFFFF (after macro conversion) #define addTempClass ((0x38 <10) | LRESULT) // Define Return to the General Function Return Code Type // For the incoming value of LRESULT between 0X0000 ~ 0X1FFF #ifndef CMEMAKEHR #define CMSMAKEHR (lResult) MAKE_HRESULT (SEVERITY_SUCCESS, FACILITY_CM, ADDTEMPCLASS (lResult)) #define CMEMAKEHR (lResult) MAKE_HRESULT (SEVERITY_ERROR, FACILITY_CM, ADDTEMPCLASS (lResult)) # endif // CMEMAKEHR // definition of virtual reality function returns a return value passed to the type of code // lResult is between 0X0000 ~ 0X1FFF #ifndef VREMAKEHR #define VRSMAKEHR (lResult) MAKE_HRESULT (SEVERITY_SUCCESS, FACILITY_VR, ADDTEMPCLASS (lResult)) #define VREMAKEHR (lResult ) Make_hResult (severity_error, facility_vr, addtempclass (limited) # Endif // Vremakehr // definition of the image function returns a return value passed to the type of code // lResult is between 0X0000 ~ 0X1FFF #ifndef IMGEMAKEHR #define IMGSMAKEHR (lResult) MAKE_HRESULT (SEVERITY_SUCCESS, FACILITY_IMG, ADDTEMPCLASS (lResult)) #define IMGEMAKEHR (lResult ) Make_hResult (severity_error, facility_img, addtempclass (limited) # Endif // Imgemakehr // When a return code occurs, go to the end / / Require return code number with LRESULT, mark number with end # define if_error_goto_endiff (failed (LRESULT)) goto end; // Display return code Description information #define display_hresult_Message IF (LRESULT) CMDispResultMessage (LRESULT); Typedef Long LRESULT; / / =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===== // Keep and Windows System (COM) unanimous #define cm_ok s_ok # define cm_false E_FAIL #define vr_ok s_ok # define vr_false E_FAIL #define img_ok s_ok # define img_false E_FAIL #define cm_unknow_error cmemakehr (0x000) // Unknown error // Memory error #define cm_mem_alloc_fail cmemakehr (0x001) // Memory Allocation Failure #define cm_Mem_Free_Fail CMemakehr (0x002) // Memory release failed #define cm_invalid_pointer cmemakehr (0x003) // invalid pointer // file operations #define CM_CREATE_FILE_FAIL CMEMAKEHR (0X010) // file creation failed #define CM_OPEN_FILE_FAIL CMEMAKEHR (0X011) // file open failed #define CM_CLOSE_FILE_FAIL CMEMAKEHR (0X012) // file close failed #define CM_DELETE_FILE_FAIL CMEMAKEHR (0X013) // file delete failed #define CM_FILE_HAS_EXISTED CMEMAKEHR (0X014) // file already exists #define CM_COPY_FILE_FAIL CMEMAKEHR (0X015) // file copy failed #define CM_FILE_NOT_OPEN CMEMAKEHR (0X016) // file does not open #define CM_READ_FILE_FAIL CMEMAKEHR (0X017) // file read failure #define CM_FIND_FILE_FAIL CMEMAKEHR (0X018) // file lookup fails #define CM_FILE_HAS_ERROR CMEMAKEHR (0X019) // file itself is wrong #define CM_WRITE_FILE_FAIL CMEMAKEHR (0X020) // // file write failed array operation #define CM_ARRAY_BEYOND CMEMAKEHR (0X060) // Array Crossing // Function Operation #define cm_param_beyond cmemakehr (0x030) // Parameter offline // database operations #define CM_OPEN_DATABASE_FAIL CMEMAKEHR (0X040) // open the database failed #define CM_OPEN_TABLE_FAIL CMEMAKEHR (0X041) // data table open failed #define CM_TABLE_BEYOND CMEMAKEHR (0X042) // Data Sheet access violation #define CM_CREATE_DSN_FAIL CMEMAKEHR (0X043) / / Create a data source failed #define cm_table_exist cmemakehr (0x044) // table already exists #define cm_databaseHR (0x045) // Database is not open // Other operation #define cm_beyond_param cmemakehr (0x100) // Parameter Crossing #define cm_point_is_invaliad cmemakehr (0x101) // point is illegal point // Image Operation #define cm_create_bmp_fail cmemakehr (0x200) // Creating a bitmap failed // Thread operation #define cm_thread_is_lock cmemakehr (0x300) // thread back lock // Mathematics calculation #define cm_edgenum_notenough cmemakehr (0x500) // is not enough // Network operation #define cm_connect_fail cmemakehr (0x700) // Connection failed // 3D equipment operation #define dd_create_device_fail cmemakehr (0x400) // Create device failed #define dd_delete_device_fail cmemakehr (0x401) // Delete device failed #ENDIF / / __ ERRORDEFINE_H__ #ifndef __ERRORMATCH_H __ # define __ERRORMATCH_H __ # include "errotfine.h" #include "windows.h" //rrormatch.h // Used to match the error #define lResultCount 128 # define IF_ERROR_DISPLAY_MESSAGE if (FAILED (lResult)) {DisplayChineseMessage (lResult); goto END;} # ifndef SAFE_DELETE #define SAFE_DELETE (p) {if (p) {delete (p); (p) = NULL; }} # Endif # ifndef Safe_Delete_Array #define Safe_Delete_Array (p) {if (p) {delete [] (p); (p) = null;}} # endif // ============ ============================================================================================================================================================================================================= ============================================================================================================================================== TypeDef struct _Resultinfos // Display return code information {long LRESULTNO; // Returns CHAR SZRESULTMESSAGECHINESE [40]; // Return to code Char SzResultMeengLish [40]; // Return to code} ResultInfos; / / =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===== static RESULTINFOS sResultInfo [lResultCount] = {{CM_MEM_ALLOC_FAIL, "memory allocation failure", "Memeroy"}, {CM_MEM_FREE_FAIL, "memory release failure", "Memeroy"}, {CM_INVALID_POINTER, "Invalid Pointer", "Memeroy"}, {Cm_create_file_fail, "Memory Allocation Fail", "Memeroy"}, {cm_open_file_fail, "file open failed", "memeroy"}, {cm_close_file_fail, "file closure failed", "memeroy"}, {cm_file_has_existed, "file already exists" , "Memeroy"}, {cm_copy, "memeroy"}, {cm_file_not_open, "file is not open", "memeroy"}, {cm_read_file_fail, "file read failed", "memeroy"}}} CM_FIND_FILE_FAIL, "File Finding Failed", "Memeroy"}, {cm_file_has_error, "file itself"}, {cm_write_file_fail, "file write failed", "memeroy"}, {cm_Array_beyond, "Array" , "Memeroy"}, {cm_param_beyond, "Parameter", "Memeroy"}, {cm_open_database_fail, "Database Open Failed", "Memeroy"}, "Memeroy"}, "Memeroy"}, {cm_table_beyond , "Data Table Access", "MEMEROY"}, {cm_create_dsn_fail, "Create Data Source Failed", "Memeroy"}, {cm_table_exist, "Table Exes", "Memeroy"}, {cm_database_not_open, "Database is not open" , "Memeroy"}, {cm_create_bmp_fail, "Create Bitmap Fails", "Memeroy"}, {cm_thread_is_lock, "thread back lock", "memeroy"}, {cm_point_is_invaliad, "point is illegal Point "," "}, {dd_create_device_fail," Create device failed ","}, {dd_delete_device_fail, "Delete device failed", "}}; static char * getCHINESEMESSAGE (HRESULT LRESULT) {for (long Li = 0; Li static char * GetEnglishMessage (HRESULT lResult) {for (long lI = 0; lI Static void DisplayEnglishMessage (HRESULT LRESULT) {MessageBox (Null, GetEnglishMessage (LRESULT), "Error!", MB_OK; #ENDIF / / __ ERRORMATCH_H__