Installing the latest version of Boost C++ from source on Windows for use in Visual C++ in 5 simple steps

by APIJunkie 23. January 2012 06:38

If you wish to use the latest Boost C++ libraries in your Visual C++ projects and the automated Boost installers at: http://www.boostpro.com/download/ are not up to date, crashing (happened to me) or you just want to build them yourself,  you can follow a few simple steps to get the job done.

1. Download the latest version of Boost from:

http://www.boost.org/users/download/

The direct link for the current version (1.48.0) can be found at:

http://sourceforge.net/projects/boost/files/boost/1.48.0/boost_1_48_0.zip/download

 2.  Extract the compressed file to a directory of your choice

Example: C:\SrcLibs\ boost_1_48_0

 3. Open a command prompt in the directory you created in step 2.

Example: C:\SrcLibs\ boost_1_48_0

 4. Type the following 2 commands at the command prompt:

 bootstrap.bat

 b2

 The above commands will configure and build the Boost libraries from source.

 It will take some time to build the libraries depending on your hardware.

 If all has gone well you should see a message along the lines of:

 The Boost C++ Libraries were successfully built!

 The following directory should be added to compiler include paths:

     C:\SrcLibs\ boost_1_48_0

 The following directory should be added to linker library paths:

     C:\SrcLibs\ boost_1_48_0\stage\lib

 5.  Add the Boost include and library path to a Visual C++ project

For example in Visual Studio 2010:

Create a new C++ console application

Go to Project/Properties/Configuration Properties/VC++ Directories/

Set Include Directories to:

C:\SrcLibs\ boost_1_48_0;$(IncludePath)

 Set Library Directories to:

C:\SrcLibs\ boost_1_48_0\stage\lib;$(LibraryPath)

That’s it; you can start writing code that uses Boost…

 

 

 

Tags:

C++ | How To | Visual Studio | Boost

How to develop native apps on VS 2010 targeting Win 2K and older Windows versions

by APIJunkie 24. March 2011 03:41

By default when developing native C/C++ apps using VS 2010 beware that your executables will not run on Win 2K and older targets.

That is true even if you remove any external dependencies and adhere to Win32 API compatible with older Windows versions.

One possible solution to the problem is Native Multi Targeting - using the VS 2008 compiler while working with the VS 2010 IDE. Assuming you can afford to have VS 2008 installed on the same machine.

 

Tags:

C | C++ | How To | Tips and Tricks | Visual Studio

Creating a Self-Signed Certificate for use with IIS on Windows Server 2003

by APIJunkie 25. June 2010 23:47

This is the second time I had to find the solution to install self assigned SSL certificates on IIS so I am writing this down for posterity.

 

In many cases it is desirable to create your own SSL certificate when working with IIS.

For example when developing/testing SSL secure web sites, when using a custom web application in a local intranet or for a closed  group of users to name a few.

 

It should have been easy to create your own SSL cert and instruct IIS to use it.

Microsoft delivered a tool to do just that. It was a part of the IIS 6.0 Resource Kit and it was called SelfSSL. But alas because of a bug in the SelfSSL tool you will run into problems if you try to use multiple certificates on a server.

 

Apparently Microsoft decided not to release a patch for the resource kit but instead released another tool that can be used to create self SSL certificates called SSL Diagnostics.

 

The tool is very easy to use. There is a nice tutorial on how to use the SSL Diagnostics tool to create an SSL certificate by Revindex.

 

Another option you might want to explore is using the open source alternative called OpenSSL. There is a nice tutorial on how to use OpenSSL with IIS by Dylan Beattie.

 

Best of luck!

Tags:

How To | IIS | Tips and Tricks

Using the free Babel Obfuscator in Silverlight projects

by APIJunkie 4. February 2010 05:24

One of the problems with Silverlight managed code is that it can easily be reverse engineered using standard .NET reflection tools.

Although no method can completely prevent reverse engineering your code there are ways to slow down and even deter all but the most persistent hackers.

