In that year, only C # is used. Therefore, writing C ++ is like this !,

Source: Internet
Author: User
Tags manual writing socket error

In that year, only C # is used. Therefore, writing C ++ is like this !,

This should have been 4-5 years ago. At that time, c # Won't knock on the code, and C ++ won't, but I am confident that the idea is enough to develop this thing. It's just a syntax problem. For C ++, it seems that only Daniel can be competent. Therefore, we have made some common classes to avoid many unfamiliar syntaxes in C ++.

Release some code. For example.

Let's take the first example:

ApplicationHelper is used as an example:

See what you think of the two methods. Yes. Is the Doevent and startuppath methods in the Application method in C. Many methods in C # require manual writing. However, your experience is limited. It is also limited to converting C # into C ++, so it can only be written as this. So all I think is that many of my classes are constructed on the basis of a C # To avoid learning too much about the C ++ principle. Why not!

Let's take a look at the implementation.

If you have any mistakes, Do not spray them. I am not familiar with C ++. However, you can write a C ++ project.

The general serial port class is BCLSerialPort. The name is also Microsoft's mvc Hahaha. Think about it now!

1 // BCLSerialPort. h: interface for the BCLSerialPort class. 2 // 3 //////////////////////////////////// //// // 4 5 # if! Defined (rows _) 6 # define rows _ 7 8 # if _ MSC_VER> 1000 9 # pragma once10 # endif // _ MSC_VER> 100011 12 typedef BOOL (CALLBACK * ONREAD) (const char * buf, DWORD dwBufLen, void * pContex); 13 14 # define READ_BUFFER_SIZE 1024 // read Serial Data Length 15 # define READ_TIME_OUT 500 // read timeout millisec Onds16 17 # define SERIALPOINT_DEFAULT 0 // serial port initial status 18 # define SERIALPOINT_OPENED 1 // serial port enabled 19 # define SERIALPOINT_CLOSED 2 // serial port disabled 20 21 22 class BCLSerialPort 23 {24 public: 25 /// constructor 26 BCLSerialPort (); 27 28 /// parameter comNo serial port number 29 /// parameter baudRate baud rate 30 BCLSerialPort (CString comNo, DWORD baudRate ); 31 32 // parameter comNo serial port number 33 // parameter baudRate baud rate 34 // parameter parity check bit 35 // parameter byteBit 36 // parameter stopBit stop bit 37 BCL SerialPort (CString comNo, DWORD baudRate, DWORD parity, BYTE byteBit, BYTE stopBit); 38 39 // open the serial port 40 BOOL SerialPortOpen (); 41 // close the serial port 42 void SerialPortClose (); 43 44 // write the serial port 45 DWORD SerialPortWrite (LPCTSTR sBuf, DWORD dwToWrite ); 46 // read the serial port 47 BOOL SerialPortRead (LPTSTR sBuf, DWORD & dwRead); 48 49 virtual ~ BCLSerialPort (); 50 51 public: 52 CString m_ComNo; // serial number 53 DWORD m_BaudRate; // baud rate 54 BYTE m_ByteBit; // data bit 55 BYTE m_StopBit; /// stop bit 56 BYTE m_Parity; // parity (no-NOPARITY) (odd-ODDPARITY) (even-EVENPARITY) 57 58 DWORD m_SendLength; /// the length of the sent data is 59 60 DWORD m_OpenState; // the serial port is opened in 61 HANDLE h_Com; // the serial port HANDLE is 62 COMMTIMEOUTS m_CommTimeouts; // the serial port times out 63 }; 64 65 # endif //! Defined (afx_bclserialport_h1_86b3d83f_d22c_44f9_b138_40e3d480edfb1_included _)

General Socket communication class:

1 # pragma once 2 3 # include <winsock2.h> 4 # include <windows. h> 5 6 # pragma comment (lib, "ws2_32.lib") 7 8 # define WIN32_LEAN_AND_MEAN 9 # define MAX_RECIVE_SIZE (256*1024) 10 11 // define the connection disconnection event 12 typedef void (CALLBACK * ONCLOSE) (void * pOwner); 13 // define 14 typedef void (CALLBACK * ONTCPREAD) when there is a data receiving event) (void * pOwner, void * tsOwner, const char * buf, DWORD dwBufLen); 15 // defines the Socket error event 16 typedef void (CALLBACK * ONTCP ERROR) (void * pOwner, int nErrorCode); 17 18 class BCLTcpSocket 19 {20 21 public: 22 BCLTcpSocket (); 23 virtual ~ BCLTcpSocket (); 24 25 BOOL Connect (); // Connect to the server 26 BOOL Close (void); // Close 27 void CloseReciveThread (void ); // close the receiving thread 28 29 void ReciveData (void); 30 BOOL Send (const char * data, int dwBufLen); // Send data 31 void RegisteCallBack (ONCLOSE fClose, ONTCPREAD fRead, ONTCPERROR fError); // sets the processing callback interface 32 private: 33 HANDLE m_ExitReciveThread; // exits the receiving thread 34 static dword winapi Recive (LPVOID lparam); // receives data 35 36 public: 37 SOCKET m_Socket; // Socket communication HANDLE 38 HANDLE m_ReciveThread; // data listening thread 39 40 DWORD m_ConnectState; // connection status-1 not connected 0 connection successful 1 Connection Failed 41 DWORD m_ReciveThreadId; // accept thread ID42 char m_Ip [255]; // ip address 43 int m_Port; // port 44 char m_Data [MAX_RECIVE_SIZE]; // accept the maximum data buffer data zone 45 void * m_pOwner; // master thread pointer 46 47 ONCLOSE OnClose; // connection disconnection event, callback Function 48 ONTCPREAD OnRead; // receives data events, callback function 49 ONTCPERROR OnError; // error event occurs, callback function 50 };

