Skip to main content

Find the length of the string in C

· One min read
//str_len returns the length of str
int str_len(char* str) {
int len; len = 0;
for (int i = 0; str[i] != '\\0'; i++)
{
len ++;
}
return len;
}

void main() {
char* website = "www.github.com";
int len = str_len(website);
printf("length = %d n", len);
}

OUTPUT length = 17
Tags:

Set a variable that can be accessed on all pages of a Windows Phone App

· One min read

App.xaml.cs

public partial class App : Application {
public string sName { get; set; }

public static new App Current
{
get { return Application.Current as App; }
}
...
...


}

Page1.xaml.cs

public partial class Page1 : PhoneApplicationPage { 
public string _sName;

public Page1()
{
InitializeComponent();

_sName = App.Current.sName;
}

}

Can't login to Windows 8 with account live password! ?

· One min read

Steps

  1. open the 'On screen keyboard' and use it to type the password

Preventive measure steps:

It's good to setup sign-in options in order to have one or more ways to login to your PC

  1. Go to charm bar select 'Change PC Settings'

  2. Select Users

  3. Use 'Sign-in options' to use 'Picture Password' and 'PIN' password

How to Delete \"Windows.old\" in windows 8

· One min read

1. Press the Windows+R keys to open the Run dialog, type cleanmgr, and press Enter.

2. Select the Windows drive, and click/tap on OK. NOTE: You will not see this window unless you have more than one drive or partition on your computer with a drive letter.

3. Click/tap on the Clean up system files button

4. Click/tap on the Previous Windows installation(s) box to check it, and click/tap on OK. (see screenshot below)

5. Click/tap on Delete Files.

6. When Disk Cleanup finishes, the C:Windows.old folder will be deleted.

Installation Setup for Windows Phone 7 Development

· 2 min read
  1. Install Visual Studio 2010 Professional or  Visual Studio 2010 Ultimate

  2. Install Microsoft VisualStudio 2010 ServicePack1 http://www.microsoft.com/en-in/download/details.aspx?id=23691

or

If you don’t have Visual Studio 2010 Professional or Visual Studio 2010 Ultimate go for 3) Visual Studio 2010 Express for Windows Phone (MSDN) http://www.microsoft.com/visualstudio/en-us/products/2010-editions/windows-phone-developer-tools

  1. After installing  Visual Studio 2010 Professional or  Visual Studio 2010 Ultimate or Visual Studio 2010 Express for Windows Phone install following Windows Phone SDK’s

  2. Install Microsoft XNA Game Studio 4.0 http://www.microsoft.com/en-in/download/details.aspx?id=23714

  3. Install Windows Phone SDK 7.1 SDK http://www.microsoft.com/en-us/download/details.aspx?id=27570

  4. Install Windows Phone SDK 7.1.1 SDK Update http://www.microsoft.com/en-us/download/details.aspx?id=29233

ATL Tutorial (DLL or Inproc Server)

· One min read

In this tutorial we will be creating

  1. MathComp which is a DLL or Inproc server and exposes the Add and Sub functions.

  2. An MFC Dialog Based Application which acts like a Client for MathComp

For complete tutorial refer Tutorial

WPF Architecture

· One min read

The major code portions of WPF are.

PresentationFramework, PresentationCore, and milcore WPF. PresentationFramework, PresentationCore are managed components but only milcore is an unmanaged component Milcore is developed in unmanaged code in order to enable tight integration with DirectX. All display in WPF is done through the DirectX engine, allowing for efficient hardware and software rendering.

1. Presentation Framework

Most of the important WPF elements are in Presentation Framework.  Presentation Framework Provides high-level services like layout, data binding, command handling.

2. Presentation Core

Presentation provides .NET API that uses rendering services for the MIL. During graphics programming we work with Core API.

3. Milcore

The composition engine in milcore (Media Integration) is extremely performance sensitive. MIL takes Bitmaps, Vectors, and media render them to the DirectX

WPF Basics

· 3 min read

1. WPF Definition

Windows Presentation Foundation is the successor to Windows Forms for Microsoft Desktop Application development. WPF uses XAML to create visible User Interface (UI) elements like (buttons, listboxes, editboxes, etc).

WPF applications allows take advantage of the best attributes of diverse systems, such as DirectX (3-D and hardware acceleration), Adobe Flash (animation support), and HTML (declarative markup and easy deployment), styles, templates, documents and typograph.

2. Advantages of WPF Applications

