WINAPI question from noob

Hi guys - been several years since I first (and last) used C++ and am basically starting over with fundamentals. I'm a c# developer and my job requires a lot of pinvoke/interop which I am comfortable doing but find would be easier to do in C++.

I'm writing some simple code to get my feet wet with winapi calls in C++, just a simple call to the Beep function (VS2008 from my IDE):

1
2
3
4
5
6
7
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
	Beep(0x32, 1000);
	return 0;
}


The code above works. However, I like to rely on Intellisense so I originally had it written as "WINAPI::Beep(0x32, 1000)" which threw up a compile error "syntax error: missing ';' before '__stdcall'."

So what does this error mean? What is "WINAPI" in this instance, an abstract class, namespace, ...?

Secondly, I'm a bit confused about MSDN's "Syntax" section. For the Beep function, it is shown as:

C++
BOOL WINAPI MessageBeep(
__in UINT uType
);

So.. is this how the function is actually defined in the header? Is this C++ or C? I understand BOOL is the function's return value, what is WINAPI, the class?
Is the "__in" indicator there simply for documentation or is it actual code?

Thanks in advance guys, great site.
Had a look here
http://msdn.microsoft.com/en-us/library/ms679277%28VS.85%29.aspx
It appears you have used it correctly, have you tried entering as in decimal instead of hex?
Let me reiterate, this code works:

1
2
3
4
5
6
7
8
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
	Beep(0x32, 1000);
	return 0;
}


This code DOES NOT (compile error I mentioned):

1
2
3
4
5
6
7
8
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
	WINAPI::Beep(0x32, 1000);
	return 0;
}


So.. why is WINAPI::Beep(0x32, 1000); invalid?
closed account (z05DSL3A)
WINAPI is a macro for the __stdcall calling convention.
http://msdn.microsoft.com/en-us/library/zxk0tw93(VS.71).aspx

Edit:

__in is a header annotation. (more to help you understand how to call an API function).
http://msdn.microsoft.com/en-us/library/aa383701(VS.85).aspx

The Windows API is C, just include the corect headers and call the functions.
Last edited on
Thank you Gray Wolf. Those links will be helpful.

About the Windows API being written in C- why then does the documentation on MSN have the syntax sections annotated with "C++?"

EG:

Syntax:
C++

BOOL WINAPI MessageBeep(
__in UINT uType
);
closed account (z05DSL3A)
Maybe just esthetics, I'm sure the MSDN used to have it as C/C++ hadn't even noticed it change.
Technically, if you are writing in C or C++ the syntax is the same.
Thanks GW, you da man!
Topic archived. No new replies allowed.