I don't understand Win32 datatypes

Posted 16 July 2012 - 08:46 PM

I am creating a console application using the win32 API. i am having a lot of trouble getting anything to compile. what is LPSTR? how do i use it. what datatype's SHOULD i be using? the only reason I'm creating a console app is because to create a G.U.I. app i MUST use Microsoft's stupid datatype's which i obviously don't understand. here is what i have so far.

So you get LPSTR. The long used to be significant because Windows used to be 16 bit, and so the default pointer in the compiler was only 16 bit, but there was a need to ensure that all pointers were 32 bit, and so the long modifier.

Nowadays, there is no need for the L. You can technically use PSTR, PCSTR, PWSTR, and PCWSTR if the 'L' messes with your sensibilities.

You can probably figure out that the C stood for "const". The WSTR stands for "Wide character string".

Re: I don't understand Win32 datatypes

Posted 16 July 2012 - 09:15 PM

The Windows API evolved before there was the C++ standard. Since MS's goal was to have some kind standard API for companies and individuals outside Microsoft to have some standard way to use the Windows APIs it had to forge ahead and define it's own types.

If you were going to use GIMP or MPIR, would you begrudge using their datatypes (mpz_t) to use their API's?

Re: I don't understand Win32 datatypes

Posted 16 July 2012 - 09:24 PM

Quote

sorry. I'm just tired of not understanding this crap. ive never struggled this much with anything else in programming ever.

I feel your pain. I get a headache any time I see a Windows API program. This crap was supposed to make using the Windows API the same no matter what version of Windows you were using from Win16 to Win32. For example a DWORD is guaranteed to be a 32 bit unsigned integer. You may want to book mark this page if you will be dealing with the Windows API: MSDN Common Data Types This is a list of most of the data types used by the Windows API.

Re: I don't understand Win32 datatypes

Posted 16 July 2012 - 09:28 PM

Skydiver, on 16 July 2012 - 09:15 PM, said:

The Windows API evolved before there was the C++ standard. Since MS's goal was to have some kind standard API for companies and individuals outside Microsoft to have some standard way to use the Windows APIs it had to forge ahead and define it's own types.

If you were going to use GIMP or MPIR, would you begrudge using their datatypes (mpz_t) to use their API's?

YES, i would. and jim, how do you write GUI applications without the windows api?

Re: I don't understand Win32 datatypes

But there are Frameworks that encapsulate the low level Windows API, such as wxWidgets, QT, and several others.

Jim

my goal in learning the windows API was to learn the low level aspects. this was also my goal in learning C++. after learning the windows API, then direct x, i plan to learn assembly. My goal in every program i write is efficiency. so using wxWidgets or QT would defeat the purpose of me writing GUI applications period! thanks for the input though! now, as for my next issue, why am i getting the compile time error(s)

Re: I don't understand Win32 datatypes

You forgot the Class:: scoping qualifier in front of your class function implementations.

As a side note: unless you plan on declaring those functions as inline, you should really move the implementation into a .cpp file.

BTW, the way I deal with Windows data types, is I just use native C++ types in my Model and Controller code. Only when in my View code do I convert to a Windows type if necessary. Often most of the basic C++ types have direct equivalents. I think that my only concession to the Windows data types is that instead of using std::string to store ANSI strings, I always use std::wstring to store UNICODE string.

Re: I don't understand Win32 datatypes

You forgot the Class:: scoping qualifier in front of your class function implementations.

As a side note: unless you plan on declaring those functions as inline, you should really move the implementation into a .cpp file.

BTW, the way I deal with Windows data types, is I just use native C++ types in my Model and Controller code. Only when in my View code do I convert to a Windows type if necessary. Often most of the basic C++ types have direct equivalents. I think that my only concession to the Windows data types is that instead of using std::string to store ANSI strings, I always use std::wstring to store UNICODE string.

so what your saying is that its better practice to declare the class in a .h file and the actual code for the class into a .cpp file (with the same name as the .h file perhaps?) i have seen this done, but when i first learned OOP C++ i always did it all in one file.