C# com dll + events + vb6

Hey

I have made me a C# com visible dll. The C# class + interfaces look like this

namespace communication
{
public delegate Boolean onReceiveMessage(object source, String message, String queue, String application);
public delegate void onConnectionStatusChange(object source, int connectionStatusChange);

//[GuidAttribute("45BE88DC-856F-4b4e-AB3A-781EF0500E8D")]
[Guid("45BE88DC-856F-4b4e-AB3A-781EF0500E8D")]
//[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIssDispatch)]
public interface ICommunicationServer
{
event onReceiveMessage ReceiveMessage;
event onConnectionStatusChange StatusChanged;
[DispId(1)]
void setInitializationValues(string username,
string password,
string brokerurl_1,
string brokerurl_2,
string[] queueNameR);

[DispId(2)]
Boolean openConnection();
[DispId(3)]
void closeConnection();
[DispId(4)]
Boolean sendMessage( String message,
String queue,
Hashtable properties);
}

//[GuidAttribute("1068E001-6D5E-49ca-8890-91FF3DEA42A0")]
[Guid("1068E001-6D5E-49ca-8890-91FF3DEA42A0")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
Boolean ReceiveMessage(String message, String queue, String application);
void StatusChanged(int connectionStatusChange);
}

//[GuidAttribute("39DAAC77-0946-424d-A28D-C00B4B367789")]
[Guid("39DAAC77-0946-424d-A28D-C00B4B367789")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces("communication.IEvents")]
[ProgId("DCS")]
[EventTrackingEnabled(true)]
public class CommunicationServer : ExceptionListener, MessageListener, ICommunicationServer
{
public event onReceiveMessage ReceiveMessage;
public event onConnectionStatusChange StatusChanged;

public static String version = "DCS_NET_02";
public static int NOT_CONNECTED = 0;
public static int TRYING_TO_CONNECT = 1;
public static int CONNECTED = 2;
public static int WAITING_TO_CONNECT = 3;
public static int FAILED_TO_CONNECT = 4;
public static int CLOSING_CONNECTION = 5;

private QueueConnection qcConnection;
private QueueSession queueSessionR;
private QueueSession queueSessionS;
private Sonic.Jms.Queue[] queueR;

private QueueReceiver[] queueReceiverR;
private QueueSender queueSenderS;

private String username;
private String password;
private String brokerurl_1;
private String brokerurl_2
private String[] queueNameR;

private long messageTimeToLive = 0;

/*
* properties for the user of the CommunicationServer
*/
private int connectionStatus = 0;
private String connectionError = "";
private String msgSendingFailure = "";

private static ILog logger = LogManager.GetLogger(typeof(CommunicationServer));
//private static ResourceBundle bundle;

/** Creates a new instance of QueueServer */
public CommunicationServer()
{
}

public void setInitializationValues( String username,
String password,
String brokerurl_1,
String brokerurl_2,
String[] queueNameR)
{...}
public void onException(JMSException jsme){...}
public void onMessage(Message msg){//triger onMessageReceived event}

public Boolean openConnection(){...}
public void closeConnection(){...}
public Boolean sendMessage(String message, String queue, Hashtable properties){...}

public int ConnectionStatus{...}
private int setConnectionStatus{//triger onStatusChange event}
public String ConnectionError{...}
public String SendingFailure{...}
public String DCSVersion{...}
}
}


I can Use this class in a VB6 project. But
if I declare it like
Private WithEvents comm As CommunicationServer.CommunicationServer
in vb6, I can handle the events but I can't access the methods.
if I declar it like this
Private comm As CommunicationServer.ICommunicationServer
I get the error "Object reference not set to an instance of an object"
I can't declar it like
Private WithEvents comm As CommunicationServer.CommunicationServer

could someone help me out here?
I need to access the methods and have the events together

kind regards

Hans

Comments

  • try :

    [code]
    Private comm As communication.CommunicationServer.ICommunicationServer
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion