sanitizedUser
sanitizedUser

Reputation: 2115

How to interpret docs on WinMain?

Please look at the WinMain docs.

int __clrcall WinMain(
  [in] HINSTANCE hInstance,
  [in] HINSTANCE hPrevInstance,
  [in] LPSTR     lpCmdLine,
  [in] int       nShowCmd
);

How should I interpret this? Is in attribute optional which is denoted by the square brackets? If so, what does it look like.

I tried to compile a simple application in Visual Studio with the following flags:

/clr /permissive- /Zc:twoPhase-
#include <Windows.h>

int __clrcall WinMain(
    [in] HINSTANCE hInstance,
    [in] HINSTANCE hPrevInstance,
    [in] LPSTR     lpCmdLine,
    [in] int       nShowCmd
) {
    return 0;
}

But it won't compile and gives the following errors.

C2373 WinMain': redefinition; different type modifiers
C2337 'in': attribute not found
E0337 linkage specification is incompatible with previous "WinMain" (declared at line 1033) WinBase.h
E0147 declaration is incompatible with "int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)" (declared at WinBase.h)

Upvotes: 0

Views: 208

Answers (1)

padeso
padeso

Reputation: 464

The [in] decorations are just for documentation. You can ignore them and just implement WinMain like in the sample WinMain docs:

If building for Multibyte (a.k.a. ANSI):

#include <Windows.h>

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cmdshow)
{
    return MessageBoxA(nullptr, "hello, world", "caption", 0);
}

If building for Unicode:

#include <Windows.h>

int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPWSTR cmdline, int cmdshow)
{
    return MessageBoxW(nullptr, L"hello, world", L"caption", 0);
}

Upvotes: 2

Related Questions