Basic Content of MFC

Source: Internet
Author: User

1. _ T () function

 

_ T ("") is a macro, whose role is to make yourProgramSupports Unicode encoding.
Because Windows uses the ANSI and Unicode character sets,
The former is the common single-byte mode,
However, it is inconvenient to process double-byte characters such as Chinese characters in this way,
It is easy to have half Chinese characters.
The latter is in dubyte mode to facilitate the processing of dubyte characters.

All character-related functions of Windows NT provide two versions, while Windows 9x only supports ANSI.
If you compile a program in ANSI mode,
_ T does not actually play any role.
If a program is compiled in Unicode mode, the compiler saves the "hello" string in Unicode mode. The difference between _ T and _ L is that _ L is saved in Unicode no matter how you compile it.
 

Lpstr: 32-bit pointer to a string, each character occupies 1 byte

Lpcstr: 32-bit pointer to a regular string, each character occupies 1 byte
Lpctstr: 32-bit pointer to a regular string, each character may take 1 or 2 bytes, depending on whether Unicode is defined
Lptstr: 32-bit pointer each character may occupy 1 or 2 bytes, depending on whether Unicode is defined

 

L indicates that the string resource is Unicode.

For example
Wchar_t STR [] = l "Hello world! ";
This is the character stored in the double section.

_ T is an adaptive macro ~

When
# Ifdef _ Unicode
_ T is L
No # ifdef _ Unicode
_ T is ANSI.

For example

Lptstr lpstr = new tchar [32];
Tchar * szbuf = _ T ("hello ");
The preceding two statements make it correct for Unicode compiling.

In addition, we recommend that you use matching string functions in ms.
For example, when processing lptstr or lpctstr, do not use strlen, but use _ tcslen

Otherwise, strlen cannot process the wchar_t * string in Unicode compiling.

T is a very interesting symbol (tchar, lpctstr, lptstr, _ T (), _ text ()...), it indicates the use of an intermediate type, which neither explicitly indicates the use of MBCS nor explicitly indicates the use of Unicode. Which character set is used? It is determined during compilation.

 

Converts a char string to a unicode string.
T is a macro, not a function.

A double-byte string is required in a function that requires two bytes or a string of two bytes in COM.
For international compatibility. It is actually very simple.
When defining strings in Visual C ++, use _ t to ensure compatibility. VC supports ASCII and Unicode character types, when _ t is used to convert the ASCII encoding type to the Unicode encoding type, the program does not need to be modified.

If you do not plan to upgrade to Unicode in the future, you do not need _ T,

_ T ("Hello World ")
In the ANSI environment, it is ANSI. If it is in UNICODE, it is automatically interpreted as a dual-byte string, both Unicode encoding.
These benefits apply to both the ANSI and Unicode environments.

2 \ What is the difference between string _ T ("ABC") in VC ++ and a common string "ABC.

_ T ("ABC ")
Indicates that if Unicode is defined
It indicates l "ABC", each character is 16 characters, wide character string
---------------------------------------------------------
If not Unicode
It is the ASCII "ABC", each character is 8 characters
"ABC" refers to the ASCII string "ABC"

----------------------------------------------------------

Equivalent
# Ifdef _ Unicode
# DEFINE _ T ("ABC") l "ABC"
# Else
# DEFINE _ T ("ABC") "ABC"
# Endif

----------------------------------------------------------

A character in _ T ("ABC") occupies two bytes, while an English character occupies one byte and a Chinese character occupies two bytes.

 

 

Ii. Stack and stack

1. "Heap" and "stack" in C ++ mainly refer to the areas where data or variables and objects are stored in the memory, as in reality
The difference between the United States and China is that the locations in the memory are different on the surface, but the memory allocation method is very different. Although the United States and China are both countries on the surface, their social systems and various benefits
Different organizations are different. In a word, they are different regions in the memory.

