SlideShare a Scribd company logo
1 of 16
Rohit Vipin Mathews
 Interoperability is the process of communication
  between two separate systems.
 In .NET Interop, the first system is always the .NET
  Framework; the other system might be any other
  technology.
 Unmanaged interoperation is not easy as the managed
  interop, and it's also much difficult and much harder
  to implement. In unmanaged code interoperation, the
  first system is the .NET code; the other system might
  be any other technology including Win32
  API, COM, ActiveX, etc.
 Interoperation with Native Libraries.


 Interoperation with COM components.
 This is the most famous form of .NET interop with
 unmanaged code. We usually call this
 technique, Platform Invocation, or simplyPInvoke.
 Platform Invocation or PInvoke refers to the technique
 used to call functions of native unmanaged libraries
 such as the Windows API.
To PInvoke a function, you must declare it in your .NET
code. That declaration is called the Managed Signature.
To complete the managed signature, you need to know
the following information about the function:

1.   The library file which the function resides in.
2.   Function name.
3.   Return type of the function.
4.   Input parameters.
5.   Other relevant information such as encoding.
using System.Runtime.InteropServices;

namespace InterOp_with_API
{
  class Program
  {
     public enum beepType
     {
       Beep = -1,
       OK=0x00,
       Question=0x20,
       Exclamation=0x30,
       Asterix=0x40,
     }
[DllImport("User32.dll",ExactSpelling=true)]
    static extern bool MessageBeep(uint type);
    static void Main(string[] args)
    {

            MessageBeep((uint)beepType.Exclamation);
            MessageBeep((uint)beepType.Question);
        }
    }
}
 Marshaling is the process of converting unmanaged
  types into managed and vice versa . That conversion
  can be done in many ways based on the type to be
  converted.
 For example, BOOL can simply be converted to
  System.Boolean, and LPCTSTR can be converted to
  System.String, System.Text.StringBuilder, or even
  System.Char[].
 Compound types (like structures and unions) usually
  don't have counterparts in .NET code and thus you
  need to create them manually.
 COM Interop is very large and much harder than
  P/Invoke and it has many ways to implement.
 COM Interop includes all COM-related technologies
  such as OLE, COM+, ActiveX, etc.
 You can't talk directly to unmanaged code.
 you have to declare your functions and types in your
  .NET code.
 To include a COM-component in your .NET
  application, you go to the COM tab of the Add
  Reference dialog and select the COM component that
  you wish to add to your project and use it!
 When you add a COM-component to your .NET
  application, Visual Studio automatically declares all
  functions and types in that library for you.
 It creates a Proxy library (i.e. assembly) that contains
  the managed signatures of the unmanaged types and
  functions of the COM component and adds it to your
  .NET application.
 The proxy acts as an intermediary layer between your
  .NET assembly and the COM-component.
  Therefore, your code actually calls the managed
  signatures in the proxy library that forwards your calls
  to the COM-component and returns back the results.
 Proxy libraries also called Primary Interop Assemblies
  (PIAs) and Runtime Callable Wrappers (RCWs.)
 Now you don't have to ship a proxy/PIA/RCW
 assembly along with your executable since the
 information in this assembly can now be embedded
 into your executable; its called Interop Type
 Embedding.
//Add a reference to the Microsoft Speech Object Library
  class Program
  {
     static void Main(string[] args)
     {
        Console.WriteLine("Enter the text to read:");
        string txt = Console.ReadLine();
        Speak(txt);
     }
     static void Speak(string text)
     {
        SpVoice voice = new SpVoiceClass();
       voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault);
     }
  }
 ActiveX is no more than a COM component that has
  an interface.
 To add an ActiveX control to .NET application, right-
  click the Toolbox, select Choose Toolbox Items, switch
  to the COM Components tab and select the controls to
  be used in the application.
Unmanged code InterOperability

More Related Content

What's hot

Component object model and
Component object model andComponent object model and
Component object model and
Saransh Garg
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
Sisir Ghosh
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecture
phantrithuc
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
10n Software, LLC
 
The .NET Platform - A Brief Overview
The .NET Platform - A Brief OverviewThe .NET Platform - A Brief Overview
The .NET Platform - A Brief Overview
Carlos Lopes
 

What's hot (20)

Component object model and
Component object model andComponent object model and
Component object model and
 
Introduction to .NET Programming
Introduction to .NET ProgrammingIntroduction to .NET Programming
Introduction to .NET Programming
 
Book management system
Book management systemBook management system
Book management system
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Architecture of .net framework
Architecture of .net frameworkArchitecture of .net framework
Architecture of .net framework
 
.Net introduction by Quontra Solutions
.Net introduction by Quontra Solutions.Net introduction by Quontra Solutions
.Net introduction by Quontra Solutions
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 
Aspnet architecture
Aspnet architectureAspnet architecture
Aspnet architecture
 
Flex and PHP For the Flash Folks
Flex and PHP For the Flash FolksFlex and PHP For the Flash Folks
Flex and PHP For the Flash Folks
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
The .NET Platform - A Brief Overview
The .NET Platform - A Brief OverviewThe .NET Platform - A Brief Overview
The .NET Platform - A Brief Overview
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti
 
Online lg prodect
Online lg prodectOnline lg prodect
Online lg prodect
 
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
Apple’s New Swift Programming Language Takes Flight With New Enhancements And...
 
