.NET/COM Interop and .NET Starter Resources
Here you can find various information on how to get started with .NET and how to integrate .NET projects into your Access/VBA applications.
What is COM Interop?
COM (Component Object Model) and .NET are two different technologies/frameworks for writing code and building applications. COM is the technology that Access/VBA is built on (among many other applications), and .NET is an expansive framework whose primary aim is to provide a unified platform and take away some of the complexities of lower level code management that COM developers have had to deal with.
The COM technology has been around for a very long time, and for new development tends to be falling by the wayside a bit. However, due to its long tenure and being the foundational technology for applications, there’s still a very wide range of applications both in use and being developed. .NET of course has a very wide foothold as well, but the two technologies work very differently at the lower levels and are not directly compatible. That is, to make one play well with the other, there are some specific steps that need to be taken (this is true in both directions by the way: COM doesn’t easily consume .NET code, and .NET requires special attention to consume COM code).
COM Interoperability, from the .NET perspective, deals with how to create .NET resources and consume them with COM Clients. A COM Client is any COM-based application: VB6, Access/VBA, many C/C++ programs, etc.
Why should I consider COM Interop?
.NET tends to offer a more robust set of tools for dealing with certain programming tasks. By leveraging the power of .NET programming in your Access/VBA application, you can often times write .NET code for specialized tasks that would be very difficult and time consuming to create in Access/VBA. The following gives a few ideas of how an Access/VBA developer might supplement their applications with .NET resources:
- Web Service Calls: In this day and age, just about everyone is using web services of some sort or another. .NET tends to be a more robust platform for dealing with these types of things, and the fact that most web service providers will give C# example code but not VB/VBA sample code and templates makes a compelling case for doing this type of work in .NET, then calling the .NET libraries from VBA.
- Azure Automation: Most of the services and features that Azure offers can be quite difficult to work with from VBA, but have extended support through .NET. Some tasks such as working with cloud based document stores and maintenance and infrastructure work can be handled much more easily in .NET, then called from your VBA application accordingly.
- Async Support: The .NET platform offers fairly extensive set of async/parallel programming features. By utilizing these in .NET and then calling that code from Access/VBA, you can offload many tasks to run in the background without holding up the Access UI. This is especially useful when working with web services or other remote-located resources.
- Deeper Lower-Level Support: In VBA, when we want to work with “lower level” stuff, we often go through the Windows API, but the Windows API is not for the faint of heart. Much of this can be done quite easily in .NET, so with .NET under your belt and the ability to integrate that with Access/VBA, we can often do this type of work much more easily.
- Working with External Applications: Many applications that you might want to integrate with are more closely tailored to .NET integration. AutoCAD is a good example of this, with their newer versions allowing only .NET automation.
- Working with Enterprise/Domain Code: In enterprise environments, sometimes it can be helpful to tap into larger .NET codebases to utilize existing logic from within your Access/VBA applications. This can also be an effective means for more robust security measures.
- Utilizing Community Libraries: There’s a multitude of open source libraries available for .NET. Utilizing these and integrating them with your Access/VBA applications can be an easy and more stable means than reinventing the wheel in Access/VBA.
As things currently stand, all of the walkthroughs below can be done using the Express/Community edition(s) of Visual Studio (any recent version, let’s say from 2010 and up) and a copy of Access.
For Visual Studio 2013, you can download the Expression edition here: https://www.microsoft.com/en-us/download/details.aspx?id=44914
For Visual Studio 2015, there’s a free Community edition: https://www.visualstudio.com/products/visual-studio-community-vs
In the resources section below is a link that walks through a bit of the VS IDE.
- Overview of Technologies: This article gives a brief overview of the core .NET technologies (WinForms, WPF, ASP.NET, ADO.NET, etc), along with some insight to layered architecture and how they can work together.
- Visual Studio IDE Familiarity: get an idea of what’s what, take a quick peek at my ideal setup, learn basic manipulations and a small handful of important keyboard shortcuts.
- NetCom Starter’s Guide (hands on): The NetCom starter’s guide gives an introduction to Visual Studio: solutions, projects and basic structure in the context of preparing for a simple .NET library exposed for use by a COM client. The subsequent walkthroughs will build off the information in this article.
- .NET Code Walkthrough (Basic) (hands on): The .NET Code Walkthrough (Basic) takes the structure we discussed in the Starter’s Guide and digs into writing actual C# code, explaining how and why as we move along. By the end, you’ll know how to utilize references, external libraries, manage different projects within a single solution and set up a test project.
- C# COM Class Template: This is a raw reference for those familiar with .NET/COM interop and need a quick place to look for syntax on how to do something specific. This is not intended for the uninitiated.
- .NET Glossary: Brief descriptions of .NET terms.