Most of the tools I found that can be used to obfuscate Silverlight code are not free. But the Babel obfuscator by Alberto Ferrazzoli is an open source .NET obfuscator that can be used in Silverlight based projects.

Babel is a command line tool and it can be integrated into your build process. One way to do that is to add it to your post build events.

When you run babel on a target dll (assembly) it will generate an obfuscated version of the dll in the directory “.\BabelOut” relative to your dll output directory.

Usage Example:

"D:\Program Files \Babel\babel.exe" $(TargetPath) --noildasm --nomsil --noinvalidopcodes

Some caveats that apply to current babel version 2.0.0.1:

1.       The current version does not support obfuscating xap files directly but you can unzip the files first or integrate the babel tool into your build process.

 

2.       Not all command line parameters/options are supported in Silverlight projects. The following options work:

       --noildasm --nomsil –noinvalidopcodes

 

3.       Some assemblies (dll’s) that contain resources do not seem to obfuscate correctly (Its very easily detected they are not usable after obfuscation). If you have this problem you can always move all the sensitive code into a separate Silverlight code library and obfuscate only the code library.

Example:

Let’s assume you have one monolithic project called: “MySilverlightApp” that contains all the code and resources (xaml, images etc.) that will not obfuscate. To solve the problem:

1.       Add a new project to the solution called “MySilverlightAppCode” of type “Silverlight Class Library”.

2.       Add a reference to the new Silverlight library from the “MySilverlightApp” project.

3.       Move all the sensitive code files into the new Silverlight code library (“MySilverlightAppCode”).

4.       Obfuscate only the “MySilverlightAppCode” assembly (MySilverlightAppCode.dll).

 

Tags:

Silverlight | How To

How to add Silverlight version detection to Google Analytics

by APIJunkie 15. May 2009 06:35

One of the things that are currently missing from Google Analytics is Silverlight detection. Normally this type of information would appear under the browser capabilities section, the same section that lists Flash and Java versions. While I'm sure this will change eventually, it is something that can be very useful to web sites hosting Silverlight applications today.

In order to bridge this detection hole here is a simple solution that would plug this information into Google analytics.

The solution is based on 2 things:

1. Custom visitor segments  - Google Analytics allows us to create user defined values that can be stored and reported upon.

2. Silverlight JavaScript detection code - Code that allows you to detect the installed Silverlight version on the client's browser.

Awhile back I showed how to detect/report the current Silverlight version in JavaScript. Combining this code with Google analytics code to report user defined values is fairly simple. The following code is a rough example that would do the trick:

////////////////////////////////////////////////////

// Google analytics include files

////////////////////////////////////////////////////

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

////////////////////////////////////////////////////

// Report Silverlight version to Google analytics

////////////////////////////////////////////////////

<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-xxxxx-x");

pageTracker._setVar('SLVersion ' + getSilverlightVersion() );

</script>

////////////////////////////////////////////////////

Notes:

1. Remember to replace UA-xxxxx-x with your Google analytics code in the code example.

2. The information you report to Google analytics will appear under user defined values in the visitors section.

3. You can use Advanced Segments to integrate your user defined values into other reports.

4. There is normally a time delay in Google analytics reporting so it might take a few hours before you start to see the effects of your new code.

Good Luck!

Tags:

Silverlight | How To | Google | Analytics

How to programmatically detect Silverlight version

by APIJunkie 24. April 2009 23:39

Two questions that often arise when building Silverlight based websites are:

  A. How do I detect if Silverlight is installed on a visitor's browser?

  B. How do I detect what version of Silverlight is installed on a visitor's browser?

The answer to A is relatively simple since Silverlight.js (the standard Silverlight javaScript include file) contains a function that we can use. The function is called isInstalled and it returns true/false. You can use it the following way to detect if there is any Silverlight version installed:

<script src="Silverlight.js" type="text/javascript"></script>

var isSLInstalled = Silverlight.isInstalled(null)

The answer to B is a little more complex since for some reason there is no direct way to get Silverlight's version number. Basically the only documented way to answer this question is to repeatedly call isInstalled with different version numbers until you get the right version.

Example:

Silverlight.isInstalled('3.0')

Silverlight.isInstalled('2.0')

Silverlight.isInstalled('1.0')

etc.

Every time we call isInstalled the function code goes through the same process of trying to create an ActiveX/Plugin object etc. In some parts of the programming world this kind of inefficiency would be labeled as border line heresy. But luckily Since we are normally only interested in Silverlight's major version we can do things a little more efficiently. The function below will only return 0,1,2,3 where 0 stands for no version and 1 to 3 stand for a Silverlight major version.*

//////////////////////////////////////////////////////////////////

// get major Silverlight version

// Return values:

// 0 -> Silverlight not installed (at least not properly).

// 1 -> Silverlight 1 installed

// 2-> Silverlight 2 installed

// 2-> Silverlight 3 installed

//////////////////////////////////////////////////////////////////

getSilverlightVersion = function() {

var SLVersion;

try {  

       try {

            var control = new ActiveXObject('AgControl.AgControl');

            if (control.IsVersionSupported("3.0"))                

               SLVersion = 3;

            else

            if (control.IsVersionSupported("2.0"))               

               SLVersion = 2;

            else

               SLVersion = 1;           

            control = null;

      }

      catch (e) {      

                     var plugin = navigator.plugins["Silverlight Plug-In"];

                     if (plugin)

                     {         

                       if (plugin.description === "1.0.30226.2")             

                          SLVersion = 2;

                       else

                          SLVersion = parseInt(plugin.description[0]);

                      }

                      else

                         SLVersion = 0;

      }

}

catch (e) { 

      SLVersion = 0;

}

return SLVersion;

}

-------------

* Note that this code will break with future versions of Silverlight/silverlight.js so it needs to be rechecked when a new version is released.

 

Tags:

Silverlight | How To

TIP - Dynamically Loading an ASP.NET user control in the code behind

by APIJunkie 8. January 2009 06:26

When you need to dynamically create a control or use another page's code in your code behind use the reference directive ->

http://msdn.microsoft.com/en-us/library/w70c655a.aspx

Note that you can sometimes get away with only registering the control. But expect to experience some odd compilation problems especially when dependent code is changed...

Tags:

ASP.NET | How To

Building Firefox Plugins using Visual Studio

by APIJunkie 22. September 2008 00:59

If you are in the business of writing components/plugins that work inside browsers and even if your target audience is Windows users, you can't ignore Firefox anymore.

IE is still the most popular browser by far but Firefox is a force to reckon with when it comes to writing browser plugins.

If you use Visual studio as a development environment and want to develop plugins for Firefox here are a few points to get you started.

First checkout the article OpenGL sample as Firefox plugin on code project. It is a great and simple example on how to write a Firefox plugin.

Second, because some things have changed since the above article was written, follow the steps below to get the Firefox plugin project to work on Visual Studio:

1. Download the Firefox source code version you want

    Example: the Firefox 3.0.1 version is found here

2. Extract to yourroot\mozilla

   Example C:\Projects\XProj\mozila

3. Download the Gecko SDK/ XULRunner SDK source code version you want

    Example: the Gecko 1.9 (Firefox 3.0) version is found here

4. Extract to yourroot\xulrunner-sdk(for Firefox version 3.0) or yourroot\gecko-sdk(for Firefox version 1.5-2.0)

   Example C:\Projects\XProj\xulrunner-sdk

5. Run unix2dos on npbasic.dsp and npbasic.dsw (you can find them at yourroot\mozilla\modules\plugin\tools\sdk\samples\basic\windows)

6. Open the npbasic Visual Studio project (you can find it at yourroot\mozilla\modules\plugin\tools\sdk\samples\basic\windows)

7. Inside Visual Studio go to project properties and set the additional include directories:

For Firefox 1.5-2 (gecko-sdk) change to->

yourroot\gecko-sdk\include; yourroot\mozilla\modules\plugin\tools\sdk\samples\include

