Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * * 1 votes

Win32 Tutorial Part 1 - MessageBox

hello world wcscmp

  • Please log in to reply
19 replies to this topic

#13 sun13zenith

sun13zenith

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Programming Language:C, Java, C++, PHP
  • Learning:C, Java, C++, PHP

Posted 21 May 2012 - 08:41 AM

Do you think there is something missing in my Code::Blocks compiler i.e. MingW. If true, how to add that thing MingW in my CB.
  • 0

#14 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 21 May 2012 - 08:51 AM

Well, the truth is I don't use CB for Windows app development but I use Visual Studio. However, two general things we need to consider everywhere...
  • We need to add header files directory which we want to include in our project. As example we used Windows.h in our above code for which the directory for it already added by default (or perhaps by the project template we used). But if we want to use other 3'rd parties header files we need to add that directory manually.
  • We also need to do the same to link to the libraries we want to use.
You can read this tutorial to learn how to do those two steps when you need.
  • 0

#15 sun13zenith

sun13zenith

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Programming Language:C, Java, C++, PHP
  • Learning:C, Java, C++, PHP

Posted 21 May 2012 - 08:59 AM

Oh! you use Visual Studio. But it's not open source. Hence we cannot distribute the code to everybody. And also it is Windows platform dependent.

If I have to commercialize my software in future, I should use VS or CB please I need info. Also, if apps created in CB are not going to make any living for a person then what is the use of it, then people should only use VS. What say?.
  • 0

#16 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 21 May 2012 - 10:01 AM

You are right about the platform dependency and about the license on Visual Studio. If you need to compile your code on Windows, Linux and Mac, you can use CB. To distribute the software (the binaries), your users don't need to have VS or CB.
  • 0

#17 hockey97

hockey97

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 95 posts
  • Programming Language:C, C++, PHP, JavaScript, Bash
  • Learning:Assembly

Posted 06 June 2012 - 11:03 AM

Hi, I am still kinda confused about this. I know c and C++ using console aka main(). I am trying to learn the win32 api.

I know you said that hinstance is a variable But why is it like HINSTANCE hinstance ??? I am confused about this.

Also what is hprevinstance used for? i know you said it isn't used for windows 32 systems. I am guessing must be used for 16 bit systems? or older systems. I am not sure. Can you explain why we always set this to null? and does it need to be set at all? what would happen if we don't include hprevinstance in the WinMain ???
  • 0

#18 freiza

freiza

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 56 posts

Posted 06 June 2012 - 05:19 PM

HINSTANCE is handle to current instance. ( I mean current running executable),
Suppose you open 4 notepad. Then there are 4 running instances of notepad in your computer memory. Each Instance is given a number (also called handle) by the OS. With this number you can access the running instance through programming.

hPrevInstance was used in 16-bit OS. They need to track number of previous running instances mainly because of memory sharing. But Now each Instance runs on it own address space(32-bit OS) so hPrevInstance is always set to 0.
It was handle to previous running instance.

what would happen if we don't include hprevinstance in the WinMain ???


Suppose in your program. You have declared a prototype like this:

void func( int a , int b, double c);

Can you omit int b in actual declaration?
void func ( int a, double c) {} // Is this valid??? ==> No, you can't do it. Since in prototype you mentioned that you have to pass 3 parameters. Whether you use int b or not you have to define it in your function delaration.

Similarly, You have to include hprevinstance in WinMain.
Prototype of WinMain is
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
So you have to include hPrevInstance.


Win32 API was created back in 1990's, at that time 16-bit OS were common. And because of compatibility WinMain still have hPrevInstance.
  • 0

#19 hockey97

hockey97

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 95 posts
  • Programming Language:C, C++, PHP, JavaScript, Bash
  • Learning:Assembly

Posted 20 June 2012 - 02:13 AM

HINSTANCE is handle to current instance. ( I mean current running executable),
Suppose you open 4 notepad. Then there are 4 running instances of notepad in your computer memory. Each Instance is given a number (also called handle) by the OS. With this number you can access the running instance through programming.

hPrevInstance was used in 16-bit OS. They need to track number of previous running instances mainly because of memory sharing. But Now each Instance runs on it own address space(32-bit OS) so hPrevInstance is always set to 0.
It was handle to previous running instance.



Suppose in your program. You have declared a prototype like this:

void func( int a , int b, double c);

Can you omit int b in actual declaration?
void func ( int a, double c) {} // Is this valid??? ==> No, you can't do it. Since in prototype you mentioned that you have to pass 3 parameters. Whether you use int b or not you have to define it in your function delaration.

Similarly, You have to include hprevinstance in WinMain.
Prototype of WinMain is
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
So you have to include hPrevInstance.


Win32 API was created back in 1990's, at that time 16-bit OS were common. And because of compatibility WinMain still have hPrevInstance.


Oh, Thanks for the clarification. I now understand. So when you say 16-bit OS would one 16 bit OS be DOS.?
  • 0

#20 freiza

freiza

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 56 posts

Posted 20 June 2012 - 04:20 AM

Yes.
  • 0





Also tagged with one or more of these keywords: hello world, wcscmp

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download