Peter Did you try the sample code, with Excel? The GUID in the C# or Vb.NET will be different for Excel, Access.
Have a read of this article (CodeProject) for an overview - http://www.codeproject.com/KB/COM/cominterop.aspx _____ Ian Thomas Victoria Park, Western Australia _____ From: [email protected] [mailto:[email protected]] On Behalf Of Maddin, Peter Sent: Monday, 8 March 2010 2:34 PM To: ozDotNet Subject: RE: Calling a class library C# method from ms access Thanks Ian I ma having trouble translating this from Vb.NET to C#. I built the class library and then used reflector to see the c# code. Tried cutting and pasting but the VS Editor did not like it. Googling other material, locates code that only vaguely resembles that in your link below. I am venturing into unchartered territory never having had much to with Com before (and being told it was dead) The latest one has no GUIDs at all http://www.codeproject.com/KB/office/ParallelMsAccess.aspx My project is tiny using System; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; namespace PathWest { [ComVisible(true)] public interface HashInterface { string Md5Hash(string passwordValue); } [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] public class GetHash : HashInterface { public string Md5Hash(string passwordValue) { byte[] hashValue = new MD5CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(passwordValue )); return Encoding.ASCII.GetString(hashValue); } } } I do see one in the Assembly.cs file though // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(true)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("b92f832a-3887-412b-a126-e58f35041f2d")] Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 9473 3944 Fax : +618 9473 3982 E-Mail : [email protected] The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately. From: [email protected] [mailto:[email protected]] On Behalf Of Ian Thomas Sent: Monday, 8 March 2010 11:13 AM To: 'ozDotNet' Subject: RE: Calling a class library C# method from ms access http://support.microsoft.com/kb/317535 _____ Ian Thomas Victoria Park, Western Australia _____ From: [email protected] [mailto:[email protected]] On Behalf Of Maddin, Peter Sent: Monday, 8 March 2010 10:49 AM To: [email protected] Subject: Calling a class library C# method from ms access I need to call a C# method from MS Access 2003. I need to pass in a string and return a string. I have spent some trying to do this in Delphi but am now sure I need to use COM so I might as well use C#. I have wasted a couple of days almost getting it working only to find that it was too flaky with Access crashing. Does anyone have a simple code example they would be willing to share? The goal is to pass in a string (which will be a password) and return a hash of that string using MD5 or something similar. Generating the hash is no problem its just writing the class and method so Access will be able to call it, setting up the MS Access declaration and calling the method passing in a string and returning a string. I believe one needs to make the assembly 'Com-Visible". Also the Access declaration needs to specify the TLB and not the dll. One needs to register the dll (? And tlb) using regasm. Is there anything else required? Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 9473 3944 Fax : +618 9473 3982 E-Mail : [email protected] The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately.