Dot Net Framework
Dot Net FrameworkDot Net Framework
Dot Net Framework
 
COM and DCOM
COM and DCOMCOM and DCOM
COM and DCOM
 
ASP.NET 01 - Introduction
ASP.NET 01 - IntroductionASP.NET 01 - Introduction
ASP.NET 01 - Introduction
 
dot NET Framework
dot NET Frameworkdot NET Framework
dot NET Framework
 

Similar to Unmanged code InterOperability

.Net framework
.Net framework.Net framework
.Net framework
Raghu nath
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02
Wei Sun
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
Satish Verma
 
Vb6.0 Introduction
Vb6.0 IntroductionVb6.0 Introduction
Vb6.0 Introduction
Tennyson
 

Similar to Unmanged code InterOperability (20)

Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
 
COM
COMCOM
COM
 
.Net framework
.Net framework.Net framework
.Net framework
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Interoperation
InteroperationInteroperation
Interoperation
 
C# Unit 1 notes
C# Unit 1 notesC# Unit 1 notes
C# Unit 1 notes
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
introduction to_mfc
 introduction to_mfc introduction to_mfc
introduction to_mfc
 
Vb6.0 Introduction
Vb6.0 IntroductionVb6.0 Introduction
Vb6.0 Introduction
 
CFInterop
CFInteropCFInterop
CFInterop
 
As pnet
As pnetAs pnet
As pnet
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
Visual Basic –User Interface- V
Visual Basic –User Interface- VVisual Basic –User Interface- V
Visual Basic –User Interface- V
 
LLVM
LLVMLLVM
LLVM
 
C-PROGRAM
C-PROGRAMC-PROGRAM
C-PROGRAM
 
Programming
Programming Programming
Programming
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
Using Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentUsing Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) Environment
 
Microsoft.Net
Microsoft.NetMicrosoft.Net
Microsoft.Net
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Unmanged code InterOperability

  • 2.  Interoperability is the process of communication between two separate systems.  In .NET Interop, the first system is always the .NET Framework; the other system might be any other technology.  Unmanaged interoperation is not easy as the managed interop, and it's also much difficult and much harder to implement. In unmanaged code interoperation, the first system is the .NET code; the other system might be any other technology including Win32 API, COM, ActiveX, etc.
  • 3.  Interoperation with Native Libraries.  Interoperation with COM components.
  • 4.  This is the most famous form of .NET interop with unmanaged code. We usually call this technique, Platform Invocation, or simplyPInvoke. Platform Invocation or PInvoke refers to the technique used to call functions of native unmanaged libraries such as the Windows API.
  • 5. To PInvoke a function, you must declare it in your .NET code. That declaration is called the Managed Signature. To complete the managed signature, you need to know the following information about the function: 1. The library file which the function resides in. 2. Function name. 3. Return type of the function. 4. Input parameters. 5. Other relevant information such as encoding.
  • 6. using System.Runtime.InteropServices; namespace InterOp_with_API { class Program { public enum beepType { Beep = -1, OK=0x00, Question=0x20, Exclamation=0x30, Asterix=0x40, }
  • 7. [DllImport("User32.dll",ExactSpelling=true)] static extern bool MessageBeep(uint type); static void Main(string[] args) { MessageBeep((uint)beepType.Exclamation); MessageBeep((uint)beepType.Question); } } }
  • 8.  Marshaling is the process of converting unmanaged types into managed and vice versa . That conversion can be done in many ways based on the type to be converted.  For example, BOOL can simply be converted to System.Boolean, and LPCTSTR can be converted to System.String, System.Text.StringBuilder, or even System.Char[].  Compound types (like structures and unions) usually don't have counterparts in .NET code and thus you need to create them manually.
  • 9.
  • 10.  COM Interop is very large and much harder than P/Invoke and it has many ways to implement.  COM Interop includes all COM-related technologies such as OLE, COM+, ActiveX, etc.
  • 11.  You can't talk directly to unmanaged code.  you have to declare your functions and types in your .NET code.  To include a COM-component in your .NET application, you go to the COM tab of the Add Reference dialog and select the COM component that you wish to add to your project and use it!
  • 12.  When you add a COM-component to your .NET application, Visual Studio automatically declares all functions and types in that library for you.  It creates a Proxy library (i.e. assembly) that contains the managed signatures of the unmanaged types and functions of the COM component and adds it to your .NET application.  The proxy acts as an intermediary layer between your .NET assembly and the COM-component. Therefore, your code actually calls the managed signatures in the proxy library that forwards your calls to the COM-component and returns back the results.  Proxy libraries also called Primary Interop Assemblies (PIAs) and Runtime Callable Wrappers (RCWs.)
  • 13.  Now you don't have to ship a proxy/PIA/RCW assembly along with your executable since the information in this assembly can now be embedded into your executable; its called Interop Type Embedding.
  • 14. //Add a reference to the Microsoft Speech Object Library class Program { static void Main(string[] args) { Console.WriteLine("Enter the text to read:"); string txt = Console.ReadLine(); Speak(txt); } static void Speak(string text) { SpVoice voice = new SpVoiceClass(); voice.Speak(text, SpeechVoiceSpeakFlags.SVSFDefault); } }
  • 15.  ActiveX is no more than a COM component that has an interface.  To add an ActiveX control to .NET application, right- click the Toolbox, select Choose Toolbox Items, switch to the COM Components tab and select the controls to be used in the application.