Intro to C on Windows - Day 1
By Molly Rocket
Summary
Topics Covered
- Windows C Setup Demands Visual Studio
- Win32 Console vs Window Apps Segregated
- Compilation Translates Text to CPU Code
- Linking Resolves Cross-File References
- WinMain Entry Ignored Without Headers
Full Transcript
Okay Assuming this is working I would love to welcome everyone to this Pestering basically what I wanted to do Is I am planning on I'm starting a project on Monday Which is probably very ill-advised and I appreciate that but I'm Planning to start a project Where I am going to show how to code A complete game in C Which is a pretty big undertaking And
I thought about it whether it was a good idea for a while and I wasn't sure but I finally decided that I really wanted to do it and I always want I need the directions to have like a documentation But you can basically Or documentation say Like a live recording of like cures everything that we did to make An actual games you can play from scratch
And so I don't know how that'll go nobody make care about that at all until the game is pretty far along or something like that That but I really really want to do it And so I'm going to be starting that On Monday but before then I wanted to practice the streaming to make sure that all of the stuff is going well because Computers of course as you know are oh so reliable these days
And so I kind of have a feeling that there will be plenty of So what I thought I do Is spend a couple days Doing test dreams where I will at least do something useful Which is explain how to do C programming on a computer Because I mean Let's face it lots of people don't know how to do that And if anyone wants What's to follow along as I program the game
NC and go through all the explanations Of why I'm reading the game code that way I won't be wanting to stop and explain little things like what is the question mark operator or How does Is the staff work or something like that unless that's exactly relevant topic At the time so I was hoping to basically do A couple streams that I could archived and just put up on the website that's like
If you don't know how to pronounce it all if you literally have no idea but would like to watch the series Go watch these couple videos that'll get you up to speed I'm just what's going on so you can start to follow and granted you'll still have to do a bunch of work to practice and learn how to program at Aldi Because if you don't know any programming
You're not going to be able to just jump right in but at least I'll get you started and then you can presumably At least start to follow the videos and understand You know the majority So What this video is going to be It was going to be literally showing How I would start To program Siana machine and how to do some of the basics I forgot
So this is not a Windows machine cuz that's the most common Programming machine that people are going And have And The thing that you have to do right off the bat which is actually kind of annoying and you don't have to do this If you're on Linux but the thing you have to do on a Windows machine issue has to find A c compiler I'm currently you don't have a lot of option
Even though llvm which is, one other platforms Is Sort of able to build seen out it's not able to actually do the entire process so what you have to do Is you have to go Get something called Microsoft Visual Studio X And this is basically a free version Of their you know thing that they're there Professional C programming environment and you'll see when you get to this page
They want to give you a lot of other stuff But you really don't want When you look on here you can see stuff like oh.
Team Foundation server And Since you're just someone is trying to program C at home you probably don't have a team or if you do they probably don't Don't have a foundation or don't want their Foundation to be comprised primarily Or something for Microsoft anyway I certainly would And they're also going to try and give you things like this Express for web which is something that you use To program
Like you know if you want to do web deployment you know asp P.net and other things like that What you want to do You're the one that you actually want to get Is this one here which is Express 2013 for Windows Which is the thing that actually lets us compile C++ which is what we want So I'm going to start that downloading Or at least I'm going to go through this this awesome Crazy
Circus here that you have to do to download Los Arcos And now we're going to kind of have to skip a little bit of this process only because there is a challenge response that they do Which people will have to do on their own I obviously I can't tell you how to do You will have to basically Install the Skype Loading identity provider
Okay so yeah you will have to go through and you'll have to fill this out Unfortunately you'll have to get like a Microsoft Login of some kind In order to get it But once you get it it will allow you to install visual studio and you will be able to do basically Sub sub Definitely what I'm about to do After you get that in
Install it'll probably make you reboot your machine which I also can't do on a live stream of course because if I would have read them Machine But after you do that You will get A newer version Essentially Of this particular product this is the older version that was installed on this machine Visual Studio 2008 And as you can see we've got stuff on here which is kind of not actually stuff I can open up
Obviously I'm not allowed to To show you any of the secret Witness Things that would that would be very bad for him But what you can do To actually start programming In this particular Department you should go to new And you go to Project And what that'll do is that will allow you to create one of their dummy projects which I'll show you how to build
Only for a little while because we'll kind of immediately get off What advice does the brings up A giant window Full of all of the things That you Could build with this And most of them are things that we are not concerned with Are you can see there's a bunch of template things for you can use for. Net you can see there's all sorts of things here MSC which is like an Antiquated Library
And you don't care about any of these things the only thing you want to do is build a win32 Application Tinder two options One is for win32 console application One is for win32 Project And the difference between these two is actually extremely rudimentary All it is is for some reason way back when they actually did The original version of Windows they decided to segregate How you built
Basically applications that can run from a command line Which is something we'll look at me Future and ones that are actually more like apps like it have a window And because they did that You have to build an app as one or the other And this is actually something that's basically impossible to get around there are workarounds for it if you really care but basically there is no No way on Windows
Unlike say on Linux or Mac Off There is no way to actually build something That both Works from the command line And work From In the standard application mode But We don't have to talk about that too much because we're going to be building a game and games don't really have Have to do anything from the command line Inside of a That's right away So
What we're going to do is Select win32 project which is what setup for actually building a Sorry I got to enter a name So we're going to call this We're going to call this Okay And what I'll do is I'll bring up this silly little wizard And The Wizard is basically asking a bunch of stuff none of what you want
So what you want to do is just check empty project so that it will get out of your way And what kind of gives you another option here to do other things like the console application dlls which are separate issues.
Saclibrary switch we don't need Worry about right now better things you might want to know And we'll go to Windows application which will basically just give us Our own Furtive This will basically give us our own sort of Dumping Ground where we can put stuff in and build it No the way that Microsoft Visual Studio works if it has this thing called a solution Explorer
And one thing that will often happen to you when you're developing is it will go away so you will get something That's like this or perhaps you'll get something that's even completely blank I'm so that has nothing in it like this And you can get back to the solution Explorer Thing by going to view solution Explorer now what is a solution You may ask what was the problem
You may also ask him that's a very valid question But the answer is there wasn't necessarily a problem Unless you consider the problem being that Microsoft makes it very hard to build things Solution was just something that they started calling a project at some point Answer Really a solution is just their word for a thing that you are going to build it's like a basically
A list of things that need to get built and how they're going to build them and so instead of having an intuitive name like Files Explorer project Explorer it's called solution Explorer And you have to go to it when you go to the solution Explorer You will basically get something here That works a lot like You know the file explorer in Windows It's hierarchical and you can collapse it
And they made some folders in here but we don't really have to care about these folders very much And we can have our own folders or rename folder So if we wanted to rename one of these you know we could go in here and call this Whatever we wanted and that's fine But we need to do to in order to start building something is Axe She have some files in your How to build
So that it will know What we are So in order to do that I'm just going to right click on this and going to add And I'm going to take a new item So that would have make a new file basically That we can actually build That will pop up a mess of Windows stuff Because there's all sorts of things that you might want to do you might want to make an SQL script file Class diagram
Those might be good things to me But we're not going to make those right now Instead we're going to make just a straight-up CPP file Okay So basically I was ripped into the name done I so basically we just have to Give RC Fallon name and add it now we will have a blank file that we can start typing into And that is what we will use To start programming in Now
Programming UC has not Advanced much over the years unfortunately Obviously C & C++ They're both pretty old but You know I think C++ was sometime early 80s I see was you know a good decade before that I want to say And yet Just the same even though they're so old The way in which you actually enter C code into a computer and the way it is actually built is still Almost the same
As it was back then you basically just have Text files Their basic clean old text files less complicated than something that you would type into Microsoft Word like they They literally don't even have annotation right there just Robotics And that raw text Is then Interpreted I'm by the tools To do the things that we need to do And that's done with the Compiler and stuff that will be talking about
Basically just understand that nothing we're going to do is going to be anything other than entering text Enterkomputer Okay So The first thing to do is to say well okay we haven't actually done anything here This is some text In a file And What you wanted what you will notice is that this basically every time I type in here there's a little yellow bar that sort of appears
And that just tells you that these are new lines that you have type since you have saved And you can see that I've got a little Star there That now adds to it just like in most applications that says this file has been modified since it has been Can save now if I want to say that I can just go to files saved Peppa Pig or I wanted some shorthand I can hit control s
Right and there it saves it and you'll notice that the yellow bars now changed to a green bar And what does a green bar mean when a green bar is basically something that lets you know That is saved there was still a change recently there And I believe although I am not a frequent user Visual Studio that It will basically remove the green bar Once we actually I'll be Inter working program
So that you know what changes you've made since the last time you bought Your program So let's say I want to actually run the process Of making something out of this text file Well the thing that you do there is you say build solution And Bill solution will go through everything that we have in here It will actually Do the work necessary to make this in To a program And we'll talk about all those steps
In a little while So when I hit build solution You'll notice that if I did not have an output window open it magically made one for me It just pops up there's really nothing you can do About it And What it does is it Prince out What happened When it tried to build the program So it starts out by giving me a line which says what was trying to build So it says build started Project test
No that's what we wanted you can see in here we've essentially when it created are automatic Project for us He created the solution called test And it put inside one default project which is called test in the reason I call a default project you can see it's bold It's because You can actually go in here And there's a thing called set as start-up project in Some of the things like this
There's basically a notion of what the project is you're going to build When you build a solution because we could actually stacked other products in here that build other programs Which we don't all want to build and other sorts of nonsense like this Most of that is not really necessary when you're doing development unless you start developing a very large and complex project
But if you're just building a game by yourself it's on like you'll need to ever do anything Like that And I often don't build anything anything from here so What are things were at carburetors how to build things without using That's it Cast of the project that we will build when we do build solution and so what this was telling us here Is it was going to build that project And there's a configuration line
Which is debug win32 And what the configuration mean Is basically what sort of build it was trying to do Because as we'll see later on there's actually multiple ways you can build the same set of C code Some of them are designed to Target different platforms for example you may want to Target a 32-bit copy of Windows Or 64-bit copy of windows And that would be part of the configuration
You might want to be trying to do things that are based on Deep like a debug developer build so something that has a lot of test code compiled into it Special menus for you the editor for the game or something Might be built In this mode but then there might be another build called release Or retail depending on how you do your naming Team which will build these things out and so basic configuration
Is something that affects the way In which these text files Are actually interpreted by the various things that That we do in order to get to an application that that Is somehow different from the other configuration That we might be So now the next time you can see here is compiling And what that is is compilation Is the general term It's not a particular specific term although we actually use it to mean something specific
That's a very general term that technically means Moving something from one format into another Basically It's sort of like A translation in some sense a compiler is something that parses A text file typically It turns it into something Samantha it understands the meaning of that text file what we were trying to do that text And then it turns it into Some other thing that we wanted Now in this case
What is going to do is we're actually trying to get it To produce at the end of the day I'm an actual program that we can run an executable something that you would click on in Windows to run like with the little eye Icon. Exe that thing we want build that thing
Icon. Exe that thing we want build that thing In order to build that thing Basically the the text code that we write Has to be translated into something that the computer can run And that is what the compilation step does and there's another step After compilation that we'll talk about But the compilation step is basically in charge of doing the majority of the work To translate
Are text file from something humans read into something that a CPU can read and specifically Often times A specific process The compilation will be Compiling from a text file into say x86 to X64 code Something for the actual CPU That you were trying to Target not abstract Stop Given that After we we see the compilation lineman of the compiler
Started and we now go to a list of what files it's actually Compiling we only have one file which is Just test out CPP And so not surprisingly it tries to compile that file now you will note In front of all of these There is a little Number within with assertive Greater than symbol And What is
Is totally Irrelevant for the most part 2 what you're going to be doing for development it's not really something to pay attention to But just in case you're wondering If you are on a machine That happens to have a lot of processor So if I go in here If I basically just that use the hot tea One of my favorite hot fries Control shift escape to bring up the task manager You will notice that this machine
Have a lot of processors In this thing called CPU usage history There is one of these for every logical processor In the machine I'm a logical processor is or shouldn't say lunch process Crap that's the wrong word Deluxe compressor is not individual processor If it's only a logical unit that can run code And there's two different kinds of these And we might as well talk about them now if I'm going to talk about them Certainly more
Out later on in the actual series It's not in the center doctors Basically the word processor is divided internally or as we are computers about internally honestly there are actual physical processors So most people have one physical processor in the machine obviously But other machines have two or three or four maybe Even dozens A processor I'm certainly not consumer boxes but you know Certain server types my I have 32 processors The machine
Who's physical processors obviously are chips they were made by Intel they're stuck in the machine they have a nice big old heatsink, Grandpa from overheating And when you power on your machine they are what executes everything Graphics code or things like The networking which is sometimes on Car adjustable chips The CPUs what does all the work but In addition to being A physical unit The CPU itself is actually divided internally Into processing unit
Which actually can run code sort of separately Those are typically called course So inside a single CPU You might have four chords For a course or something And you will see these often times advertising Intel advertising and of course more course is better but what is a quart Accor Is basically something that is capable I'm doing the work
Stand-alone CPU for the most part it is something that would have been a CPU in the old days when CPUs could only Execute one thing Time Now you have processors capable of executing multiple things at a time Each one of those units is Call Decor in And the chorus typically have a bunch of things in them They have units capable of doing Maddox they have units capable of doing every other saying all these hurtful things
And then they will talk to the memory in your system will talk to the The bus go talk to all sorts of things to do their job but Biologic or Is the things action of the computation Even that It's still not really What you might call a logical processing unit Nowadays and the reason for that is they subdivided that even further Down two things called hyperthread And of course
Hyperthreads are basically A thing where A processor Score Is actually able to maintain this State Of multiple cores As if it were multiple cores Even though is only capable of executing anyone given Court a time so for example You think of a CPU core as being able to remember say what it was running where it is in the
Program what the state of the things it was operating on these sorts of things We'll get into all those aren't detail later But Cory's basically doing this work of running an application That core can actually store multiple of those States Almost like a multitasking operating system you can think of is, there's the taskbar and it's got different tasks That it has Wella Cork and actually sort of do that testing Insertive sent itself
And Even though it's only running one thing at a given time it could keep safe for additional State But it can really quickly switch to And so what happens is Those actually show up often times in the operating system as a logical processing unit Because to the operating system they sort of look Like a processor They are effectively running something Even though only one of them are particular court is actually inflated a given
Another word to talk about their But I am from two tangents I thought I'd mention some of that way booted up here So how's it going to see there a lot of logical bussiness as they are not this many processors In the actual machine In fact I don't actually know If I can go on here I think If it's actually will tell us What kind of processor it is Yes It is a Xeon It easy
2 processor box Although it doesn't actually tell me how many threads for plumbing how many cores for processor it actually has We can go look up what a w5580 is And we could see how many it has But I think it's probably only got maybe 4 / I don't know I'm not really sure But anyway each one of these would would correspond basically To one individual one of those hyperthreads and it would show me basically
How much usage that particular thread is is getting Right now So hopefully that that gives you a little bit Perspective on this I wonder too You know what Nowadays that kind of attitude I wonder if there's any way I can get more information About things like hybrid Like I say even show hyperthreads I feel like in the old days you could Chicago Bears Didn't say whether you were showing Clusters of large compressors out of
I do now Doesn't Doesn't look like there's much here For that Alright well Anyway that is not really relevant what we're doing so I'm going to skip it but maybe later on we will We will go try to find out how to how to get a little more info Thanks anyway So there a lot of Pastors in this system in when you build something
Obviously compilers can get a little slow and if you have a lot of things compiled they could take Sometime it's a one of the things that compilers do is they are more Threading sometimes Depending on which one Talking about And they will try to compile using more than one Lots of passing it so they'll try to use More of a CPU resources faster and what this little thing here Represents if I remember correctly
It's been a long time since I've ever really use my things that just to let you know a sequence number of basically which Sort of Sort of Spawn of the compiler Was reporting this message because you may have multiple compilation I going Multiple different City is doing compilation and I believe that basically just tells you Which Wonder Which one you're looking at that time Time so if we were to do more complicated
Population with multiple files you might see two stories for is going on there as it's cooled off jobs Any more complex fashion but for the moment we're only seen ones because it only had one failed to compile And did not bother to lunch at Search for Threads to do that Anyway So This is the father was compiling and we will see here the first time we got an error
And what an era is is an error means basically it was trying to read the text file that we gave it And it did not like what it found now that is unsurprising cuz I basically just typed a bunch of gibberish in here But we can do is when we double click on this it will tell us where the problem is It will then stop basically what it's doing
So when you have errors it will list the errors that it found It will list them up usually to a certain number of errors and use that as well but after it gets hurt Compilation And it will basically just reports That it failed the compilation and you can see it says 1 errors This year and it says 0 succeeded 1 failed And Alexis know if they're ones that it skipped because it didn't thicken
Need to do any work that's what it It also save a build log for Which are pretty useless most the time but If you want to look at the build log basically it saves an HTML file That has sort of A a lot of what happened in the building for I guess for posterity or if you want to do some kind of thing for you You saved the logs are doing Maybe you are running these
In some way that you're viewing remotely there's there's reasons for build logs but we're certainly not going to Okay So that rather exciting process there where we just hit build and we get an error Is what we're going to be doing In order to produce an executable and in order to get to the next step of actually producing Beautiful What we are going to have to do Is we are going to have to give it
Some code that actually Understand And Basically I'm going to type In some rope code now And I'm going to explain to you Certified it does it start of the simplest thing that we can possibly type in To get to the next stage In Here it is Set If I now try to build this You will notice And don't worry we'll get to this You will notice that what it does is it gets
That's if we were before we got to test out CPP And it actually was Able to sort of moved past that And move on to doing other things now He tried to lock the Microsoft resource compiler And that was because we have a resource files Singing here and it created This project for awesome A resource compiler is nothing fancy
It sounds a lot better than it is you're like a resource Camp I like it to pile my games resource with that Not very likely And you probably don't want to do that Myriad reasons but What the refractive actually does is the resource compiler does things like packing up an icon For your application And sticking it in somewhere Where the
But where Windows could find it in the executable so that I can display it next year schedule things like that so that is something that you do need to know how to do Eventually The right now we don't care at all obviously didn't actually do anything so to finish that up but then it got to the stuff that I actually want to talk about Which is linking No blinking is Is linking Is sort of a
A backpack Tennis compilation Process Now what we could do You know compiler certainly could Take a text file and it could directly make an X Skittle out of it if that textile contain everything that needed to Define their stupid butt What usually happens more often And Harley for legacy reasons at this point but You know What can you do
What happens more often if you have a lot of text file so you know the code for game could be hundreds of thousands of lines of code Kodak It's a lot of PCP files that we're going to Learn how to write here And In order to Quote on quote save compilation time And various other reasons What a dolphin wants to do is be able to compile each file into an intermediate file
Doing one part of a compilation process one part of the bruising Deleted file will basically be The process that takes the text and turns it into mostly Code to see if you can actually put their a bunch of things that aren't quite done yet Windows intermediate files Don't always have to be updated they only have me updated when the particular Source found that they came from changed
So for example this test ICP If I don't change test at CPP won't have to recompile testout CBP if I had tons of them Other files productivity bar. CDP all these other files Guy sings just one of them you would only have to do the recopilation I just one of them But Does all of them have to be pulled in made into an executable at the end They basically have a second stage
The compilation process which is called blinking And that's what this line does here And what Lincoln is about is licking is about Gathering all of that process Sing together All of us intermediate files And Basically resolving the places Where is Bay Point to each other So I made you a bunch of things in test out TPP That are going to Call out and and or reference 2 or or use data from Older
CPP file so I can pile And Since the compiler is only looking at each individual CPP file as it goes in Found them It can't resolve those references It can't tell Where the things are that things are pointing to because it's only seeing one individual files so what the Linker does In this link stage There's a thing called a liquor that gets executed Separate from the compiler And what it is
Is it is something that gathers all this together Resolve the references Packages into one EXE Which you can then ship Now when I say which you can then ship That was the good old days There's a lot of reasons why you can't actually just you Thanks to Microsoft in their Tyler's Pursuit Lawmaking building applications complicated But I'm going to hold off on that for now
So that we can focus on just the basics of the process in It's a lot to absorb I don't want over complicated More than it already is So in the linking stage You will see that we've gotten to our next Air And that air is this line right here you'll notice that it doesn't give me a line number and that is cuz Microsoft Linker Is not particularly good
I don't know if they fix this and one of the more modern versions but Even as of 2008 Their liquor never bothered to tell you where your errors are so all you get Is which function It was referenced in That makes sense So basically you will know you will know very little you'll know like what file maybe May Made the error possibly and you'll know what function
What's causing the problem or things like that and we'll kind of get to what all those mean and how to stop them out later but basically you get very Cryptic message for a blinker fortunately Most of the time winter errors are simpler airzooka Power air so it's not too hard To figure out what they mean So Look at this error What it says is unresolved external symbol underscore winmain at 16 Referencing function Tri main CRT startup
And then goes on to tell us that that was a fatal error So there was one unresolved external And now what that means just what I was just saying and unresolved external What external means in this case is external to the population unit in which it was being used So when I compile test at BP or something It's got a corresponding file That the compiler produced at the Linker isn't pulling in
Things that are external to that file are called externals And when you see one unresolved external it means that it came across one of these Couldn't resolve the couldn't find any Actual definition of that anywhere else in the other file so what can I do it can't finish linking Because it can't figure out What it was supposed to do there So again we get an error
This time it says 2 hours but really it was only wanting her But that's just the way I guess it Decided to print it out and not sure what the secondary is but hey What you going to do Anyway Nobody gets now that we see what I look for areas we can start to the bucket So What actually happens If you think about it when you run an executable There is
Something kind of complicated but has to occur Which is that Windows Is actually the program that's running on your machine So the processor your machine is executing windows And now we have built something that we would like Windows to start executing But windows and our program We're not linked Together right This linking stuff that I just explained where hey we can write some stuff and it pulls out together and it references each other and everyone's happy
It makes sense if we typed in all the code But if we only typed in some code That has to be started by windows are started by some operating system will How does it know where to start how does it actually get started And the answer to that is basically that The linking process Even though it seems like we're going to finish it here in a minute Is never actually really finished In an executable
Unless what you're building Is the whole operating system If you are building a kernel You know that runs the entire machine then and some sense you've built the entire program in Lincoln can resolve all external And even that maybe isn't Totally true because even in that case there is a bios in your computer and that by us has to know how to Load something
And start executing it which is the colonel that's on the disc so you know it's complicated if you actually want to go all the way Way down to the bottom And open up the Russian nesting dolls all the way down to what's actually happening In your machine when you actually turn it on But Assuming that you're already running a program Like Windows that's enough free system setup To run executable content The question is
How does Windows actually know where to start how did they know what to even do with this file Any answer is that executable file format Executable jar files on your disk just like a bitmap or anything else The executable file format is basically set up in a way that Windows understand so that I can open it and read it And read out of it information That tells it Where to actually start executing
So when Windows wants to run some of your Code if it's we can load that file into memory Do some work on it but it needs to do Which will talk about again In a little bit And then it will use information that was put in the Goodwill by the slinker in fact Which Talbot Where in the Bible we wanted to actually start executing sewing memory where should it actually Jump to
To actually start executing and tell the CPU here's where the code is go running Any answer to that Is The way in which we tell the Linker Where we wanted to tell Windows where to start Is it we use a predefined name And we name something that name So that I can find it in our code Now That's not entirely true Because we actually could go into the Linker itself
And there are settings which we could modify that would tell it to use some other name For example through here But most of the time nobody actually does code that way most of the time people just use the default name And that default name name Is actually Well I'm going to stay at Twin name
I will see you in a second it's not actually women but I don't want to spoil the surprise I'm going to say this with me And what you can actually do if you You're not going to probably remember a lot of The stuff that I'm saying and I and I totally respect that I don't remember all the stuff all the time Either I always am looking things up Ion msdn which
If you type women into your Google search box You will get the first hit As this site called msdn. Microsoft.com
Which we are going to be using a lot As we learn to program C in Windows because it is basic Repository For all of the stuff that is Windows specific About program And since we're going to be putting you in this for awhile that matters to us Because we are possibly going to have to look things up at least in the first couple weeks Look up things that tell us how to interface with the offering
Now in here you can see The definition We met in the documentation for it tells us a bunch of stuff If you are beginning c programmer you will understand none of this and that is okay One of the things I am definitely going to do in the series is go over things many times we're going to go over things in depth
You don't have to worry about the fact that a lot of the stuff that we're going to do may not be completely understand if you understand Able to you at the moment I will always try to explain as much as you need to know then And then we will go into more detail later as necessary because I don't want it to bog down
I do want to get bogged down fairly often but it don't like it to bog down And You can also email me anytime you have a question and we will try to work those questions into future Editions of Web series So This right here Is what it's called a function prototype And we're going to be dealing with these a lot But basically what it does is it Tells you The way in which
A particular piece of code needs The star Texaco And we'll get into a lot of Stop with these later so I won't belabor the point the basically this is the predefined entry point That we will be getting called at When we start executing And so if we want to Define it in RC program We have to basically do something like this We have to go in and Define this Just the way that they didn't hear And
When we Define this The Linker will now see the symbol this win main symbol And it will know that that is the place That we wanted our Are execution for Windows Now if I go to build again and you'll see there's a there's a shortcut to a here which Ff7 so it's good to learn this was you build programs a lot If I build it with S7 you'll notice one of the things that happened here
Before we get into two eras What is going to happen series Save the file automatically I don't know if you noticed the green line to the yellow line turning green One of the things that happens By default in the setup for for For Microsoft Microsoft Visual Studio Is it when you build something it will save files that are unsaved That's actually something you can change here in the tools option If you want to
I change that stuff there's there's things in here that That affect things like that I don't have it remember exactly where that one is I think it might be in documents But I don't know Build projects I have no idea where it is You will have to hunt for it my friends because I have no idea where that actually is But Etsy There it is before building Save all changes
And you can set that other things like don't say whatever so That's just a custom my picture liking but you will notice that is why you have to save the file Before I go So if I hit that 7 it feels the file and you will see That we have gotten some errors here And the errors are because we have started to use Windows specific thing And windows specific things aren't defined by default In our secret
So what we have to do is we have to bring in something sad to find Again don't worry too much about this because we're about to discuss it in detail I just want to finish this one process first Before we go back here So I have done that And now you will see And I suppose I will have to remove these To also How to put those back Things I wanted to talk about this
I was hoping they would be allowed So That did a successful field but I want to break it into two parts because I can't leave these in declaration Gyms in there Until If I want Taxi So Miss particular definition Basically uses a bunch of words Windows has to find them We're going to talk a lot about how we Define those things are things later but I wanted to display nuts Quickly
These things are all stuff that Windows defined that are specific to Windows They're all things that you won't probably ever actually see if you're programming in a higher-level language I've never really programmed in C sharp Specifically So maybe some of the stuff still creepy Through that's entirely possible But a lot of higher level languages Obscure the underlying things that are happening in the windows code And so you never will actually see them
But when we are apart of me and see it specifically when we program in low-level see that we want to directly interfere Face with Windows as much Possible to avoid any sort of Intermediaries We will have to deal with a lot of bees No I'll get in touch with you specifically mean in a in a bit but you will see where it's like this LPS Easter Now what is LP sturmey what what does that mean
Even an experience Free programmer who's never programmed in Windows before Would not know what LPC Mr met so it is not the fact that I haven't explained What this definition is or how any of this stuff in this file works that is why you don't understand it if you're beginning You got a friend This is actually complete gobbledygook 28 experienc programmer Who hasn't actually ever prevent windows before Because these are things that Windows made up
They made them up To use to reference specific things in their operating system Which we will have to enter Interesting For example Is a running program It's something that refers to running program and LP stir If something that is a pointer To a string like a string of characters like some text For example And you will notice something that occurs in these that is kind of frustrating These weird little H's because hey Instance
Well that makes some sense that English right I mean That makes no sense to use an instance of a program Str that kind of makes me like a string Str stream MX But like LP and age Repeated over here Okay pre Vincent previous since that makes sense instance that makes sense CMD line command line I can read this evening if I don't understand anything about programming language
But these weird little things here H&M LP there's are confusing Where do they come from The answers they come from something a long long time ago in Windows history Called Hungarian notation If you want to know if that's racist well it probably is it's just nobody ever Complain about it being racist Because most people Aren't racist against hungarians I don't think they are not a typically Oppressed class during Washington State
So probably no one got upset about it but to be honest with you it's pretty racist to call Hungarian notation Call Victoria notation is because the guy who introduced it What is Hungarian I think it was Charleston money I don't actually know I don't remember who it was but Hungarian notation Is The sort of Antiquated at this point I hope Notion that you should prefix everything That you ever typed Into a programming language
With some characters that tell you what the thing actually is So some kind of notion of what the thing is Key in this case was pointer I think L was long Meaning it was it was a pointer that was into memory in the old 16-bit days that was outside the PayPal Cuz I mean program Mark 16 bit Windows I don't at this point my memory of what LP stand for Completely.
They just handle it means something that you would use to talk Two windows It'll take me about something and you will see these littered everywhere they are super annoying Because they really just do not helping me make things harder to read Cannot emphasize enough please don't do this is a terrible idea What can I say no you will see in modern code Some people still do a variance of this They will do things like
IP Foo if something is a pointer to food which will talk about a Wild Bill's um Foo or something cuz I'm Number which is if you're doing object-oriented programming which we are really cover so Don't ever find out what that is but You can go watch someone else's track on Ustream Belinda Anyway
That's what these annoying things are and you can pretty much ignore the most of the time although if you know how to read it it does help you if you just had Happened to Try to decipher something in Windows that's Somewhat obtuse maybe you can use that To help yourself So there is Anyway If I said I want to talk about before we get into explaining exactly what all this code does And how see
Work sort of At a basic level Is these things right here So What you will find If you actually look at Windows code as you will see that there's a lot of annotation in it There's not actually designed to be processed and see necessarily but that is designed to be processed by something Say a documentation system that also reads the same files Or was called the middle compiler which is a thing that is used to produce
Secondary files for Object linking and embedding and all this other windows crap We don't care about any of that stuff but You will see things like this Annotate some of the functions that you call and they see what this means In Is it telling you what direction The data is flowing No it's not actually something we want to have in here when we actually Define it is It's strictly for their header file
But when you see it when you look at them sdn you will see it there and that is what that mean Means that this is something That is going to Windows using pass Into windows As opposed to an out parameter which is something that would be passed Out to you back from window And we will look at those We will see those working Mini Things we go through Getting a windows program
So I'm going to go in here and delete those because you don't want to leave those in I guess I've never actually tried before to leave them in I was kind of hoping you could Just so that you could just So where we build we now have a successfully Building Program And What this does is this means we actually have produced And I will file and if we want to We can actually run the executable
So in here you can see there is build solution But in debug in the debug Menu You will also see that there is a way Play to actually run the program Which is start debugging And that will actually run our program Africa That was our program Did you love it I know it's right side So nothing strange but that actually did run our program our program doesn't do anything so it just started it
And then I deleted it But you can also see hear some debug information that was printed out Buy the actual startup code Which is telling us something I'm sorry but that's exactly by the butter Wichita keep telling us some things for example It's telling us that it loaded Pepcid AC unit Let's get information for it Hey buddy some other things Depends on So yeah she did Runner program Isn't that a
Well let's complete that before I slam whatever Does With one Simple thing that we can actually Morrissey Very exciting We are going to run this And oh Oh man I get there Everything So as you can see now the program but as I modify everyone lying to it and now it's actually prints out As part of Its Behavior To the debug output It prints out of string That we wrote Craigslist
I know that you are all very excited I am very excited as well about this And I think It is safe to say That once I explain how this works You are so on your way to create a game with Windows If you can print something out of the debug window How much more work Couldn't even be to make a game Certainly not much Well Maybe it's a little I'm sure we'll be able to
In Future rapper So Now that we have a working windows program Even though it really Very much Let's go through and see what everything did I'd like to start first With the things that I typed in But couldn't actually be called by Windows cuz it was just a sub box didn't do it I could do anything and wasn't in the format that it wanted and terms Blinking us What this is Empty Is a function death
Now hopefully most people have Are coming from other programming languages to have a passing familiarity with What function is So I won't belabor the point too much Paisley what a function is Is it something It's sort of a reusable piece Summer program It's something where I can put some code in I can I can put some stuff in that it can do And then I can use it Anywhere I want to
So anytime I want to basically go do the things that the function does I can do what's called a function Call And I can call into it Now without actually Explaining The signature quite yet We can actually see this in action By moving the line that printed stuff out Into My function that I defy Find before now when I run You will notice I no longer get The printout You know It's not there Too bad
How do I actually do it well I just function called that function And now the thing is that it does Get done where the Function call You can see now Carpenter Seriously what function is it something that holds some code for us In a way that we can reuse Encoding is about We use a lot there's a lot of stuff encoding that has to do with sort of
Building little pieces then work together to make a program It's very very difficult If you were to sit down and write the entire program in one function That would be really really difficult to do And it's a lot of reasons why you would not want to do that Which hopefully with my parents we go on but That is what function is and now you'll notice our function How to draw the parts to it
The first thing it has its word void What the word void means there's this section before the name of the function Images fear This section here Tells us if the function Returns anything And what that means is When this function is called by somebody when someone asks it to do the work Does it provide anything back Two dots To that call or to the person who invokes it And it's actually more ways
But you can actually have that happen than just this This is the most basic way What void means in C Is basically nothing It's like saying I don't Provide anything I am not going to give you something When you call me So the void in front of food just says this function produces no value for its color it does not act Chile return Anything to the person who called me The next part of our function decoration
You can see here In parentheses Is another voice And what that is is sort of the opposite of The Return part It's what does this function expect to get From the person who called it So what Things are going to be sent Down to this function in order to get it to do the work that it needs to do And as you can see it also void which means nothing
This is a function that returns nothing and takes nothing And of course That makes perfect sense given the fact that Outputdebugstring Just print out of string It doesn't need anything to do it So That is our function Apps that you can see these little plus and minus is he related to collapse functions if you're trying to So After that Which is basically the thing that tells us it's called the function prototype Piper the function signature
This right here This is called Prototype And what it does is based It defines the circumstances If you will for how the function Just called what does it take what does it return We then have the function body This part right here is a function body oh and I will note This right here DS2 of flashes What is something that says I'm about to type some stuff that's just a note to myself it's a comment
It has nothing to do with the code But if that's something You know what to do with my thought process SOC allows me to do that anywhere I want to C & C plus plus have to start with comments there's this kind Which are bracketed by these little guys which is a lot like HTML a favor program HTML you know You've got these two things Right if you can use to enclose things and quotes
Enclosed things as a comment but doesn't actually process So that's something that doesn't there and that basically says from here everything ignore until you see one of these Right so can be multiple lines and all that stuff This kind is a kind of was introduced with C++ And what that does is it says ignore them to the end of the line Get to the end of the line Star-Crossed
And that's just a sweetie cut down on some typing it means you didn't have to type one of these at the end It's a little convenient It's not really that important but you'll find it's more convenient I just typed So anyway that's the Prototype of my function in this is the body The body of the function Is what it actually exit So when this function is invoked This is the code that will occur
And everything in between these two curly braces Are things that will occur So all the codes we put in here Will occur On invitation The function Principal right Not much to it And you can see You really don't need much else understand what our function actually does the code Inside the Box Office Depot Because all it does Is it called another function A function we didn't Define Call output debug string a
And I'm going to check out the as Anyway as you can see When I want to call the function Syntax actually looks something like The Prototype These parentheses here Most likely to find what I was going to take These parentheses Contain the things That I'm going to pass To the function So in this case I didn't take anything Equity Bank Spring Takes a string NC The way that you define A basic string Just a simple spring
Easy book quotes Double quotes Anything in between the double quotes It's part of the strain So This is a string that I have made And I'm passing it to Alba TX train so that you can print it out Apple TV screen is a function That works With the operating system in order to actually send stuff to our debug output Which Betty Buttercup Frozen Prince over here
Now we'll talk a little bit more about that although debugging services on Windows is probably not something we're going to cover into much detail But I will talk a little bit more about how that stuff works More in-depth after we kind of go through in are more comfortable with just basic Sexy code Okay So after that function is called You'll notice there's a semicolon
A semicolon is a weigh-in see of telling the compiler that you're finished with a particular logical line of coke Now it's not a particularly useless piece of syntax Not particularly useful Pizza syntax it is a relatively useless Pizza Center A lot of things just don't need semicolon In a lot of languages only semicolons once in awhile or end-of-line 2 limited license Understatement The beastly all doesn't see in C plus plus is what the compiler know
That the things on that line Other things that were part Of a logical piece of code have now concluded And so there might be more things on here that are part of this logical line of code and we'll start to see more of those later The base of a semicolon says that the end And that's called a statement One line of code like that terminate by semicolon Because it could actually go on for longer
The End of Line actual end of the text line Doesn't really mean anything MC plus plus It's not like python or languages were white-faced mean something In general like this Whiteface here that I use to indent To put this thing So I could see that was part of the function more easily That's really my decision She doesn't care she just doesn't care about that Cimorelli it doesn't care about this white space
Basically the only time Serie to care about white space Would be if you were to insert it into something it was supposed to be a single name Whiteface does breakup name NC and so basically output debug String a Would not work if I were to compile this you would see that it would say that it doesn't know what output debug is
And the reason is because I Saw the space and thought that was a complete name that it's just hard to look And see what it means and it can't do that Something to get rid of that and go back to where we were So anyway that is basically How a line of code look NCAA Inside function No Let's go down to a more complicated function over here at the one that Windows call
So if you look here it's got a whole lot of decoration on it a lot more than we have here Got something called in the beginning that we know That is the place Where the return value goes where the thing that comes back from the function His place Miss In this case 10th and C is a special keyword It means editor so much like Boyd is a specialty word in seed It tells it nothing
Isabella keyword that says an integer value He's going to come back a number Basically a whole number -5 12 Something like this Is going to be returned From this function To whoever called it Whenever they call it Call back Is a piece of syntactic icing Which Actually expands to something else entirely It is what we call a macro in C
And we'll look at those little bit later on when I dive into this windows at age 5 And basically what it does is it expands To some special decorations that are used Only in Windows Only for this particular Windows called And it's decoration That tells the Linker And the compiler The dysfunction is special It is a function that must adhere to a special convention
Because since Windows was not compiled as part of our program and our program is not Compile this part of windows They will have to agree on how functions are called that makes They will have to agree on a And we'll talk about that little more when we start to talk about exactly how she actually generates Access code I think I'll probably be next Next Xvideo So anyway
Put that in the back of your mind for now but suffice to say this is a special macro that we're going to look at in the future that Tells The compiler and the Linker That this is a special function not like our run-of-the-mill function and then it has certain constraints that have to be met Why does the pile
We then have the parameters to the function the things up a collar provide these are things that are being Passenger the function that the function can use We didn't use any recent void here But women uses A few A few It has access The first one is HSN Is actually just a handle to ourselves What it is it's basically a handle that we can use
When were talking to windows again if we should do to talk to Windows To refer to our running program So for example let's say we need to do something that is very window specific everyone knows their service ever going to ask the windows car Hey we need you to do something to a running executable We need you to tell us about the memory this using we're going to we're going to access Addie bookkeeper Reducing stuff
And where specifically referencing This copy our copy in memory of our executable code That is what this handled does Is a handle that a lot that we can pass back to Windows to refer to ourselves Turns out you don't really need to Actually remember this or use it for Because most the time you can get if I back down I will cover that way Free Vincent you can completely ignore is Legacy thing
You will never need it in game programming is basically something That you needed to use in older versions of Windows sometimes In order to do things That had to do with previous runs of your programmer things like this Previous versions of your program that we're running in memory This right here Much like this string But we created this This is the first time you've actually printed store Miss LP store LP command line Is basically What
Got sent to us When We Were Young No The interesting thing about that Is although it's called LP command line It is referring to it as if we're going to call something from a command line Which we have not talked about yet and you may have no idea what it is But I will show you briefly What it actually is if you go into All programs You can go to a thing Call accessories and in accessories
There is a command prompt If you go to that you will get this thing This is a command line and we will be talking about how to use it later But what allows you to do is it allows you to run things like I can run notepad for example from it He loves you to run things and you can pass Stuff to them on fear that they will receive
Nekros I tried to pass that if you like I don't know what you're talking about cuz notepad doesn't Want to hear any of that But when you look at this you'll think of LT command line Well I don't need that cuz my things not going to be called from the command line and we just talked about the brave genius episode The fact that We're not going to be building a console application or command line application
So I don't care about that well not exactly true If you go in here And you open up something let's say Notepad itself Can I go to property You will notice But there's a bunch of stuff in here Well this target line Simon Says Target It actually allows you to put the command line after So it's entirely possible to shift Windows programs
Are not run from the command line it will never be no one will ever run them there It's still take a command line And so it's important to know that that's there I know there's other ways to get that We'll talk about And finally Anchorman show It's basically a parameter But just back again To this disorder properties I don't even know if it Still there I'm just going to see if it is Vans No Teeth
Hotels compare Purity I don't know what that is Can you list it for legacy reasons no almost no one ever uses Best butt There's still a drop-down that says whether you want to run a particular application minimize or maximize or just in the normal window So that it would open If it wasn't told to do anything specific well That gets passed to you right Shear n Comanche And that is basically a number That corresponds
To which of those things was selected and we'll look at that in In a little more detail later it's not exciting but you know Might as well if they're Play me those are things that we are passing me start up and then we have another function body just like we had up here And we call function just like this. A function in that function is our road And it does apathy books That is
A complete C program With a function calling it even But that you don't quite know everything about because there's things in here Dinner Define dusk And so the question becomes Well You know if I was to do this Far Western just run that You will notice that I couldn't do it Because it says Who identify was not Found Cuz I deleted That from my program And When we get to the Welcome I should mention weather thing
You may wonder if this point Since there was no Foo why wasn't that a linker-error instead of a compilation error This is the compilation there remember I said in the past the Linker is the thing That gathers things up into one Peace so that they can essentially be Taken And and made into and have their references sorted We combined all point to each other in the proper way
You would think of that era would come then right Why does it come drink compilation Because it should have come at the step when people try to resolve reference as well the reason for that Iams this is actually a good thing to bring up I'm happy that Better that I remember that What are the reasons But that happens is because C
And C plus plus are languages in which you are never allowed to use something which has not been defined yet NC There were looser restrictions on this And so it some things and see would work even if you didn't Define Minuet in C plus plus date Titans that down they tighten the ratchet on that So you always have to find things before they are called Since this isn't defined it can't be called
Now that many leaves you wondering if you can't If you can't actually Call something unless it's Define well how are there ever unresolved external symbols The answer to that Issy allows you to do what's called a forward declaration Functions are split into two parts essentially They are split Into a declaration And the definition Now definition is the full thing It's the full function
It has the Prototype and it's got the body so it actually is the thing that you need If you want to run it But you could instead make just what's called a declaration and a declaration Looks like this It is the first Don't you just love the pretty green, They're so lovely Anyway Inside here We basically have the same exact stuff that we had here But instead of it actually Providing the body it just
Put the semicolon and ends if they still use that I'm done Semicolon marker to say I'm not actually tell you the body I'm just going to tell you the signature And Once you have that signature You will see that I can actually build And you will notice that now or compile error has become a link error And the reason I care is because now it's legal to call the function during compilation
And it the compiler will just assume That since it has all the information used to call the function which is the signature knows what it needs to pass it knows what it will get back It just goes ahead and does The compilation that started to Producer call and leaves Essentially marker that it says hey Linker When you find this function Please pass it in here because I would like to call it All right
This is quite via the laryngitis seducing Stream I'm going to have to talk quieter Anyway So We actually fully defined our funk So we have a fully buildable program But Could find this function And for that matter you to find me this stuff You'll notice that these things in blue They're automatically being syntax highlighted by Visual Studio Bee stings in blue They are keywords they're built into the Tyler you can actually type these in
Alongside the brackets The semicolons the parentheses These are part of the language They will work anywhere they will work on any c compiler that you ever want to use But all this stuff Where did that come from that's not mistaken power units is not turning blue is not a keyword I can tell you that And neither is this guy And we need to find that function somewhere to come from The answer is Vista find that phone
So we're going to get to the last line here And then we're going to wrap it up For tonight because I want to try to keep these two roughly an hour And we are about an hour So Okay This is a line which says I want you to go find this File Is actually a file name It could have a complete path if you want Whatever It could be out the full on
In anything any filename you want to put in there Although in general Most the time you use for its lashes even though you're on Windows because forward slashes work for includes no matter where you are Where is backslash enjoying working windows with us Hey play think it's a filename any phylum a drive you can include and really all it means For all intensive purposes Is go get this file Inspect the entire contents of it Right here
I'm so this essentially makes Are very simple program That's only a dozen or so lines long It actually makes this a very long program Cuz it goes and What's this file I should tell you how to do that If you right click on one And knows where to find it you can go open document and it will jump right to that file I just got a nice So this is Windows. 8
Which is the file that we included Let me not look like much It may look like a bunch of gobbledygook but relatively minor gobbledygook if not It's absolutely massive And the reason for that If it's all just a bunch of more includes That's going to include this Right it's going to go down here And it's going to include This And it's going to include All of these things Right Who knows
You got to go interpret all the crazy stuff I don't even know what it's including And all those things include more things happening things Have included them as well this one includes this one So there is a huge nightmare Amazon closes with this Alexis I don't actually needs to be open but Anyway Pound including this town and close Windows 8 foot pounds includes all kinds of stuff From the operating system Include files
And those include files are designed To Define A bunch of functions like these That you used interface with Windows and a bunch of special macros And types of other things that will get into next week That are designed for you to be able to read Steve information From Windows as well And so That Define this That is hard to find All of these things And that is why this is a complete program
Cuz without it it would not be Orange No I think that's a good place to stop Because the next step here is we're going to start to look At exactly how this program works I'm going to step into the Assembly Language it was actually generated We're going to look at how linking actually works Where talk about the C runtime Library And We're going to look at why I said Win Maine With actually a little bit
Of a of a Misdirection Why it's not really the entry point for your program Even though I said it was going to be Went to the program and it sure seems to have been the end All that We will get to tomorrow I believe As we Further continue Our introduction 2 C programming on Windows I hope you have enjoyed this Stream And I am going to stop the recording now But I will continue to take questions
On the On the live stream And I will split those Into a A separate record
Loading video analysis...