The advantages of WPF applications include:

  1. Declarative programming – WPF uses Extensible Application Markup Language (XAML) declarative programming to define the layout of application objects and to represent 3-D models, among other things. This allows graphic designers to directly contribute to the look and feel of WPF applications.

  2. Tight multimedia integration –WPF provides consistent programming model to create -D graphics, video, speech, and rich document viewing.

  3. Resolution independence –WPF uses vector graphics to make the applications resolution-independent. WPF Applications can shrink or enlarge elements on the screen, independent of the screen’s resolution.

  4. Hardware acceleration – WPF is built on top of Direct3D, which offloads work to graphics processing units (GPUs) instead of central processor units (CPUs). This provides WPF applications with the benefit of hardware acceleration, permitting smoother graphics and enhanced performance.

  5. Rich composition and customization – WPF controls are easily customizable. We need not write any code to customize controls in very unique ways. WPF also lets you create skins for applications that have radically different looks.

  6. Easy deployment – WPF provides options for deploying traditional Windows applications (using Windows Installer or ClickOnce).

  7. Culturally aware controls – static text in controls and the return data for the String function are modified according to the culture and language specified by the end user's operating system.

3. WPF vs WinForms

WPF is also more suitable for applications with rich media content than Windows Forms applications. This includes applications using:

  1. Multimedia and animation with DirectX technology
  2. HD video playback
  3. XPS documentation for high quality printing
  4. Control rotation (Windows Forms applications support text rotation only)

WPF is also great if you need to create a skinned user interface, or if you need to bind to XML data, or dynamically load portions of a user interface from a Web service, or want to create a desktop application with a Web-like navigation style.

WPF stores its data more efficiently hence individual objects will be small, but there tend to be more objects in WPF than in WinForms .This would require more RAM than Windows Application.

CPU utilization will go up compared to WinForms   WPF objects onscreen takes more CPU as normal WinForms rendering (again depending on the requirement).

4. XAML - eXtensible Application Markup Language

Definition: XAML (zammel) is an XML-based declarative markup. We can create visible User Interface (UI) elements like (buttons, listboxes, editboxes, etc) using XAML.

XAML files are XML files .xaml file name extension encoded as UTF-8.

Example:

C# Button  Compile (Design-time) and Execute (Runtime) where as XAML Button Load, Parse,Render and Display

COM Threading Models

· 3 min read

COM Threading Models / Apartment Model

Definition: Multithreading in COM is referred to as the apartment model in COM

Apartment

The COM apartment is a conceptual entity that allows us to think about components and their clients in a logical way

  • An apartment is not a thread, but a thread belongs to only one apartment.

  • An apartment is not an instance of a COM object, but each COM instance belongs to only one apartment.

  • A process can have one or more apartments, depending on its implementation.

  • Apartments are created or entered by calling the CoInitialize or CoInitializeEx function. Each thread that calls CoInitialize(0) or CoInitializeEx( 0, COINIT_APARTMENTTHREADED )

  1. STA (Single Threaded Apartment) : Only One thread can join this Apartment.
  2. MTA (MultiThreaded Apartment): Multiple threads can join this Apartment.

Differences between STA and MTA

NoFeatureSTAMTA
1Synchronization provided by COMYESNO
2Uses Windows message queuesYESNO
3Can have multiple threads in an apartmentNOYES
4Must marshal interface pointers between the threads in the same apartmentN/AYES
5Must marshal interface pointers between apartmentsYESYES
6Must call Coinitialize() in every thread that uses a COM ServiceYESYES
7PerformanceSlowFast

NOTE: ATL object wizard allows you to set the threading model. The values can be

Threading ModelDescription
Single / No ValueObject knows nothing about threads
ApartmentSTA
FreeMTA
BothBoth STA & MTA

COM Threading Model vs Win32/MFC Threads

· 2 min read

1. Win32/MFC Threads

There are two types of win32/MFC threads.

  1. User-interface thread: these types of threads are associated with one or more windows. These threads have message loops that keep the window alive and responsive to the users input.

  2. Worker thread: these threads are associated with background processing and are not associated with a window. These types oh threads does not use message loops.

NOTE: A single process can have multiple user interface threads, multiple worker threads.

2. COM Threads

COM uses same type of threads with different names.

  1. Apartment threads (User Interface Thread): This thread owns the component it creates. COM synchronizes, all calls to the component. The component does not need to be threading safe. COM does all of the marshaling and synchronization.

  2. Free threads (Worker Thread): COM does not synchronize the calls. Ant thread can access the component. These are free to use. The component must be threading safe. Marshalling is not necessary and component’s job to synchronize.

NOTE: One process can have single apartment or multiple apartments. In-proc server is example for single process with different apartments (server apartment, client apartment both are in same exe).

Out of-proc server is example for single process with single thread.