Which SDK should I use for windows programming?

http://msdn.microsoft.com/en-us/library/ff381409(v=VS.85).aspx

I tried to compile the codes above with Code::Blocks, but it can't be done.

undefined reference to 'WinMain@16'

Since I'm very new to windows programming, I can't figure out what the error codes mean. Is there any mistake in these codes and how to fix it?

Does this relate to the SDK? Can Code::Blocks accomplish windows programming? I tried to compile the codes with Microsoft Visual C++ 2010 Express(the free version, http://www.microsoft.com/express/Downloads/#2010-Visual-CPP), but I couldn't even find the BUILD button.

And the BMP Loader(from http://www.cplusplus.com/src/) won't work for me either. So please tell me whether Code::Blocks is OK for windows programming or I should go for something else.

Thank you in advance.
Last edited on
Did you copy and paste the code correctly, or if you typed it out did you type it out correctly??

In particular have you got thses lines at the top of your cpp file
1
2
3
#ifndef UNICODE
#define UNICODE
#endif  
@guestgulkan

Thank you for replying, sorry, I gave the wrong information, error code is
undefined reference to 'WinMain@16'

And of course, I copied every single character of that codes including the
1
2
3
#ifndef UNICODE
#define UNICODE
#endif  
and pasted to my CB.

So you mean it's not related to Code::Blocks right? CB is able to deal with windows programming right?
Last edited on
It's a linker issue. You need to tell the linker it's a Console app and not a Windows app. The two kinds of apps have different entry points (main and WinMain respectively).
@kbw

I know nothing about windows programming, so please tell me exactly what I should do, then maybe I can figure out something. Thank you.
Code Blocks can work with windows programs just fine, but I don't think all compilers support wWinMain (Code::Blocks is mostly used with GCC/MinGW, so I guess you have that). Try WinMain instead and replace the PWSTR in the arguments by PSTR. If you want to get Unicode command line arguments with MinGW use the GetCommandLineW function instead.
@hanst99

It works. You've got my first windows program done! Thank you very much.

But why does your way work? You mean GCC/MinGW doesn't support wWinMain and PWSTR right? So what exactly are WinMain, wWinMain, PWSTR and PSTR? Are they part of windows.h? How can I distinguish these differences from various compilers?

And what are Unicode and GetCommandLineW? Where can I learn all the beginners' stuff?

Thank you for your time.
WinMain
The Entry point for a Windows GUI application is WinMain. It's just a matter of fact. The designers could have used main, but found it more suitable to pass in different arguments to the app at startup.

When WIN32 came around, it had explicit support for non-GUI apps and so was forced to support main as an entry point. So, if you build your app as a GUI, the environment uses WinMain and a Console app uses main.

WinMain/wWinMain, PSTR/PWSTR, GetCommandLine/GetCommandLineW
The WIN32 API is Unicode-16. However, it does support ANSI with CodePages as per the previous versions of Microsofts Operating Systems. GetCommandLine() is the ANSI version, GetCommandLineW() is the Unicode version. The same applised all the W functions and types.

Whereas it is more convenient to use the ANSI, all ANSI functions convert to/from Unicode before calling into the kernel as necessary.
closed account (z05DSL3A)
Technically GetCommandLine() will resolve to either GetCommandLineW() [Unicode] or GetCommandLineA() [ANSI] depending on UNICODE settings. The same as most of the API.
Last edited on
+1 Grey Wolf

This reminds me of a post from Disch. WinAPI: Being Unicode Friendly http://www.cplusplus.com/forum/articles/16820/

I just thought it's worth reading. Good luck!
Thank you all very much. I'll look into it.
Topic archived. No new replies allowed.