Getting MS Access/VBA to work with an external/referenced DLL correctly

Andy Brown
Andy Brown used Ask the Experts™
on
I have a .Net developer creating a DLL that we are going to Reference in an Access VBA application.  However, whilst we can see the DLL methods (once referenced), he is struggling with a couple of aspects such as passing variables through and how best the code the .DLL so that Intellisense works as expected.

Whenever I have worked with external references in the past, I usually access them like this (rough example):

Dim obj1 As New TSDialler.Dialer
obj1.SignalKey = "ABC123456"
obj1.TelephoneDestination = "0123456789"
obj1.InternalID = "ZYX987"
If obj1.MakeCall = 1 Then
    MsgBox "Call made"
Else
    MsgBox "Call not made.  Error: " & obj1.ReturnMessage
End If

Open in new window


However, he has never worked in VBA and is struggling with the various aspects.  His list of questions is below, but I was wondering if anyone had any links/suggestions for him to look at (more than just answering his questions).

Which kind of methods works?
Do properties work?
Constructors work, what about parameters?
How to do event pattern for a custom class and not UI control?
What pieces (that we use regularly) in C# that does not work with VBA when referenced?
Any article/doc that can be referred that has details for questions like above?


Any help would be greatly appreciated - sorry it's so vague.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Andy,

  Keep in mind that there are two different ways of interacting with a DLL:

1. DLL calls
2. As a COM object.

  Straight DLL calls are done with DECLARE statements (think Win API).    You write the Declare, then in VBA code just call the routine.

 The example you gave in the question is declaring an object, which is a totally different thing, and the type lib developed would need to present a COM interface.  

Jim.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
Andy BrownDeveloper

Author

Commented:
Jim - if you were developing this, would you have a preference?
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
My preference is a straight DLL call, but then I'm a bit "old school".    However without having any idea of what your developing or how it will be used, it's hard to say one way or the other.

 But a straight DLL is always simpler to develop (no COM interface).

Jim.
Andy BrownDeveloper

Author

Commented:
Thanks Jim - I'll pass the advice on and see what comes back.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
I should add that in using .Net (and I assume C#), a COM object is probably simpler.  The articles I posted show you how.

 A direct DLL setup is something you'd typically do with using something like C++ rather than .Net.

Jim.
Andy BrownDeveloper

Author

Commented:
Thanks again Jim.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial