dot NET DLL for use with VBA - Reference the vba created class within the C# class? (specifically an event)

henry appliancedude.com 21 Reputation points
2022-01-12T14:51:28.913+00:00

"Notify" and is an event that shows up and works fine in vba.
I tried to add a function called "Start() in csharp that calls the EVENT "Notify()" of the class that was instantiated from vba.
How to fire that event?

Given the following code:

----VBA----
Private WithEvents c As Myclass

Private Sub Command_Click()
    Set c = New Myclass
    c.setSecurityFilePath ("NEWPATH!")
    c.Start
End Sub

Private Sub c_Notify(ByVal s As String)
MsgBox s
End Sub

-----C Sharp------

public delegate void NotifyDelegate(string s);
[GuidAttribute("SOMEGUID")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface INotifyEvents
{
[DispId(1)]
void Notify(string s);
}

[ComSourceInterfaces(typeof(INotifyEvents))]
[ComVisible(true), GuidAttribute("SOMEGUID")]
[ProgId("clsMyclass.Myclass")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Myclass

public delegate void NotifyDelegate(string s);
[GuidAttribute("SOMEGUID")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]

public interface INotifyEvents
{
[DispId(1)]
void Notify(string s);
}

public class MyClass
{

[ComVisible(true)]
public void setSecurityFilePath(string p)
{
secpath = p;
Notify("SecurityFilePath set to: "+ p); << this works fine, fires the event in vba!
}

[ComVisible(true)]
static async Task Start()

{
this.Notify("HELLO FROM THE DLL") << (Compiler Error CS0026) Keyword 'this' is not valid in a static property, static method, or static field initializer
}
}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,250 questions
0 comments No comments
{count} votes