0

I have write a library and need to make a Com-wrapper for it. regasm says what registration of com library is successful, then I am adding library to VBA references but methods and classes is unavailable.

using System.Linq;
using System.Runtime.InteropServices;
using BetLib2.Entity;
using BetLib2.Sports.Soccer.Grabber;

namespace BetCom.ComLib
{
    [ComVisible(true)]
    public class Com_Odd
{
    public string Name { set; get; }
    public string Odd { set; get; }
}

[ComVisible(true)]
public class Com_Market
{
    public string Name { set; get; }
    public Com_Odd[] Odds { set; get; }
}

[ComVisible(true)]
public class Com_SoccerMatch_Line
{
    Com_Market[] Markets { set; get; }
}

[ComVisible(true)]
public class Com_SoccerMatch
{
    public string Name { set; get; }
    public string Time { set; get; }
    public string Score { set; get; }
}

[ComVisible(true)]
public class Com_Result_SoccerMatch
{
    public string Error { set; get; }
    public Com_SoccerMatch[] Matches { set; get; }
}

[Guid("E1605FBE-54E8-4F7F-B86F-1399859236F8")]
[ComVisible(true)]
public interface ICom_SoccerGrabber
{
    Com_Result_SoccerMatch GrabMatches();
}

[Guid("DABD1A76-402B-49E1-B701-DED980D48871"),
ClassInterface(ClassInterfaceType.None),
ComVisible(true),
ComSourceInterfaces(typeof(ICom_SoccerGrabber))] 
public class Com_SoccerGrabber : ICom_SoccerGrabber
{
    public Com_Result_SoccerMatch GrabMatches()
    {
        SoccerMatchesGrabber grabber = new SoccerMatchesGrabber();
        var gResult = grabber.GetAllEntities();
        Com_Result_SoccerMatch retVal = new Com_Result_SoccerMatch()
        {
            Error = gResult.Message
        };
        if (gResult.Result == ResultEnum.ResultOk && gResult.ResultsList != null)
        {
            retVal.Matches = gResult.ResultsList.Select(match => new Com_SoccerMatch()
            {
                Name = match.Name,
                Score = match.Score,
                Time = match.Time
            }).ToArray();
        }
        return retVal;
    }

}

}

I make all by tutorials but no result.

Alexey Kulikov
  • 1,097
  • 1
  • 14
  • 38
  • Are you clicking the "Make assembly COM visible" under project settings> application> assembly information in visual studio? Also I had an issue once with making a .dll run in vba, I ended up having to run regasm with the /tlb and /codebase flags, and then point vba at the .lib file instead of the .dll. Just a thought. – Anthony Jul 09 '14 at 17:24
  • gererated .ltb file contains all types I need (I read it in notepad). but VBA cant access them – Alexey Kulikov Jul 09 '14 at 17:26
  • I have register signed library with /codebase. Result is the same. – Alexey Kulikov Jul 09 '14 at 18:16
  • Methods will certainly be unavailable, you'd have to apply the [ClassInterface(ClassInterfaceType.AutoDual)] attribute. Not actually a good idea since that exposes *all* of the class members, declaring the interface separately is always best. – Hans Passant Jul 09 '14 at 18:37
  • Thanks so much! I have add an attribute [ClassInterface(ClassInterfaceType.AutoDual)] and so my classes is available now! Problem has solved! – Alexey Kulikov Jul 10 '14 at 04:30

0 Answers0