Many years ago, in the middle of 90's, Microsoft has introduced new revolutionary programming technology and named it COM - Component Object Model. Most new OS (Windows) features were implemented using COM. New COM-based programming language was created - Visual Basic. Base Windows language - Visual C++ - has great support for COM. Most programming languages support COM but most of them are not COM-based.
Now new revolutionary technology is proposed by Microsoft - .Net. New OS features are promised to be implemented in .Net, new programming languages are created - C#, VB.Net; Visual C++ can use .Net objects and create new ones. More and more new .Net components become available on the market.
So it is the time to support .Net from other Win32 languages such as Delphi.
.Net framework - introduction
The Microsoft .NET Framework promotes interaction with COM components, COM+ services, external type libraries, and many operating system services. Data types, method signatures, and error-handling mechanisms vary between managed and unmanaged object models. To simplify interoperation between .NET Framework components and unmanaged code and to ease the migration path, the common language runtime conceals from both clients and servers the differences in these object models.
Code executing under the control of the runtime is called managed code. Conversely, code that runs outside the runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are examples of unmanaged code.
Start work with interop
This article will show the use of .Net assemblies written in C# and Delphi .Net from Delphi Win32 (.Net interop) and how to call functions in Win32 .dll from .Net application (COM interop).
At first, download and unpack examples into directory of your choice. The code includes special program - InteropUtils.exe (in Tools directory) designed to execute common interop tasks such as generating and importing type libraries from .Net assemblies, register and unregister .Net assembly for COM and generating strong name key.
Article will discuss four parts of the interop:
- .Net interop with standard assembly written in C#.
- .Net interop with assembly written in Delphi .Net.
- COM interop - use unmanaged code from Delphi .Net.
- Managed extensions for VCL - host .Net runtime in unmanaged application.
If you have any questions or comments, you are welcome in our forums.