Database Query Class SearchCondition

1 # pragma once 2 # include <stdarg. h> 3 4 // database condition 5 enum SqlOperator 6 {7 Like = 0, // fuzzy query 8 LikeAt, // fuzzy query matches the first character 9 LikeLast, // The character 10 NotLike after a fuzzy query is matched, // It is not Equal to 11 Equal for fuzzy query, // It is Equal to 12 NotEqual, // It is not Equal to 13 MoreThan, // It is greater than, 14 MoreThanOrEqual, // greater than or equal to 15 LessThan, // less than 16 LessThanOrEqual, // less than or equal to 17 In // 18}; 19 20 class SearchCondition 21 {22 public: 23 SearchCondition (); 24 virtual ~ SearchCondition (); 25 26 // obtain the condition 27 CString GetCondition (); 28 29 // obtain the condition symbol 30 CString GetSign (UINT operatorType ); 31 32 // clear condition statement 33 void NewSearchCondition (); 34 35 // fuzzy query 36 void SearchConditionLike (CString fied, CString value, CString likeStr ); 37 38 // fuzzy header query 39 void SearchConditionLikeAt (CString fied, CString value, CString likeStr); 40 41 // fuzzy tail query 42 void SearchConditionLikeLast (CString fied, CString value, CString sign, CString likeStr); 43 44 // fuzzy query 45 void SearchConditionNotLike (CString fied, CString value, CString sign, CString likeStr ); 46 47 // sort in descending order 48 void SearchConditionOrderByDesc (CString fied); 49 50 // sort in ascending order 51 void SearchConditionOrderByAsc (CString fied ); 52 53 // operatorType database operation parameter fied field value sign likeStr fuzzy query symbol 54 void SearchConditionAnd (CString fied, SqlOperator operatorType, CString value, CString sign ); 55 56 // operatorType database operation parameter fied field value sign likeStr fuzzy query symbol 57 void SearchConditionOr (CString fied, SqlOperator operatorType, CString value, CString sign ); 58 59 60 public: 61 // condition 62 CString m_Condition; 63 // 64 SqlOperator m_SqlOperator; 65 };

If you write the C ++ Industrial Control Project above, you should not worry about it. Serial Port, Socket communication. Read/write databases. I don't know C ++. You want to use interfaces. Later, there was no interface concept. It is replaced by a required method. This also provides me with a lot of convenience.

 

Conclusion: C # is difficult to convert to C ++. In the process of switching to C ++, too many difficulties have not been encountered. It is not very convenient indeed. However, you can build it step by step. Most of the time, some methods are converted according to the C # naming method. In this way, the code for writing C ++ is the same as that for writing C. I feel pretty cool.

We also hope that the various great gods will provide a better way! This alone provides some ideas for programmers who need c # To transform C ++.

 


At that time, when I got my visa, I said I only went to France and got it for half a year. The type of my visa was C. I entered the country multiple times. For example, I can go to other countries in the future.

Yes, as long as the visa is valid for any country covered by the visa.
Check whether it is valid for half a year. If so, you can enter the site multiple times.

I graduated from a 20-Year-Old High School. Without other survival skills, I would just drive a drive with a drive C photo [driver's license ].

If you want to find a way out, you have to learn how to find a better school in may not be enough in January 30 after five years, if you want to learn something, you can't be a white-collar engineer. I have a friend who is studying architecture. When I went to school with a secondary school degree, I got a mixed graduation certificate. Finally, I got someone to buy it. After graduation, I got two jobs at the construction site. I got an Adult College Entrance Examination in two thousand and seven and now my salary is RMB, do not compare anything with others, as long as you do your best. My friend is the kind of time when I first went to the construction site. after a long time, he realized that he had to work hard and study hard, just like a new person. He had to study hard. No matter what Major, first, you have to learn carefully. It will be useful in the future.

Related Article

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.