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

{

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface IVendingEvents

{

//Eventos

[DispId(1)]

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

[DispId(2)]

void Ayuda();

[DispId(3)]

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

}

public interface IVendingExposing

{

//Propiedades

[DispId(1)]

string Puerto { get;}

[DispId(2)]

bool Abierto { get;}

[DispId(3)]

bool Habilitado { get;}

[DispId(4)]

bool Moneda50Centavos { get;set;}

[DispId(5)]

bool Moneda1Peso { get;set;}

[DispId(6)]

bool Moneda2Pesos { get;set;}

[DispId(7)]

bool Moneda5Pesos { get;set;}

[DispId(8)]

bool Moneda10Pesos { get;set;}

[DispId(9)]

bool Moneda20Pesos { get;set;}

[DispId(10)]

bool Billete20Pesos { get;set;}

[DispId(11)]

bool Billete50Pesos { get;set;}

[DispId(12)]

bool Billete100Pesos { get;set;}

[DispId(13)]

bool Billete200Pesos { get;set;}

[DispId(14)]

bool Billete500Pesos { get;set;}

[DispId(15)]

bool Billete1000Pesos { get;set;}

//Metodos

[DispId(16)]

string DetectaPuerto();

[DispId(17)]

void ConfiguraPuerto();

[DispId(18)]

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

[DispId(19)]

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>

[DispId(20)]

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);

[DispId(21)]

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

TaylorMichaelL

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: http://msdn2.microsoft.com/en-us/library/k639e386.aspx

Michael Taylor - 10/10/07

http://p3net.mvps.org





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

nobugz

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.