Interfacing MS Access with an external DLL/COM object created in C#

I have an MS Access database and need to interface with a C# DLL that is about to be created for me (as a COM object).  My C# guy has no experience in interfacing with MS Access, and I have only interfaced Access with COM objects that I have purchased (EASendMail etc).  

We have run a few tests, and I can half interface with his test DLL (once referenced), but the Intelisense isn't working correctly.  However, whilst I am sure that we can overcome that one easily enough, it's the return messages that I am struggling to get my head around.  How do I tell Access to listen for them and then, trigger an event/function?

I know this is a little vague - but I could really do with some pointers to get started.
Andy BrownDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
If you have managed to reference it and instatiate it then its working on the Access side...the problems probably are due to the .Dll itself.
If you give a rough outline of what you want to accomplish along with some sample code it would be easier to get a useful answer.
Andy BrownDeveloperAuthor Commented:
Thanks John.  I agree that the reference issue will be the DLL side of things (as mentioned the c# developer is great in certain areas - but this is new to him). However, the big issue is how the DLL pushes information back into Access so that Access can do something.  So, I guess we're looking for a guide/best-practices approach for .Net.

Initially, I wanted us to create a function that allowed users to press a 'Call' button on the Access DB and then monitor for the connection/returned signals being received.  We have already created a service that can initiate the call from a command line prompt and then I get Access to periodically check an XML file, which has the end-of-call status.  This does work - but, it's not slick and I want to be able to do more than just Call a number, so getting a way to send/receive signals cleanly is essential.
John TsioumprisSoftware & Systems EngineerCommented:
The Dll should return an object...then you should cast the object to the type you want it..
Put a breakpoint and check what you get in the Watch window
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Andy BrownDeveloperAuthor Commented:
Thanks again John - I understand what you are saying - but we can't seem to get that far.  Do you know of any simplistic examples VBA/.NET/VBA?
John TsioumprisSoftware & Systems EngineerCommented:
Check this example here
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
How do I tell Access to listen for them and then, trigger an event/function?

 The answer is you don't.   Just like calling a function in VBA, you would get a return value.  ie.

   intRet = SomeFunction()

 It's not class based processing where you'd create an object based on a class, and then potentially hook that into events with "With Events".    It's more like calling something in the Win API.


Jim.
Kyle AbrahamsSenior .Net DeveloperCommented:
This works for C# 4.0 and Access 2003.  

Tell your C# developer to do the following:

1)
Add this to the top of the class.
  [ClassInterface(ClassInterfaceType.AutoDual)]

Open in new window


2)  On the property of the project (NOT the solution)  make sure the checkbox is checked for MAKE Assembly COM-Visible.  This must be done on every project.

3)  When you receive the DLL copy it to C:\Windows\SysWow64\

Then run the following:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "c:\windows\syswow64\YOURDLL.dll"  /register /codebase /tlb:"c:\windows\syswow64\YOURDLL.tlb"

Open in new window


You should be adding a reference to the TLB.

(To update the DLL UNREGISTER C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /unregister  "c:\windows\syswow64\YOURDLL.dll"  )

4)  No class may be a static class.   If you have static classes that you're trying to invoke I've run into issues with them.  To get around that, I create a wrapper class and then just invoke the static API, exposing the same parameters as needed.


That should just about do it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andy BrownDeveloperAuthor Commented:
Thank you, everyone - sorry for the delay in coming back to you.  That should give us enough information to move forward.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.