2. "Heap" in C ++: in a program
Heap is a piece of memory, not heap memory. Generally, it is manually allocated by programmers. In C ++, the new operator is generally used (if the malloc series of C is not used, it seems that only new can be used for allocation.
Can only be manually released by programmers, or memory leakage may occur. Of course, to allocate memory, you can only allocate variables and class objects, so they are stored as class objects and variables.
"Stack" in C ++: memory automatically allocated by the program. For example, when calling a function and passing parameters (passing values ), the value of this parameter is allocated on the "stack" memory. When this function exits, the "stack" memory occupied will be released.

 

Iii. Windows Socket

 

Implementation of S socket:

Socket is a bridge between applications and network drivers. It is created in the application and establishes a relationship with the driver through the binding operation. After that, the application sends the socket data from
The socket is handed over to the driver, and the driver sends the data to the network. After the computer receives data related to the IP address and port number bound to the socket from the network, the driver sends the data
Socket, the application can extract the received data from the socket. Network applications use sockets to send and receive data.

ISO/OSI Layer-7 Reference Model (ISO: OSI: Open System Interconnection ):
Physical Layer: Provides binary transmission to determine how bit streams are transmitted over communication channels.
Data link layer: Provides media access, enhances the transmission function of the physical layer, and establishes an error-free transmission line.
Network Layer: Provides IP Addressing and routing. Because data on the network can reach the destination through multiple lines, the network layer is responsible for finding the best transmission route.
Transport Layer: provides reliable data transmission services between the source host and the target host, and isolates the upper-and lower-layer protocols of the network, so that network applications are independent of the lower-layer protocols.
Session Layer: establishes, organizes, and coordinates communications between two communication application processes.
Presentation Layer: processing the representation of transmitted data, that is, the syntax and semantics of information.

Essence of peer-to-peer communication:
Virtual Communication between peer entities.
The lower layer provides services to the upper layer, and the actual communication is completed at the lowest layer.

Protocols used by each layer:
Application Layer: Telnet, FTP, HTTP, DNS, SMTP, and POP3.
Transport Layer: Transmission Control Protocol TCP and User Datagram Protocol UDP.
Network Layer: Internet Protocol IP, Internet Control Packet protocol ICMP, and Internet Group Management Protocol IGMP.

TCP/IP model: application layer, transmission layer, network layer, and network interface layer.
The TCP/IP model and OSI model are compared as follows:
Application Layer: application layer, presentation layer, and Session Layer. Transport Layer: transport layer. Network Layer: network layer. Network Interface Layer: data link layer and physical layer.

Port: an abstract software structure (including some data structures and I/O buffers ).

Socket Type:
(1) stream socket (sock_stream), implemented based on the TCP protocol.
(2) datagram socket (sock_dgram), UDP implementation.
(3) original socket (sock_raw)

Windows Socket "tcp" network programming instance
Some development steps:
"TCP" Server
1. Load the socket library.
2. Create a socket.
3. Bind The address information.
4. Bind a socket.
5. listening socket.
6. "accept" is waiting for user requests.
7. Send data.
8. "Recv" receives data.
9. Close "socket in use" and continue the loop wait.

"TCP" client
1. Load the socket library.
2. Create a socket.
3. Bind The address information.
4. Bind a socket.
5. Send a request.
6. receive data.
7. Send data.
8. Close the socket.
9. "wsacleanup" Ends "socket library. (The server has been running cyclically, but none of them exist ).

For UDP communication, you do not need to establish a connection and directly receive/send the connection.

 

 

4. Multithreading

1. programs and processes

A program is a set of computer commands that are stored on a disk as a file. A process is an instance of a running program. For example, the compiled "EXE" file is an executable program stored on the disk.
Is the program. Click Run to start an instance of the program, which is called a process. A program can have multiple processes, that is, a program can generate multiple instances.

2. Processes and threads
The process never executes anything. It is the container of the thread and is truly completed.CodeThe thread is executed. A single process may contain several threads, but at least one main thread.

3. process address space
The system assigns each process an independent virtual address space. For 32-bit operating systems, the address space of a 32-bit process is 4 GB. For 32-bit pointers, the addressing range is the power of 2, that is, 4G. This is why the memory size of a 32-bit operating system generally does not exceed 4 GB.

4. Virtual Memory.
There is a "pagefile. sys" file on the disk, which is a page file. The page file transparently adds memory for the application. This part is the virtual memory.

5. threads.
Thread Kernel Object: A small data structure used by the operating system to store thread statistics.
Thread Stack: it is used to maintain all function parameters and local variables required for the thread to execute code.
Different threads of the same process run in the same process environment, and they share resources, so they can easily implement communication between each other.
The thread runs on the CPU time slice allocated by the operating system. For Single-core CPU, multiple threads need to switch back and forth. Multi-core CPU can implement concurrent execution of multiple threads.
Multithreading rather than multi-process is adopted because the thread has only one kernel object and one stack, which consumes less memory. For each process, a 4 GB virtual address space is allocated, occupying a large amount of resources. In addition, process switching requires switching the entire address space. Switching between threads only changes the execution environment.

These are some basic knowledge. I hope you can review them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.