Using the Microsoft Advertising SDK for Windows 8 Store with VB


It is relatively easy for you make money via advertising in your apps. All you need is a valid Windows Store developer license and the Microsoft Advertising SDK. You're not here to read about all my ramblings, so without any further adieu, let us start.

Microsoft Advertising SDK

The Microsoft Advertising SDK is, as its name suggests, a means for us to advertise products in our programs. We can get the advertising SDK here. Download it and install it. It is a very small file (I think just over 1 MB). This will give us a few advertising controls in our toolbox, as displayed in Figure 1.

Advertising tools
Figure 1 - Advertising tools


The AdControl is the most common advertising tool found in most Windows 8 Store applications. It is very easy to use and set up. Before I get too far ahead, let us start a quick project and configure it to show ads.

Our Program

Our program is quite small, and its sole purpose is to get you started with working with ads.

Create a new VB Windows Store Project. If you are not sure how to create a new Windows 8 Store app, have a look at this article I wrote a while back. You could name it anything you like. With this example I have aptly named mine Ads.

Now, we need to reference the Microsoft Advertising SDK. We do this by following the next few steps:

  • Click Project, Add Reference
  • Inside the Reference Manager window, expand the Windows group
  • Inside the Windows group, click Extensions
  • Select Microsoft Advertising SDK for Windows 8 (XAML)
  • Click OK

You may also need to add the Internet capability to your app, as the ads will get downloaded, fetched from the internet. If this capability does not exist yet, follow these steps to add it:

  • Inside Solution Explorer window, double-click the Package.appxmanifest
  • Select the Capabilities tab
  • Select the Internet Client check box

Now, we can add the AdControl to our form. You can place it anywhere, as this is just an example; but in normal circumstances you'd have a clear idea of where to place the ad. Figure 2 shows the added control to our form.

The AdControl is added
Figure 2 - The AdControl is added

The following step is to configure this ad control so that it concurs with your customers' needs. We now have to set properties such as Height and Width. A complete XAML code representation of your AdControl might end up looking like this:

IsEngagedChanged="OnAdEngagedChanged" />

A couple of interesting properties here! HorizontalAlignment and VerticalAlignment makes sense, as do the Height and Width properties. The rest however seem strange. Let us look at each one of them.


Each ad will have its own unique identifier. This is not simply a random number which I thought up; I obtained this number form Microsoft's PubCenter (which I will explain later in detail). Each AdUnit will have to have its own unique ID. In the above case, this ID was assigned to me.


Just as each AdUnit must have its own identifier, so should each application making use of ads. Again, this Id was assigned to my program via PubCenter.


Enables or disables automatic rotation of ads.


Gets or sets the latitude. Not really necessary when you have set the Horizontal- and VerticalAlignment options


Gets or sets the longitude. Not really necessary when you have set the Horizontal- and VerticalAlignment options


Raised when the AdControl receives a new ad.


Raised when the AdControl encounters an operational error.


Raised when the user clicks the ad and the action dialog box appears.

Now, let us take a good dive into Microsoft PubCenter.

Microsoft PubCenter

Earlier, I spoke about Microsoft PubCenter assigning an ID to your applications as well as each end every ad. We find the PubCenter here.

Once you are there, you are already halfway!

Register your program by giving it a name. Once that is done you will recive an email confirmation as well as your screen will resemble Figure 3.

Application confirmation
Figure 3 - Application confirmation

Now you need to create the ad unit(s) by clicking on Create application ad unit, as displayed in Figure 4.

Create an ad unit
Figure 4 - Create an ad unit

Fill in the information, such as location as well as the name, as in the next figure.

Ad Unit details
Figure 5 - Ad Unit details

The final step is to confirm. Again, you will get an email, and your screen should resemble Figure 6.

Ad Unit Confirmation
Figure 6 - Ad Unit Confirmation

The IDs which PubCenter gave our app and our ad or ads must now be used inside the AdControl. Now they are linked.


All that is needed from your side is to include the following events in your app:

 Private Sub OnAdRefresh(sender As Object, e As RoutedEventArgs)
''' The code below will print information about the AdRefreshed event to the Debug Output window of Visual Studio
Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " Ad Refreshed.")
End Sub

Private Sub OnAdError(sender As Object, e As Microsoft.Advertising.WinRT.UI.AdErrorEventArgs)
''' The code below will print information about the ErrorOccurred event to the Debug Output window of Visual Studio
Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " error: " + e.Error.ToString() + " -- " + e.ErrorCode.ToString() + ".")
End Sub

Private Sub OnAdEngagedChanged(sender As Object, e As RoutedEventArgs)
''' The code below will print information about the EngagedChanged event to the Debug Output window of Visual Studio
Debug.WriteLine(Date.Now.ToString() + " : " + sender.ToString() + " EngagedChanged.")
End Sub


You can test your ad units by supplying the Test Mode values for your AdControl. This ensures that nothing goes wrong and your ad works as expected


This concludes this introduction. The rest is now up to you to get sponsors for your apps, and I wish you good luck with that! Until next time, cheers!

About the Author:

Hannes du Preez is a Microsoft MVP for Visual Basic for the sixth year in a row. He is a trainer at a South African-based company providing IT training in the Vaal Triangle. You can reach him at hannes [at] ncc-cla [dot] com

Related Articles



  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date