//
archives

.NET

This category contains 4 posts

Explore Possibilities with MSIL.

1. Introduction. 1.1. It will be hard to find an intermediate and advanced .NET programmer who has not heard of MSIL. 1.2 I have occasionally worked with IL code in the past, specifically when there is a need to modify the declarations of parameters and attributes for the purpose of interop marshaling. 1.3 Then last … Continue reading

How C# Extension Methods Work

1. Introduction. 1.1 Extension methods were introduced in C# 3.0. 1.2 The main purpose of extension methods is to provide for seamless integration of new functionalities to existing classes. 1.3 I have personally used extension methods to great effect in my projects and I intend to share some of my extension methods with readers in … Continue reading

Using the WebBrowser Control to Print Documents

1. Introduction 1.1 Recently, a junior colleague approached me for some advise. 1.2 As part of his project work, he had need to programmatically perform printing using C#. 1.3 The document he was assigned to print includes a combination of text and images. 1.4 He had no prior experience in this task and was daunted … Continue reading

Tip for Managed Applications that use COM objects – Exposing Metadata For Your COM Objects Part 1

1. Introduction. 1.1 If you have ever used COM objects in your managed applications, you would have certainly come across an intriguing  type named “System.__ComObject”. 1.2 This type indicates a generic Runtime-Callable Wrapper (RCW) that has no metadata available. It is also an internal class in the mscorlib assembly. It is not possible to define … Continue reading

Using Structured Exception Handling to Handle Exceptions from C++ in C#.

1. Introduction. 1.1 At some point, every developer who has ever worked with a mix of managed and unmanaged code would wonder whether it is possible to handle exceptions thrown from unmanaged code in managed code. 1.2 In this blog, I shall expound on one way this can be achieved. The unmanaged code that I shall use to … Continue reading

DynamicMethod as a Viable Alternative to Type.MemberInvoke() and MethodInfo.Invoke()

1. Introduction. 1.1 When using Type.InvokeMember() or MethodInfo.Invoke() to call a method that takes a reference parameter, the referenced object in the arguments array will be updated by the method. However, the arguments array items cannot be used to hold references to existing objects. 1.2 Hence after the method call, the arguments array items will be updated with potentially … Continue reading