And_catchand_catch
And_catch (Exception_class, Exception _Object_Point_Name)
Description:
Define a code block that is used to get an additional exception type in the current TRY block. Use the Catch Macro to get an exception type, then use the and_catch macro to access the subsequent exception handling code Access an exception object (if appropriate) has obtained more information about the particular reason of the abnormality. Call the Throw_last macro in the and_catch block to move the processing process to the next external exception frame. And_catch tagged the end of the Catch or the AND_CATCH block.
Note:
The and_catch block is defined as a C scope (described by curly brackets). If the user defines a variable in this scope, remember that they can only be accessed in this scope. He also used the exception_Object_point_name variable.
Assert
Assert (BooleaneXpression)
Description:
Calculate the value of the variable. If the value of the structure is 0, then this macro can print a diagnostic message and failure to run. If the condition is not 0, then nothing. The form of diagnostic message is: assertion failed in file in line where Name is a meta file name, NUM is a snap number that is failed in the source file. In the Release version, Assert does not calculate the value of the expression does not interrupt the program. If you must calculate the value of this expression and use Verify instead of ASSERT regardless of the environment.
Note:
Assert can only be used in Debug
AskERT_VAILD
AskERT_VAILD (POBJECT)
Description:
Used to detect the validity of the internal state of the object. Assert_Valid calls the AssertvalID member function of this object (transfer them as its own variable). Assert_Valid in the release version does not do. In the Debug version, he checks the pointer to check in a different way in NULL and calls the object's own Assertvalid member function. If there is any failure in these tests, he will display a warning message in the same way as Assert.
Note:
This function is only valid in the Debug version.
Begin_MESSAGE_MAP
Begin_MESSAGE_MAP (THE CLASS, BASECLASS)
Description:
Start the definition of the user message mapping using Begin_Message_Map. In the tool (.cpp) file that defines the user class function, the message map is started with the begin_message_map macro, and then the macro item is added to each message processing function, then the message mapping is completed in an end_MESSAGE_MAP macro.
Catch
Catch (Exception_Class, Exception_Object_Pointer_Name)
Description:
Use this to define a code block, which is used to get an exception type in the current TRY block. An exception handling code can access an exception object, how is appropriate, more messages about exceptions. Call the throw_last macro to put the process procedure with an external exception frame, if exception-class is class CEXCEPTIOON, then all exception types will be obtained. Users can use the COBject :: iskindof member function to determine that particular exception is excluded. A best way to get an abnormality is to use the order-to -_catch statement, each with a different exception type. This exception type pointer is defined by macro, and the user does not have to be defined.
Note:
This CATCH block is defined as a C range (description by curly brackets). If the user defines a variable in this range, they can access only within the range of eating. He can also use the pointer name of the abnormal object. Debug_new
#define new debug_new
Description:
Help look up memory errors. The user uses debug_new in the program, and the user usually uses the New operator to allocate from the pile. In Debug mode (but define a debug symbol), Debug_New records file names and line numbers for each object it assigns. Then, when the user uses the CMemoryState :: DumpAllObjectsince member function, each place allocated by the object assigned by Debug_new displays the file name and line number. In order to use Debug_New, you should insert the following instructions in the user's resource file: #define new debug_new Once the user inserts this instruction, the preprocessor will insert debug_new where the NEW is used, while the MFC is operated. But when users compile one release of their programs, Debug_new makes simple New operations and does not produce file names and line number messages.
Declare_dynamic
Declare_Dynamic (class_name)
Description:
However, when a class is derived from the COBject, this macro adds access to the access runtime feature of an object class. Enclude this module in the .cpp file that you need to access the word class object all in all the .cpp files you need to access the word class object all. If you use DELCARE_DYNAMIC and IMPLEMENT_DYNAMIC macros as described, the user can use the runtime_class macro and the cobject :: iskindof function to determine the object class at runtime. If the declare_dynamic is included in the class definition, the importmetn_dynamic must be included in the class tool.
Declare_Dyncreate
Declare_Dyncreate (class_name)
Description:
Use the Declare_Dyncrete macro to allow COBJECT derived objects to be automatically established at runtime. Host use this feature to automatically create new objects, for example, when it reads an object from disk during serialization, files and views and frame windows should support dynamic establishment because the framework needs to be created automatically. Include the DECLARE_DYNCREATE Macro into the class .h file, then you need to access this type of .cpp file in this object. If DECLARE_DYNCREATE is included in the class definition, the import_dynce must be included in the class tool.
Declare_MESSAGE_MAP
Declare_message_map ()
Description:
Each CCMDTARGET derived class in the user program must provide message mapping to process messages. Use the declare_message_map macro at the end of the class definition. Then, in the .cpp file defined by the class member function, use the begin_message_map macro, the macro of the macro item of each user message processing function and the end_message_map macro.
Note:
If you define any member after declare_message_map, you must specify a new access type (public, private, protected).
DECLARE_SERIAL
DECLARE_SERIAL (class_name)
Description:
Declare_serial is a necessary C title code for a serialized COBJECT class class. Serialization is to read and write a file from one file from one file. Using the Declare_Serial Macro in .h file, this file is included in all .cpp files that need to access such objects. If DECLARE_SERIAL is included in the class definition, the import_serial must be included in the class tool. The Declare_Serial macro contains all the features of all declare_dynamic, import_dycreate. END_CATCH
END_CATCH
Description:
Identify the last Catch or the end of the AND_CATCH block.
END_MESSAGE_MAP
END_MESSAGE_MAP
Description:
Use the end_message_map macro to end the user's message mapping definition
Implement_dynamic
Implement_dynamic (class_name, base_class_name)
Description:
The necessary C code is generated by the dynamic COBJECT derived class access class and location by running in the serial structure. Use the import_dynamic macro in .cpp file, then a link result object code
Implement_dyncreate
Implement_dyncreate (class_name, base_class_name)
Description:
Use the import_dyncreate macro to allow the COBJECT derived class object to allow COBJECT derived class objects to be automatically established at runtime. The host uses this feature to automatically establish an object, for example, when it reads an object from the disk during the serialization process, he adds the Implement_DyncReate Macro in the class tool. If the user uses the declare_dynce_dyncreate macro, then use the runtime_class macro and the COBject :: iskindof member function to determine the object class at runtime. If DECLARE_DYNCREATE is included in the definition, IMPLEMENT_DYNCREATE must be included in the class tool.
IMPLEMENT_SERIAL
Implement_serial (class_name, base_class_name, wschema)
Description:
The necessary C code is established by dynamic COBJECT Dynamic CoBject Dynamic Coca in the serial structure. Use the Implement_Serial Macro in the .cpp file, then link the result object code once.
ON_COMMAND
ON_COMMAND (ID, Memberfxn)
Description:
This macro is mapped by ClassWizard or manually inserting a message. It indicates that the function will process a command message from a command user interface (such as a menu item or Toolbar button). When a command object accepts a Windows WM_COMMAND message by the specified ID, ON_COMMAND will call the member function MEMBERFXN to process this message. In the user's message map, there should be an ON_COMMAND macro statement for each menu or accelerator command (must be mapped to a message processing function).
ON_CONTROL
ON_Control (WNOTIFYCODE, ID, MEMBERFXN)
Description:
It indicates which function will process a regular control representation message. Control identification messages are messages that are sent from one control husband to the mother window.
ON_MESSAGE
ON_MESSAGE (Message, Memberfxn)
Description:
Indicate which function will process a user-defined message. User-defined messages are typically defined within WM_USER to 0x7FF. User-defined messages are any messages that are not standard Windows WM_MESSAGE messages. In the user's message map, each must be mapped to a messaging function. User-defined messages should have an on_message macro statement. ON_REGISTERED_MESSAGE
ON_REGISTERED_MESSAGE (NMESSAGEVARIBLE, MEMBERFXN)
Description:
The Windows RegisterWindowsMesage function is used to define a new window message, which is unique in the entire system. This macro indicates which function handles the registered message. Variable NMESSAGEVIABLE should be defined in a NEAR modifier.
ON_UPDATE_COMMAND_UI
ON_UPDATE_COMMAND_UI (ID, Memberfxn)
Description:
This macro is usually inserted into a message mapping via ClassWizard to indicate which function will process a user interface change command message. In the user's message map, each user interface changes command (the signal is mapped to a message handler) should have an on_update_command_ui macro statement.
ON_VBXEVENT
ON_VBXEVENT (WNOTIFYCODE, MEMBERFXN)
Description:
This macro is usually inserted into a message mapping via ClassWizard to indicate which function will process a message from VBX control. Each VBX control message that is mapped to a messaging function in the user's message map should have a macro statement.
Runtime_class
Runtime_class (class_name)
Description:
Use this macro to get the runtime structure from the C class. Runtime_class returns a pointer to the CRUNTIMECLASS structure for classes specified by class_name. Only the COBJECT derived class defined by declare_dynamic, declare_dyncreate or declare_serial_DyncReate or Declare_Serial_DyncReate or Declare_Serial_DyncReate or Declare_Serial_Dyncreate or the pointer to a CRUNTIMECLASS structure.
Throw
Throw (Exception_Object_pointer)
Description:
Send a designated exception. The THrow interrupt program is running to pass the control to the associated CATCH block in the user program. If the user does not provide a Catch block, the control is passed to an MFC module, and he prints an error and terminates run.
Throw_last
Throw_last ()
Description:
This macro allows users to send a local established exception. If the user tries to exclude an exception that is discovered, this exception will overflow and deleted. With throw_last, this exception is transmitted directly to the next Catch handler.
Trace
Trace (exp)
Description:
Send a formatted string to the dump device, for example, a file or debug monitor, and provide a function similar to the Printf. Like the printf of the C program under MS_DOS, the Trace Macro is a convenient form of tracking variable values at the program runtime. In the Debug environment, the Trace macro outputs to AFXDUMP. He doesn't do anything in the Release version.
Note:
This macro is only valid in the DEBUG of the MFC.
Trace0
TRACE0 (EXP)
Description:
Similar to TRACE, but he puts the tracking string in code segment, not DGROUP, so less DGROUP space. TRACE0 is a variant of a set of tracking macros that can be used to debug output. This group includes trace0, trace1, trace2, and trace3, which differ from the number of parameters taken. Trace0 takes only one format string and can be used for simple text messages. TRACE1 takes a formatted string plus a variable - a variable that will be dump. Similarly, TRACE2, Trace3 takes 2 or 3 parameters (after formatting a string). If the user has used the application's release, it only dumps the data to AFXDUMP. Note:
This macro is only valid in the DEBUG of the MFC.
Trace1
Trace1 (EXP, PARAM1)
Description:
See Trace0
Trace2
Trace2 (EXP, PARAM1, PARAM2)
Description:
See Trace0
TRACE3
Trace3 (EXP, PARAM1, PARAM2, PARAM3)
Description:
Try
Try
Description:
Use this macro to establish a TRY block. A try recognizes a code block that can exclude exceptions. These exceptions are processed in subsequent Catch and And_CATCH blocks. Transfer is allowed: Exceptions can pass an external TRY block or ignore them or use the throw_last macro.
Verify
Verify (BooleaneXpression)
Description:
In the DEBUG version of the MFC, the Verify macro calculates its variable value. If the result is 0, then macro prints a diagnostic message and abort the program. If the conditions are not 0, then what jobs are not doing. Diagnostics There are as follows: assertion failed in file in line where Name is the name of the source file, NUM is a deadline number that failed in the source file. In the RELEASE version of the MFC, verify calculates the expression value but does not print or abort the program. For example, if the expression is a function call, then call success.
Read more ... ESQM published in 12:55 Has been viewed 65 reviews (0) / Quote (1) Join Bo Cai Center
PRAGMA Instructions 2005 January 04 - Select Blog from VcForever In writing programs, we often use the #pragma instruction to set the status of the compiler or indicate some specific actions to complete the compiler. Some common parameters of this directive, I hope to help everyone! 1. Message parameters. Message It can output the corresponding information in the compilation information output window, which is very important for the control of source code information. The method of use is: #pragma Message ("Message Text) When the compiler encounters this instruction, print the message text in the compilation output window. When we define many macros in the program to control the source code version, we may have forgotten that there is no correct settings. At this time we can use this instruction to check when compiling. Suppose we want to judge what you have in the source code _X86 this macro can use the following method #ifdef _x86 #pragma message ("_ x86 macro actid!") #ENDIF When we define _x86 this macro, The application will display "_ x86 macro actid!" In the compilation output window when compiling. We will not scratch it because some of the specific macro I don't remember. The other uses more #pragma parameters for Code_SEG. Formats, such as: #pragma code_seg ([{Push | POP},] [Identifier,]] ["segment-name" ["segment-class"]) This instruction is used to specify the function stored in the .obj file Observing the OBJ file can use the Dumpbin command line program that comes with the VC, the function is in the .Obj file, the default storage section is .Text section If the code_seg does not have a parameter, the function is stored in the .Text section PUSH (optional parameters) In the stack of a record in the internal compiler, the optional parameter can pop up a record from the top of the stack or the number of items, which can be an identifier or the name of Identifier ( Selection parameters) When using the PUSH instruction, an identifier of the recorded assignment of the stack is pressed, and when the identifier is deleted, the record in the relevant stack will be popped up "segment-name" (optional parameters " ) Represents the name of the function store, for example,: // By default, the function is stored in the .Text section void func1 () {// stored in .text} // In. MY_DATA1, #pragma code_seg (" .my_data1 ") Void func2 () {// stored in my_data1} // R1 is the identifier, put the function in. MY_DATA2 #Pragma code_seg (push, r1," .my_data2 ") Void func3 () {//// Stored in my_data2} int Main () {} II. #pragma overce This is a relatively common directive, as long as the first instruction is added to the first instruction, it is possible to ensure that the header file is compiled once. #pragma HDRSTOP represents the pre-translated header file until this, and the header files are not precompiled. The BCB can pre-translate the header file to speed up the speed of the link, but if all header files are pre-compiled, it may account for too much disk space, so use this option to exclude some header files. There is a dependency between the units, such as unit A dependent unit B, so unit B is compiled by unit A. You can use #pragma startup to specify compilation priority, if #pragma package (smart_init) is used, BCB will compile according to the size of the priority.
5. #pragma warning instruction This instruction allows the behavior instruction format of a warning message for selective modification compiler: #pragma Warning (WARNING-Specifier: Warning-specifier: warning-number-list. .. # Pragma Warning (Push [, N]) #pragma Warning (POP) The warning indicates that there are several: overce: only display only one (warning / error, etc.) Message DEFAULT: Reset the compiler warning Behavior to the default status 1, 2, 3, 4: Four Warning Level Disable: Prohibits the specified warning message error: Assign the specified warning message as an error report If everyone is not understanding above, you can refer to the example below and Description #pragma Warning (DISABLE: 4507 34; Once: #pragma Warning (Disable: 4507 34) // Does not display 4507 and 34 Warning Information #pragma Warning (ONCE: 4385) / / 4385 Warning information only reports #pragma Warning (Error: 164) // Putting 164 warning information as an error. At the same time, this Pragma Warning also supports the following format: #pragma Warning (push [, n]) #pragma Warning POP) Here n represents a warning level (1 --- 4). #pragma Warning (Push) Save existing warning status of all warning information. #pragma Warning (Push, N) Save existing warnings for all warning information State, and put the global warning level to n. #Pragma Warning (POP) pops up the last warning message in the stack, and cancels all changes made between the stack and the outlet.
For example: #pragma Warning (Push) #pragma Warning (Disable: 4705) #pragma Warning (Disable: 4706) #pragma Warning (Disable: 4707) #pragma Warning (POP) At the end of this code, re-save all warnings Information (including 4705, 4706, and 4707) often get a lot of warning information when programming with standard C , and these warning information is unnecessary, so we can use #pragma Warning (Disable: 4786) to disable This type of warning will also get unnecessary warning information when using ADO in the VC. This time we can eliminate the type of warning information from #pragma Warning (Disable: 4146). Pragma Comment (...) The format of the instruction is: #pragma comment ("Comment-Type") This instruction puts a comment record in an object file or executable, Comment-Type: You can specify as five pre- One of the five predefined identifiers of the defined identifier are: Compiler: Place the version number and name of the compiler into the target file, this section The annotation record will be ignored by the compiler if you provide CommentString for the record type. Parameters, the compiler will generate a warning, for example: #pragma comment (Compiler) Exestr: Place the commentString parameter into the target file, this string will be placed in the executable when the link is linked, when the operating system is loaded When the file is executed, the parameter string does not be loaded into memory. However, the string can be found and printed by the program, which is described in Dumpbin, you can use this identifier to embed the information such as version number. In the executable! Lib: This is a very common keyword, used to link a library file to the common library commonly used in the target file, which can help us into a library file. For example: #pragma comment (lib, "user32.lib") This instruction is used to join the user32.lib library file to this project: put a link option into the destination file, you can use this instruction instead of command The link option in which the line is incorporated or in the development environment, you can specify the / include option to force the included object, such as: #pragma comme (Linker, "/ include: __ mysymbol") You can set the following link in the program Options / DefaultLib / Export / Include / Merge / Section These options are not explained here, please see MSDN! User: Place the general comment information in the target file containing the text information of the comment, this comment Record will be ignored by the linker, for example: #pragma comment (user, "compiled on" __date__ "esqm on 12: 48 published 53 reviews (0) / Reference (0) Join Bo Cell Center
Multi-task, process, and thread December 20, 2004 Windows 95 / NT's pre-scheduled multitasking in 32-bit Windows systems, using a pre-standard multitasking, which means that the program is determined by the system for the CPU. of. The system assigns a certain CPU time for each program. When the program runs exceeds the specified time, the system will interrupt the program and turn the CPU control to another program. Unlike collaborative multitasking, this interrupt is assembled. The program does not have to call functions such as PeekMessage to give up control of the CPU, and the time of time can be taken, and will not cause the system to hang. Process and threads In a 32-bit Windows system, the term multi-task is that the system can run multiple processes simultaneously, while each process can also perform multiple threads simultaneously. The process is the running instance of the application. Each process has its own virtual address space. Each process has a primary thread, but you can build another thread. The thread in the process is performed in parallel, and each thread takes up the CPU time by the system. The process is the running instance of the application. Each process has its own virtual address space. Each process has a primary thread, but you can build another thread. The thread in the process is performed in parallel, and each thread takes up the CPU time by the system. Threads can be regarded as the basic entity of the operating system allocated CPU time. The system is constantly switching between each thread, and it is compiled for the interrupt of threads. The system allocates a CPU time slice for each thread, and a thread only has the control of the CPU only in the assigned time tablet. In fact, in the PC, only one thread is running at the same time. Since the system is small (20 milliseconds) for each thread (20 milliseconds), it seems that it is a plurality of threads run at the same time. All threads in the process share the virtual address space of the process, which means that all threads can access global variables and resources of the process. This aspect provides convenience for programming, but on the other hand, it is easy to conflict. Although the time of time consuming in the process does not cause the system to hang, but this can cause the process itself hang. So, if the process is necessary to do long-term work, it is necessary to respond to the user's input, then it can start a thread to be responsible for the work, while the main thread can still interact with the user. Thread creation and termination of the line of the user interface thread and the worker thread. The user interface thread has its own message pump to handle interface messages, and can interact with the user. Worker threads have no messages, generally used to complete the background work. The thread of the MFC application is represented by the object cwinthread. In most cases, the program does not need to create a CWINTHREAD object yourself. A CWINTHREAD object is automatically created when calling an AFXBEGINTHREAD function. The application's thread is represented by the object CWINTHREAD. In most cases, the program does not need to create a CWINTHREAD object yourself. A CWINTHREAD object is automatically created when calling an AFXBEGINTHREAD function. When one of the following events occurs, the thread is terminated: thread calls ExitThread. The thread function returns, that is, the thread implies EXITTHREAD. EXITTHREAD. EXITPROCESS is displayed or implied in any thread of the process. TerminateTHREAD is called with the handle of the thread. Call TerminateProcess with the process handle. TerminateProcess. The thread function returns, that is, the thread implies EXITTHREAD. Thread synchronization is due to virtual address space of all thread sharing processes in the same process, and thread interrupts are assembled, two threads may have access to the same object (including global variables, shared resources, API functions, and MFC). Object, etc.), this is likely to cause a program error.
For example, if a thread is not completed by reading a large size global variable, another thread writes the variable, then the first thread reads in the variable value may be during modification. Unstable value. Threads that belong to different processes will also have the same problem when accessing the same memory area or shared resource. Therefore, in multi-threaded applications, some steps often need to be taken to synchronize threads. The situation that needs to be synchronized includes the following: When multiple threads access the same object simultaneously, an error may occur. For example, if a thread is reading a vital shared buffer, another thread writes data to the buffer, then the program's operation results may be wrong. The program should try to avoid multiple threads to access the same buffer or system resource. Write multi-threaded applications in a Windows 95 environment also requires reward issues. Windows NT is a real 32-bit operating system that solves the problem of system re-entry. Windows 95 is not able to resolve the re-entry problem since the part of the 16-bit code of Windows 3.x is inherited. This means that two threads in Windows 95 cannot perform a system function at the same time, otherwise it is possible to cause the program error, or even the system crash. Applications should try to avoid that more than two threads simultaneously call the same Windows API function. Due to size and performance reasons, the MFC object is not a thread safe at the object level, only in the class. That is, two threads can safely use two different CString objects, but simultaneously use the same CString object. If you must use the same object, you should take the appropriate synchronization. Coordination between multiple threads is required. For example, if the second thread needs to wait for the first thread to complete to a step, the thread should be temporarily suspended to reduce the occupancy time of the CPU, improve the execution efficiency of the program. When the first thread completes the corresponding step, a certain signal should be issued to activate the second thread. Waiting Functions The WIN32 API provides a waiting function that enables thread to block its own execution. These functions are only returned when only one or more synchronization objects as their parameters (see subside). After the predetermined wait time, the function will return no matter whether there is no signal. When the wait function is not returned, the thread is waiting state, at which time the thread consumes very little CPU time. Use the wait function to ensure synchronization of the thread, and improve the running efficiency of the program. The most commonly used wait function is WaitForsingleObject, which is declared by: DWORD WAITFORSINGLEOBJECT (Handle Hhandle, DWORD DWMILLISECON); Synchronous Object Synchronization Objects Used to coordinate multithreaded execution, it can be shared by multiple threads. Waiting for threads The synchronization object should be accessed by the synchronization object with the handle of the synchronous object. The status of the synchronous object is either signal, or there is no signal. Synchronous objects mainly have three: events, Mutex, and signal lights. Event Object (Event) is the simplest synchronization object, which includes both signal and no signal. Before the thread accesses a certain resource, it may be necessary to wait for an event to occur, and the event object is most appropriate. For example, the monitoring thread is activated only after the data is received in the communication port buffer. The event object is built with the CreateEvent function. This function can specify the type of event object and the initial state of the event. If it is a manual reset event, it always maintains a signal state until it resets an eventless event with the resetEvent function. If it is an automatic reset event, then its status will automatically become no signal after a single wait thread is released. Use SetEvent to set the event object to a signal state. When an event is established, you can get a name for the object, so that threads in other processes can open the event object handle of the specified name with the OpenEvent function.
The status of the Mutex object is signal when it is not owned by any thread, and when it is owned, there is no signal. Mutex objects are ideal for coordinating multiple threads mutual exclusive access to shared resources. The thread uses the CreateMutex function to create a MUTEX object. When you create Mutex, you can get a name for the object, so that threads in other processes can open the Mutex object handle of the specified name with the OpenMuteEx function. After completing access to the shared resource, the thread can call ReleaseMutex to release the MUTEX to allow other threads to access shared resources. If the thread is terminated without releasing MUTEX, the MUTEX is considered to be discarded. Signal light objects maintain a count starting from 0, and the object is signals when the count value is greater than 0, and when the count value is 0, there is no signal. Signal light objects can be used to limit the number of threads accessed to the shared resource. The thread uses the CreateSemaphore function to establish a signal object, when calling the function, you can specify the initial count and maximum count of the object. You can also get a name for the object when establishing a signal light, and the thread in other processes can open the signal script of the specified name with the OpenSemaphore function. Generally, the initial count of the signal light is typically set to the maximum. Each time the signal is signal to returns the wait function, the signal is reduced by 1, and the ReleaseSemaphore can increase the count of the signal light. The smaller the count value, the more programs that visit the shared resource. In addition to the above three synchronous objects, objects in Table 12.3 can also be used for synchronization. In addition, sometimes you can use a file or communication device as a synchronization object. When an object is no longer used, you should use the CloseHandle function to close the object handle. The critical section and interlock variable access critical festival are similar to Mutex, but it can only be used by threads in the same process. The critical festival prevents shared resources from accessing simultaneously. The process is responsible for allocating memory space for the key section. The key section is actually a critical_section type variable, which can only be owned by one thread at a time. Before the thread uses the critical section, you must call the InitializeCriticalSECTION function to initialize it. If there is a key code in the thread does not want to be interrupted by other threads, then the EntercriticalSECTION function can be called to apply for ownership of the critical section, and then use the LeaveCriticalSECTION function after running the critical code to release ownership. If the critical object has been owned by another thread while calling EntercriticalSection, then the function will be awarded indefinitely. Simple and effective synchronization mechanisms can be established using interlock variables. Use the function interface to add or reduce the value of a 32-bit variable shared by multiple threads, and can check if the result is 0. Threads don't have to worry about being interrupted by other threads. This mechanism can also be used if the variable is located in the shared memory. Serial Communication and Overlapping I / OWIN 32 systems provide new services for serial communication. The traditional OpenComm, Readcomm, WriteComm, Closecomm, etc. have been out of time, the WM_COMMNOTIFY message has also disappeared. Instead, the file I / O function is provided open and closes the basic interface of the communication resource handle and the reading and writing operation. The new file I / O function (CreateFile, ReadFile, WriteFile, etc.) supports overlapping input and output, which makes threads can be liberated from the time I / O operation, which greatly improves the operational efficiency of the program. The Opening and Close Win32 system extends the concept of the file. Whether it is document, communication equipment, named pipes, mail slots, disks, or consisters, are used to open or create with API functions createfile. The initialization of serial ports is often required to initialize the serial port after opening the communication device handle. This requires a DCB structure. The DCB structure includes information such as the number of data bits, parity, and stop bits of each character.
When querying or configuring the properties of the serial port, use the DCB structure as a buffer. Calling the getcommstate function can get the configuration of the serial port, which fills the current configuration into a DCB structure. Generally, after opening the serial port with CREATEFILE, you can call the getcommState function to get the initial configuration of the serial port. To modify the configuration of the serial port, you should first modify the DCB structure, then call the SetCommState function to set the serial port with the specified DCB structure. In addition to settings in the DCB, the program generally needs to set the size and timeout of the I / O buffer. Windows uses I / O buffers to temporarily store data input and output data, if the rate of communication is high, the larger buffer should be set. Call the SetupComm function to set the input of the serial port and the size of the output buffer. When reading and writing serial ports with ReadFile and Writefile, you need to consider the timeout problem. If you do not read or write a specified number of characters within the specified time, the operation of the ReadFile or WriteFile will end. To query the current timeout setting should call the getcommtimeouts function, which will populate a COMMTIMEOUTS structure. Calling setcommtimeouts You can set the timeout with a COMMTIMEOUTS structure. There are two times time: interval timeout and total timeout. The interval timeout refers to the maximum delay between the two characters at the time of reception, and the total timeout is the maximum time to read a total of the total cost. Write operation only supports total overtime, and both operations are supported by both operation. Using the COMMTIMEOUTS structure can specify the timeout of the read / write operation. The overlapping I / O When reading and writing serial ports with readfile and writefile, it can be executed synchronously or overlap (asynchronous) execution. When executed synchronously, the function returns until the operation is completed. This means that the thread will be blocked when synchronous execution, resulting in a decrease in efficiency. When the overlap is executed, even if the operation is not completed, the called function will return immediately. Timely I / O operation is carried out in the background, so that threads can dry. For example, threads can perform I / O operations simultaneously on different handles, and even simultaneously read and write simultaneously on the same handle. The meaning of the word "overlapping" is here. The readFile function is only necessary to read the specified number of characters in the serial port input buffer, even if the operation is completed. The WriteFile function will not only copy the specified number of characters into the output buffer, but also to wait for these characters to send out the operation after sending out from the serial port. The readFile and WriteFile function are determined by the createfile function for performing overlapping operations. If the file_flag_overlapped flag is specified while calling CreateFile, call ReadFile and WriteFile to overlap, if no overlapping flag is specified, the read and write operation is synchronized .sqm is published in 22: 39 249 reviews (2) / Quote (5) Join Bo Cai Center COM Components Tour Debridge Procedure November 22, 2004 ESQM in 17:27 published 181 reviews (2) / Quote (12) Join Bo Cai Center
MIDL (Microsoft Interface Definition Language) Basis All data, methods, interfaces, and libraries of November 21, 2004 are described by attribute information. The attribute information is enclosed in parentheses as the prefixes of the object they describe. [in]: Tell the MIDL compiler to generate code, just collect the data column from the customer to the object, there is no need to send the same data column collection to the customer [OUT]: Let a data return to the customer from the object. -------------------------------------------------- ----------------------- iUnknown interface defines import "unknwn.idl"; [Local, Object UUID (FAEAE6B7-67BE-42A4-A318-3256781E945A), Pointer_Default (unique)] interface iUnknown {typedef (unique) iUnknown * lpunknown cpp_quote ("// iid_iunknown, and all system IIDs are provided by uuid.lib") cpp_quote ("// Put this Links to your agent, customer and service ") CPP_QUOTE (" / ") HRESULT Queryinterface ([in] refiid IID, [OUT, IID_IS (RIID)] void ** ppobject); ulong addRef (); ulong release ();} ---------------------------------------------- ------------------------------- [Object]: The specified interface is a COM interface. If you miss this attribute information, the IOCR interface is just a simple MS RPC interface; if there is no information, the generated column code will be incompatible with the standard column code provided by the COM function library (running). [UUID]: This is the static and unique IID of IOCR interface. It is a machine generated number in time and space. [Local]: Tell the MIDL compiler, do not generate interface proxy and stub. [POINTER_DEFAULT ()]: Sets all the default pointer properties information that has not been displayed in the Embedded Pointer. Embedded Pointer includes a structural (union), a unique property information: 1) [REF] pointer is a reference pointer and cannot be empty. 2) The [UNIQUE] pointer is a Simple Pointer, which can be empty. However, the agent does not provide support for repeated pointer detection. For example, if PTR1 / PTR2 points to the same data, two of the same copies of the data will be sent to the remote object. 3) The [PTR] pointer is a full pointer. If PTR1 / PTR2 points to the same data, only one copy will be sent to the remote object. CPP_QUOTE: Guide the MIDL compiler to convert the defined string into the generated header file.
Specifically, this four lines will make C annotations in the header generated by the MIDL compiler. [IID_IS ()]: This is a pointer attribute, which is similar to [PTR] [REF] [Unique], only for pointers. The IID_IS (RIID) property column is concerned. In fact, the stub needs to accurately know that the interface pointer (RIID, some IID) is being scheduling (RIID, some IID) [size_is ()]: Tell the collector, the pointer actually points to some bytes Piece. The column distributes memory according to the size of this block. [String]: Tip Column: The modified parameter is a string, which is terminated by null. ESQM published in 21: 11 Has been viewed 132 reviews (0) / Reference (8) Join Bo Cai Center C Type Conversion Operation (Cast Operator) November 21, 2004 Dynamic_cast used to convert polymorphic types (Polymorphic Type) Establish a runtime check to ensure the validity of the conversion. If the conversion is not secure, a BAD_CAST exception is thrown. STATIC_CAST is used to convert non-polymorphic types. No runtime check. Const_cast is used to remove an object's normal (Volatileness). Reinterpret_cast is used to convert any pointer or shaping type into another pointer or a shaping variable. For example: Reinterpret_cast <> (& PSome) Convert a double precision type pointer to void ** ESQM published in 19: 38 Has been viewed 115 reviews (0) / Reference (9) Join Bo Cai Center
COM features and services November 21, 2004 COM: Component Object Model Component Object Model. DCOM: Distributed Component Object Model Distributed Component Object Model is a line protocol Wire Protocol and a set of services that allow each COM component to communicate with each other in a distributed environment. COM features: 1. Position transparency location transparency mainly depends on columns. In order to support columns, COM uses an existing to prove the possible technique called DCE RPC (DCE RPC uses NDR-NetWork Data Reperesentation, network data representation. To transfer data. Morally in different machines and Different data representations provide a general format that provides a general format. Customer stub --- agent, server stub - stub 2, dynamic and remote object activation COM SCM (Service Control Manager Service Control Manager) Supports Remote Activation 3, Security COM Support Several Authentication Level Activation Security SCM Call Level Safety Access Security 4, interface interfaces and implementation are separated, a COM object includes many interfaces that clearly define and cannot be changed. In COM, all interfaces are derived from a special interface called IUNKNOWN, which must support a sound and constantly changing component, and must also include 3 extremely important ways: queryinterface / addref / release. Customer calls QueryInterface to dynamically discover other interfaces supported by the object, and addRef and Release are used to manage the life cycle of an object. 5, one of the important features of the survival support and dynamic discovery objects is the life cycle, because the object must be correctly created and destroyed. COM uses reference counts to support the survival management of objects. 6, binary interoperability binary reuse is an important aspect of software reuse. Binary interoperability in COM is implemented by an interface. Each interface is signed by a binary signature through VTBL (Function Point Table) and VPTR (pointing to VTBL). 7. Connection management COM supports connection management through a simple paranoia check. It requires customers to send a small packet to the server to indicate that it is still active. Be ping (forced response). COM is smart to ping the machine instead of ping object. Each COM machine runs a special coordinator / manager named OXID Analyzer. Ping is coordinated by the OXID analyzer on each machine. 8, concurrent management COM will leave the object with different concurrent semanties, and classify the independent execution environment (socket department). The object is generated, existed and died in its own suite, and you must column it in order to use this object in different suite. 9. Re-use COM currently supports inclusion and aggregation. The inclusion can be used to hide the reuse objects behind the object being developed. Then, you post a series of channels or proxy methods to make your customers' services for hidden objects. When your customer calls these channel methods, you only need to delegate these calls to the reuse inclusive object. Gathering can be used to expose the interface of the reuse object like yourself. For gathering, your object must pass its IUNKNOWN pointer to the reused object so that life management can work normally. 10, the interface storage in COM, the type of object is stored in detail in the interface storage, called the type library (Type Library, extension: .tlb) 11, the storage library is in a distributed environment, one Realizing the location of the object to be implemented. COM supports this concept through the registry.