For Firefox 3 (xulrunner-sdk) change to ->

yourroot\xulrunner-sdk\sdk\include; yourroot\mozilla\modules\plugin\tools\sdk\samples\include

8. Fix a compilation bug in npplat.h:

When building the project you might receive the following error:

error C2146: syntax error : missing ';' before
identifier 'ContextRecord'

The error can be fixed by changing the order of some of the include files inside npplat.h.

The following 2 include lines are found in npplat.h:

#include "npapi.h"

#include "npupp.h"

You will need to move them from the beginning of the npplat.h to a place beyond where the Windows include files are included.

For Example if the original file looks like this:

...

#ifndef _NPPLAT_H_

#define _NPPLAT_H_

#include "npapi.h"

#include "npupp.h"

/**************************************************/

/* Windows */

/**************************************************/

#ifdef XP_WIN

#include "windows.h"

#endif //XP_WIN

...

The modified file should look like this:

...

#ifndef _NPPLAT_H_

#define _NPPLAT_H_

/**************************************************/

/* Windows */

/**************************************************/

#ifdef XP_WIN

#include "windows.h"

#endif //XP_WIN

#include "npapi.h"

#include "npupp.h"

.....

 9. Rebuild the project.

10. You should be good to go now. Good luck!

 

Tags:

C++ | How To | Firefox

Fix for the DataGrid does not exist in the namespace error in Silverlight 2 beta 2

by APIJunkie 10. June 2008 07:27

When upgrading an existing Silverlight project to silverlight 2 beta 2 you might encounter the following error:

"The type or namespace name 'DataGrid' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)"

To solve the problem:

1. First go to your project references (Expand your project references sub tree in the Visual Studio IDE) and  look for System.Windows.Controls.Data in the reference list.

(If it does not exist in the list then you probably had the problem before the upgrade and you need to add a reference to System.Windows.Controls.Data by going to Project/Add Reference/.Net and choosing it from the list)

2. Press the right button on the System.Windows.Controls.Data reference and choose properties.

3. If the "Specific Version" property is set to true, change the "Specific Version" property to False.

4. Rebuild the project/solution.

This solved the problem for us on several Silverlight projects using a DataGrid.

Cheers

Tags:

Silverlight | PRB | Troubleshoot | How To

Getting around Silverlight 2 beta 1 error 4002 while changing visibility of a control on mouse click event

by APIJunkie 27. May 2008 23:27

While working on  Bumble Beegger we came across a daunting problem that only seemed to happen under certain conditions.

Silverlight error message
ErrorCode: 4002
ErrorType: ManagedRuntimeError
Message: System.Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at System.Windows.DependencyObject.MethodEx(String methodName, CValue[] cvData)
at System.Windows.UIElement.ReleaseMouseCapture()
at System.Windows.Controls.Primitives.ButtonBase.ReleaseMouseCaptureInternal()
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnLostFocus(Object sender, RoutedEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

After a few hours of debugging, experimenting and googling I came across a discussion on Silverlight.net that shed some light on the problem.

As it turns out there is bug in Silverlight 2 beta 1 that can cause a crash when changing the visibility of a button control inside a mouse event handler.

The recommended workarounds around this problem were to change the size to 0,0 or change the opacity to 1.

Another option is to use the Canvas.ZIndexProperty and set it to a number that is smaller then your foreground elements.

The problem is that those does not always produce a similar enough effect in other elements.

If you still want to use visibility where possible, you can check the type of control and choose to modify visibility, size, opacity or Z Index according to the type.

Granted this is a horrible hack but it gets the job done until we can get our hands on beta 2...

Example:

// assume uiElement points to some valid UIElement

UIElement uiElement;

// check element type, if its not a button set visibility to collapsed else use ZIndex for a similar effect

if (uiElement.GetType() != typeof(Button)) 

   uiElement.Visibility = Visibility.Collapsed;

else

   ((Button)uiElement).SetValue(Canvas.ZIndexProperty, -1);

Tags:

Silverlight | PRB | How To | Debug

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon