One of the API entry series-The 'annoying 'Windows Data Type

Source: Internet
Author: User

 

OriginalArticleFor more information, see the author and source.

 

Initial launch

Http://blog.csdn.net/beyondcode

Http://www.cnblogs.com/beyond-code/

Http://hi.baidu.com/beyondcode

Baidu Article address: http://hi.baidu.com/beyondcode/blog/item/09370f24526d6b6835a80f54.html

Csdn Article address: http://blog.csdn.net/beyondcode/archive/2009/03/23/4015769.aspx

 

 

Hello everybody this is beyondcode

Hello, everyone, I am beyondcode again. I am planning to give a series of Windows API programming tutorials to help you with some questions about Windows API programming, confused new friends.

First, explain some terms or terminologies. the SDK is short for the software development kit, that is, the meaning of the software development kit.ProgramSome header files, libraries, tools, help documents, and so on.

Windows API programming refers to calling Windows interface functions for programming. For example, MessageBox is an API function or interface function. You can understand everything. If you don't even understand this, I don't want to find this article ~ ·

Why do I have to do this series of tutorials? Please let me know first. Recently, some people have encountered some things, which makes me feel that the introductory articles in this field are really lacking, in addition to the complicated, huge, and annoying macro definition and data type definition in the Windows SDK header file, for a newbie (I am talking about a newbie not just getting started with programming, it also refers to those who have excellent skills in other language fields. A pure SDK-written helloworld program is a difficult and challenging task. Based on the principle of helping others and happy with myself, I have made this plan. Of course, it is also part of this plan to make memories of what I have learned before and what I have experienced.

I would like to declare that this series of tutorials are intended for beginners who are new to Win32 SDK programming for the first time. If you are a master, just smile ~ Of course, in addition to a smile, I would like to thank you for correcting the mistakes in the article to avoid mistakes ~~ Thank you.

OK. I am not talking nonsense much. I will go to the topic. What will I talk about in the first article today? For a newbie, the first time I came into contact with SDK programming or API programming, what is the most confusing to you? Let's talk about it, I think the Data Type Definition and macro definition in Windows SDK should be regarded as this very role ..

In fact, Microsoft's intention is also kind. In order to reduce the burden on programmers and facilitate programming, it took so much time and effort to define such a large set of data types and macro definitions, this is why I mentioned previously that it is annoying because it is not really annoying and skillful. Not only do you not think it is annoying, but you cannot leave it alone, this is exactly what we love.

Let's take a look at several data type definitions.

TYpedefFloatFloat;

Typedef Long Long;

Typedef Short Short

TypedefIntInt;

TypedefCharChar;

Float, long, short, Int, and char data types are all familiar C/C ++ data types. Microsoft has redefined them, which is very simple, that is, change the name to uppercase. The purpose of this operation is probably for the convenience of coding by Microsoft. You do not need to change the case sensitivity of the input method. It is more user-friendly ..

Let's look at several examples of data type definitions.

TypedefUnsigned intUint;

TypedefUnsigned intUint32;

TypedefSigned intInt32;

TypedefUnsigned longDWORD;

TypedefUnsigned shortWord;

The definition of these data types has a slightly substantial effect. Note that they are relatively short and do not have to be written so long, and they are also relatively intuitive, if I want to define an unsigned integer, I don't need to write unsigned int;

It's so long that you only need uint A; It's much simpler and clearer, so it's not annoying.

Among them, DWORD is a data type that can be seen frequently in SDK programs. It is often used, and many new users do not understand what data type it is. Now I see it, in fact, it's just the unsigned long shaping unsigned long. It just gives him an external number. · There's no technical content, so don't worry, whether the program writes unsigned long or DWORD depends on your mood, because they all represent the same data type.

Next we will introduce two very important, frequently used, ubiquitous data types wparam and lparam.

Let's take a look at their definitions.

TypedefLong_ptrLparam;

TypedefUint_ptrWparam;

First, let me tell you that these two data types are very important. It's not an alarmist. Now you will know when you write the SDK program. What are their definitions confused? No, we analyze lparam step by step. First, we define lparam as long_ptr, that is, where lparam can be used to write long_ptr. What is long_ptr defined?

TypedefLongLong_ptr;

Have you seen it? That is, long. In the final analysis, lparam is the long type. You can directly replace all lparam variables with the long data type. But this is not recommended. Why do you think about it ~~

For the above data types, refer to the description in msdn, or you can view the Windows Data Type Definitions in the windef. h header file. Please refer to the definition of laram and wparam ~

During the derivation, you may find that long_ptr is defined in this way.

# If defined (_ win64)

Typedef_ Int64Long_ptr;

# Else

TypedefLongLong_ptr;

# EndiF

What does this mean? You can understand the definition in English. If _ win64 is defined, long_ptr is defined as _ int64; otherwise, long_ptr is defined as long. That is to say, if the _ win64 macro is defined earlier, the long_ptr is defined as the _ int64 data type in 64-bit programming, otherwise, it is defined as long type, so it should be better understood. Here, you don't have to go into _ int64, which is rarely used in mainstream 32-bit programming. Understanding is OK. This definition is a trick that Microsoft uses to compile programs written by programmers in both 32-bit and 64-bit formats.

To view the data types of these windows systems, it is actually very simple. In the integrated development environments of vc6.0 and vs2008, you only need to right-click a data type, in the pop-up menu, select 'Goto defination' or 'view define'. If you do not see the final form, continue with the above steps. Until you see its essential data type. In this way, new users have a fundamental understanding of the complex data type definitions of windows, and are no longer confused, in future programming, there will be no situations where you do not know which data type to use or which data types can be converted to each other. However, you still need to observe and practice more ~~

Next, let's take a look at some macros defined in windows.

# Define voidVoid

# Define Const const

The two simplest macros are only written in uppercase. Is it to help programmers not switch the input method? It's really user-friendly.

The macro definition in Windows SDK is the largest, the most complex, but also the most flexible. Why do you say this? I will explain and accumulate the macro definition at in a series of articles in the future, because it is too much and complicated, we will only explain it when necessary. At present, it seems that there is no need to know so much about this, so we can understand the above two very simple, like other macros such as winapi callback getwindowtext, we can't remember them, but it will also increase your burden ., We will explain it later.

The content of the first series of articles is almost the same here. New friends are confused. I can decide whether to add it to subsequent articles. This SDK series tutorials require your support. Thank you.

By-beyondcode

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.