|
Category Archive for Software Development
10 Mar, 2010
rvalue references Visual C++ 2010 Visual Studio 2010
The Release Candidate of Visual Studio 2010 has changed the behaviour of RValue references slightly compared to the implementation in the Visual Studio 2010 beta versions. This is because the C++0x standard commitee has changed the RValue reference feature a bit and Visual Studio 2010 RC has incorporated those standard changes. Unfortunately, this might lead to compiler errors when you try to build code that is following the old standard. Let me give an example. Previously using a beta version of Visual Studio 2010 that was using the old C++0x standard, the following code would compile without any problems.
#include <iostream>
using namespace std;
// Increment value by 1 using RValue reference parameter.
int increment(int&& value)
{
cout << "value = " << value << endl;
value++;
return value;
}
int main()
{
int a = 10;
int b = 20;
// Increment a
int result = increment(a);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment b
result = increment(b);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment an expression
result = increment(a + b);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment a literal
result = increment(3);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
return 0;
}
However, when trying to compile this using the latest release candidate of Visual Studio 2010, you will get the following errors:
rvalue_test.cpp(18): error C2664: 'increment' : cannot convert parameter 1 from 'int' to 'int &&'
You cannot bind an lvalue to an rvalue reference
rvalue_test.cpp(21): error C2664: 'increment' : cannot convert parameter 1 from 'int' to 'int &&'
You cannot bind an lvalue to an rvalue reference
These are related to the lines that are trying to increment a and b. Incrementing an expression or a literal still works as before. To get rid of those errors, you need to convert the lvalue to an rvalue. You can use the std::move function for this as shown in red below.
#include <iostream>
using namespace std;
// Increment value by 1 using RValue reference parameter.
int increment(int&& value)
{
cout << "value = " << value << endl;
value++;
return value;
}
int main()
{
int a = 10;
int b = 20;
// Increment a
int result = increment(std::move(a));
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment b
result = increment(std::move(b));
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment an expression
result = increment(a + b);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
// Increment a literal
result = increment(3);
cout << " a=" << a << ", b=" << b << ", result=" << result << endl;
return 0;
}
This now compiles without any errors and produces the following output:
value = 10
a=11, b=20, result=11
value = 20
a=11, b=21, result=21
value = 32
a=11, b=21, result=33
value = 3
a=11, b=21, result=4
Now, it again works as expected
9 Feb, 2010
Visual C++ 2010 Visual Studio Visual Studio 2010
Microsoft has released the Release Candidate version of Visual Studio 2010 and the .NET Framework 4.
See Scott Guthrie blog post about it.
Right now it’s available for MSDN subscribers.
On Wednesday 10th of February everyone will be able to get their hands on it
Two important things to know (from Scott Guthrie blog post):
- If you have previously installed VS 2010 Beta 2 on your computer you should use Add/Remove Programs (within Windows Control Panel) to remove VS 2010 Beta2 and .NET 4 Beta2 before installing the VS 2010 RC. Note that VS 2010 RC can be installed on the same machine side-by-side with VS 2008 and VS 2005.
- Silverlight 3 projects are supported with today’s VS 2010 RC build – however Silverlight 4 projects are not yet supported. We will be adding VS 2010 RC support for SL4 with the next public Silverlight 4 drop. If you are doing active Silverlight 4 development today we recommend staying with the VS10 Beta 2 build for now.
21 Oct, 2009
Visual C++ 2010 Visual Studio Visual Studio 2010
Visual Studio 2010 and .NET Framework 4 Beta 2 are now available. The final version is scheduled for 22nd of March 2010. I’m looking forward to it
For Visual C++ developers there are lots of new things to look forward to, like parallel programming, MFC ribbon resource editor, easy application local deployment model etc etc…
When you use the .NET Framework you will apparently be able to have deployments with up to 81% reduction in the framework size by using the Client Profile.
According to the press release:
“The company also outlined a simplified product lineup and pricing options for Visual Studio 2010 as well as new benefits for MSDN subscribers, including the Ultimate Offer, available to all active MSDN Premium subscribers at the official product launch on March 22, 2010.”
The product lineup is simplified with the following versions:
- Microsoft Visual Studio 2010 Ultimate with MSDN. The comprehensive suite of application life-cycle management tools for software teams to help ensure quality results from design to deployment
- Microsoft Visual Studio 2010 Premium with MSDN. A complete toolset to help developers deliver scalable, high-quality applications
- Microsoft Visual Studio 2010 Professional with MSDN. The essential tool for basic development tasks to assist developers in implementing their ideas easily
Download Beta 2 now.
Read the full Microsoft press release.
23 Jun, 2009
code pack Windows 7
I just stumbled upon the Windows API Code Pack for the Microsoft .NET Framework. It’s a code pack that allows .NET developers to take advantage of some of the new Windows 7 features.
Features supported by version 0.9 of the code pack are:
- Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
- Known Folders, Windows 7 Libraries, non-file system containers, and a hierarchy of Shell Namespace entities.
- Windows 7 Explorer Browser Control.
- Shell property system.
- Windows Vista and Windows 7 Common File Dialogs, including custom controls.
- Windows Vista and Windows 7 Task Dialogs.
- Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
- Sensor Platform APIs
- Extended Linguistic Services APIs
- Power Management APIs
- Application Restart and Recovery APIs
- Network List Manager APIs
- Command Link control and System defined Shell icons.
Requirements:
- .NET Framework 3.5 or later.
- This library targets the Windows 7 RC version, though some of the features will work on the older versions of Windows operating system.
- DirectX features have dependency on Windows SDK for Windows 7 RC and March 2009 release of DirectX SDK.
There are also a few short 2-minute videos available to show you how easy it is to use some of the above features.
12 Jun, 2009
PPL Visual C++ 2010
Visual C++ 2010 comes with a brand new library called the Parallel Pattern Library or PPL. It is a powerful library that makes writing parallel code easier which is getting more and more important with the current and upcoming multicore CPUs. This article will give an overview of the PPL. Read the rest of this entry »
11 Jun, 2009
restart manager Visual C++ 2010
Windows Vista introduced the restart manager. It is used to automatically restart an application after it crashes. It can also be used to restart application after a reboot by a Windows Installer or update. If you create a new MFC application using the project wizard in Visual C++ 2010, you will automatically get support for the restart manager. If you want to add support to an existing MFC application, you only need to add 1 line of code to the constructor of your CWinApp or CWinAppEx derived class. Read the rest of this entry »
10 Jun, 2009
CTaskDialog Task Dialog Visual C++ 2010
Windows Vista introduced the concept of Task Dialogs. Those are a powerful replacement for the standard message boxes. Read the rest of this entry »
9 Jun, 2009
SafeInt Visual C++ 2010
The SafeInt library is a new addition to Visual C++ 2010. It allows you to safely perform arithmetic operations on integers ranging from 8-bit to 64-bit. The SafeInt library will automatically detect arithmetic overflow or divide by zero. Using the SafeInt library is pretty easy. The following piece of code uses the SafeInt library to safely calculate the addition of two 8-bit integers. Read the rest of this entry »
8 Jun, 2009
auto Visual C++ 2010
Starting with Visual C++ 2010, the ‘auto’ keyword has a different meaning. Auto is now used as a variable type and it instructs the compiler to figure out the exact type itself. This makes it much easier to define function pointers or to iterate over vectors for example. This post will give a brief overview of how to use the ‘auto’ keyword. Read the rest of this entry »
7 Jun, 2009
move constructor rvalue references Visual C++ 2010
A new feature in Visual C++ 2010 is called Rvalue References. This is a feature from the C++0x standard. One thing that Rvalue References can be used for is to implement move semantics for objects. To add move semantics to a class, we need to implement a move constructor and a move assignment operator (optional). This article will briefly explain the benefits of move constructors and how to write them. Read the rest of this entry »
27 May, 2009
Direct2D DirectWrite Visual Studio Windows 7
Microsoft has added two interesting new API’s to Windows 7: Direct2D and DirectWrite. Direct2D replaces GDI and GDI+. It can render more accurate results and has support for hardware acceleration on your graphics hardware. DirectWrite is a new API to render text. It makes it easy to render paragraphs of text that can contain different formatting, coloring, fonts etc. It supports horizontal and vertical alignments, even vertical centering of a paragraph with multiple lines which was not possible with the old text API, etc. This article will give an introduction to the new DirectWrite API. Read the rest of this entry »
27 May, 2009
layered windows UpdateLayeredWindow
In this post I will briefly explain how to use layered windows and specifically how to use UpdateLayeredWindow.
The first thing you need to do is add the WS_EX_LAYERED style to your window. This can for example be done with a call to CreateWindowEx:
hWnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, szTitle, 0,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
After your window is created we will load a PNG file with an alpha channel and use UpdateLayeredWindow to render the PNG on the window using the alpha channel of the PNG file as the transparency level for the window. This is done as follows:
// Load our PNG image
CImage img;
img.Load("circle.png");
// Get dimensions
int iWidth = img.GetWidth();
int iHeight = img.GetHeight();
// Make mem DC + mem bitmap
HDC hdcScreen = GetDC(NULL);
HDC hDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, iWidth, iHeight);
HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC, hBmp);
// Draw image to memory DC
img.Draw(hDC, 0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight);
// Call UpdateLayeredWindow
BLENDFUNCTION blend = {0};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
POINT ptPos = {0, 0};
SIZE sizeWnd = {iWidth, iHeight};
POINT ptSrc = {0, 0};
UpdateLayeredWindow(hWnd, hdcScreen, &ptPos, &sizeWnd, hDC, &ptSrc, 0, &blend, ULW_ALPHA);
SelectObject(hDC, hBmpOld);
DeleteObject(hBmp);
DeleteDC(hDC);
ReleaseDC(NULL, hdcScreen);
Because I’m using CImage, you need to include the atlimage.h header.
That’s all that is required for the basics of UpdateLayeredWindow.
NOTE: The example above does not include any error checking. That is left for the reader as an excercise.
21 May, 2009
Direct2D DirectWrite Visual Studio Windows 7
The Visual C++ 2010 Beta 1 release contains the Windows 7 Beta SDK. For Direct2D and DirectWrite there were some breaking changes between the beta version of the SDK and the RC version of the SDK. So if you want to use those new Direct2D and DirectWrite APIs, you definitely need the latest Windows 7 RC SDK. There are some manual steps involved in getting that to work with Visual C++ 2010. For detailed explanation please check out Using the Windows 7 RC SDK in Visual C++ 2010 Beta 1 on the Visual C++ Team Blog.
20 May, 2009
Visual Studio
Visual Studio 2010 Beta 1 and .NET FX 4 Beta 1 have been released and is available for download if you have an MSDN subscription. The beta 1 will be publicly released very soon. Check out http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx for more information.
19 May, 2009
Direct2D DirectWrite Windows 7
I’m working on a new article to be published on Codeguru. The new article will be about using Direct2D and DirectWrite on Windows 7 from C++.
I was really impressed while playing with those new APIs. The two APIs combined are pretty powerful and allow you to easily render complicated formatted text. The screenshot below shows what the demo application that will be included with the article is capable of rendering. The code behind everything you see in the screenshot is pretty simple.
The demo will show rendering paragraphs of text with different fonts, font sizes, styles (bold, italic, underlined…), font colors, text alignment and so on. It also shows that mixing left-to-right and right-to-left text is not a problem and how to render fancy text using special typgraphic features that are present in certain fonts. Hit testing will also be included which can for example be used to embed interactive hyperlinks into DirectWrite rendered text. Click on the screenshot to see a full sized version

