0

Please can some1 tell me as to what is wrong with my code?

C#:

namespace ComMsg
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IM
{
    [DispId(1)]
    event M.MHandler OnMSend;
}

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMEvents
{
    [DispId(2)]
    void sendM(M.Process status, string msg);
}

[ComSourceInterfaces(typeof(IM), typeof(IMEvents))]
[ClassInterface(ClassInterfaceType.None)]
public class Message : IM
{
    public enum Process { Error, Complete }

    public delegate void MHandler(Process status, string msg);
    public event MHandler OnMSend;

    public void sendM(Process status, string msg)
    {
        if (OnMSend != null)
            OnMSend(status, msg);
    }
}
}

I call this from my VBA code

Private WithEvents moCom     As ComMsg.M

Public Function Run() As Boolean
Set moCom = New ComMsg.M

it fails at

New ComMsg.Message

and i get an error message

"Object or class does not support the set of events"

Please help to resolve this issue. Thanks

4
  • possible duplicate of C# to VB6 COM events ("object or class does not support the set of events") Commented Aug 21, 2012 at 21:35
  • 1
    VBA is usually pretty cranky about interfaces that are not marked as [default]. Try declaring only one event interface. Commented Aug 21, 2012 at 22:19
  • whats the use of DispID? Is it really necessary? Commented Aug 21, 2012 at 22:21
  • whenever i pass parameters (Process status, string msg) it gives me an error.. any suggestions??? without parameters it works fine Commented Aug 22, 2012 at 17:09

1 Answer 1

1

Looks like you're missing quite a lot of the settings required to implement COM interop. The suggested duplicate link addresses a similar issue.

It might also be worth looking at the MSDN Com interop example here for all the various settings you need to include to use COM interop.

Sign up to request clarification or add additional context in comments.

2 Comments

I have edited my C# code but i still get the error. Please have a look. Thanks
whenever i pass parameters (Process status, string msg) it gives me an error.. any suggestions??? without parameters it works fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.