The .net control has been referenced and added to the vb6 project. It also shows the events that I have in the interface. However, vb6 is not registering to the events and I do not know why. I have read several dozen articles on the subject, used code from a working .Net Control/vb6. This is my first round robin with Events so its probably something very small I'm missing, but here's the code:
C#.NET
[ComVisible (true)]
[Guid(CustomerCreditControl.EventsId)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ICustomerCreditControlEvents
{
[DispId(1)]
void Test();
}
[ComVisible(true)]
[Guid(CustomerCreditControl.InterfaceId)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ICustomerCreditControl
{
void SetAccount(string customerNumber, int generatorId);
string CreditHold { get; }
}
[ComVisible(true)]
[Guid(CustomerCreditControl.ClassId)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ICustomerCreditControlEvents))]
public partial class CustomerCreditControl : UserControl, ICustomerCreditControl
{
public delegate void TestEventHandler();
public event TestEventHandler TestEvent;
[ComRegisterFunction()]
private static void Register(Type t)
{
ComRegistration.RegisterControl(t, "");
}
[ComUnregisterFunction()]
private static void Unregister(Type t)
{
ComRegistration.UnregisterControl(t);
}
public CustomerCreditControl()
{
InitializeComponent();
}
public void SetAccount(string customerNumber, int generatorId)
{
_customer = RCI.DataAccess.DataFactory.Current.AccountService.GetCustomer(customerNumber.Trim());
SetAccount(_customer, generatorId);
}
public void btnNewSalesOrder_Click(object sender, EventArgs e)
{
if (TestEvent != null)
{
MessageBox.Show("Test Event Fired");
TestEvent();
}
else
MessageBox.Show("TestEvent = null");
string[] SOI = {"a","b","c"};
MessageBox.Show(SOI.ToString());
OnNewSalesOrder(ref SOI);
}
}
VB6
Private Sub customerCreditInfo_Test()
MsgBox "Test 2"
End Sub
The vb6 code recognizes the test event, but it does not register to the event. The control is placed on a vb6 form. I have 'MsgBox "Test 2"' just as a test. The tlb is referenced by the project and the activeX is added to the toolbox components. I have unregistered this dll from windows and gone through and removed all instances from the registry. I am using regasm /register /codebase /tlb to register the dll.
Using Visual Studio 2008, .net 2.0 and compiling on a Windows 7 machine.
What am I missing?
Try changing this line
public event TestEventHandler TestEvent;
to
public event TestEventHandler Test;
This is to match the event method definition in your source interface. Then fire the event as Test()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.