NOTE: I have no idea what the Arabic piece of text is saying, so do not blame me if it says something wrong. It’s just for demonstration purposes.
3 Apr, 2009
Windows Windows 7
I’m currently in the process of implementing high DPI support in one of my applications. High DPI support is getting more and more important, especially with the resolution of todays laptop screens. Most people will switch to 120 DPI or even 144 DPI instead of the default 96 DPI to make text easier to read. However, when your application is not High DPI aware, Windows Vista and Windows 7 will in certain situations scale everything for you but this will result in a blurry user interface.
Microsoft has released an interesting document describing the steps involved in developing High DPI aware applications. You can find them at the following links:
1 Apr, 2009
After installation of Internet Explorer 8, some wizard in Visual Studio 2005 and 2008 might give a script error. The following wizards might be affected:
- Add Function
- Add Variable
- Smart Device – New Project Creation
- Smart Device – Add Class
Get the workaround from the Visual C++ Team Blog.
24 Jan, 2009
Windows 7
When the beta of Windows 7 was released, I obviously had to install it to test Wallpaper Cycler on it. Wallpaper Cycler started fine, so that was a good start However, when I wanted to cycle the wallpaper on the desktop, it changed the tiling setting on the desktop properly, but the wallpaper itself was not changed, bummer
Since Windows 7 comes by default with a very basic wallpaper cycler built-in, I thought that Microsoft had maybe changed the programming interface to change the wallpaper. I started to search on the internet for information regarding this, but didn’t find anything. So, I started debugging… Read the rest of this entry »
29 Nov, 2008
On Thursday 27th of November I have given my first presentation for a Microsoft event. The presentation was given during a Microsoft Community Osijek (Croatia) event. You can find more information about that community on their site. The presentation was a 45 minute “Introduction to C++”. It gave a brief overview of C++ and about the advantages of C++. It also explained how to decide when to use C++ and how to fuse the C++ and C# worlds. At the end, I gave a demo on how to call a C++ DLL from C#. Comments after the presentation were quite positive
7 Nov, 2008
The CTP build of Visual C++ 2010 includes a new library to help you write native parallel code. Writing parallel code is getting more and more important with the broad availability of quad-core CPU’s at this time and the many-core CPU’s that will appear in the coming years. I will only be talking about the new concurrency library for native code. Of course, writing parallel code was already possible for a long time. However, you had to create and manage all threads by yourself and this could often be a complex task. Because of this, it requires quite a bit of time to parallelize a simple loop over multiple threads. The new native concurrency library makes this much easier. Read the rest of this entry »
|
 |
|