Milton Brise&#241&#59;o

Hi Every Body, I need some help with this.. I write a object COM in C# and I declared this interface

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

using System.Runtime.InteropServices.ComTypes;

using System.ComponentModel;

namespace VendingCOM



public interface IVendingEvents




void Transaccion(int trn,string referencia,double cobro,double recibio,double cambio,double cambiofaltante,bool completa);


void Ayuda();


void Dispenso(Vending.denominaciones Denominacion, int Cantidad);


public interface IVendingExposing




string Puerto { get;}


bool Abierto { get;}


bool Habilitado { get;}


bool Moneda50Centavos { get;set;}


bool Moneda1Peso { get;set;}


bool Moneda2Pesos { get;set;}


bool Moneda5Pesos { get;set;}


bool Moneda10Pesos { get;set;}


bool Moneda20Pesos { get;set;}


bool Billete20Pesos { get;set;}


bool Billete50Pesos { get;set;}


bool Billete100Pesos { get;set;}


bool Billete200Pesos { get;set;}


bool Billete500Pesos { get;set;}


bool Billete1000Pesos { get;set;}



string DetectaPuerto();


void ConfiguraPuerto();


void Cobra(string referencia,double cobrar,bool btnAbono,bool btnAyuda);


void dispensa(Vending.denominaciones denominacion, int cantidad);

/// <summary>

/// Funcion que indica la cantidad de cada una de las denominaciones que fueron cargadas al inicio

/// </summary>

/// <returns>Void</returns>


void CargaEfectivo(int Moneda50Centavos, int Moneda1Peso, int Moneda2Pesos, int Moneda5Pesos, int Moneda10Pesos, int Moneda20Pesos, int Billete20Pesos, int Billete50Pesos, int Billete100Pesos, int Billete200Pesos, int Billete500Pesos, int Billete1000Pesos);


void acercade();



This COM work fine in Delphi, Vb.Net, C#, C++, VFP. But in VB6 alway send a error when one event is fire I have this code in VB6

Dim Vending1 As New VendingCom.Vending

Private Function Vending1_Ayuda() //This event don't fire and trash my COM
MsgBox "hola"
End Function

Private Sub Command1_Click()
Vending1.Cobra "Hola", 200, False, True
End Sub

What is wrong Every works fine except the events, Ayuda(), Transaccion() and Dispenso().

Thanks a lot.

Re: Visual C# General Help! Interop


While your interface definition for your event is correct it is still not a .NET event and therefore won't work properly. You need to create yet another interface that exposes the events as real events in .NET. You then create delegates to back the events. Finally you have to add the add/remove methods to the events to properly advise/unadvise the events from the COM object.

The steps are long so here is the step-by-step process you can use to expose events to .NET clients:

Michael Taylor - 10/10/07

Re: Visual C# General Help! Interop

Milton Briseño

Thanks a lot I still reading and prove for the solution let me see one day.

Thanks for your help.

Re: Visual C# General Help! Interop


You'll have to declare the class object with the "WithEvents" keyword in VB6 to subscribe to the events.

Re: Visual C# General Help! Interop

Milton Briseño

well it is the really problem... I have this in VB6 SP6

Private WithEvents Ven As VendingCOM.Vending 'Declaring Object

Private Sub Ven_Ayuda() 'This Event Never Fire Only in VB6 in VFP wokr Fine, in delhi Works, in C# works, in VB net works also in C++ but not in VB6
MsgBox "Hola"
End Sub

Private Sub Command1_Click()
Ven.Cobra "Hola", 200, False, True 'This acces to Method Work Fine
End Sub

Private Sub Form_Load()
Set Ven = New Vending 'Creating a new object
End Sub

Obvius I never programing in VB6 but this must work in all languajes any more suggestion

Thanks a lot, Every this can write me, I will prove.

Re: Visual C# General Help! Interop

Milton Briseño

Every Body Thanks a lot, for you help, I reinstall a VB 6 and put SP 6 again and all apears ok. (For this I never work in VB6) here I ready for next round.