Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET COM Issues with VB6 in Windows 7: Event doesn't work
    primarykey
    data
    text
    <p>I have a .NET COM DLL that is used by Visual Basic 6. However, the CloseEvent is not working in Windows 7 and the following exception is throw. The VB6 process has no problem to invoke the Init method. Only CloseEvent is not working. Both Init and CloseEvent are working fine in my XP.</p> <pre><code>System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Object does not match target type. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.Reflection.TargetException: Object does not match target type. at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&amp; msgData) at FMStation.VbComGateway.IVbComEventGateway.CloseEvent() at FMStation.VbComGateway.VbComGateway.TriggerCloseEvent() at FMStation.VbComGateway.VbComGateway.&lt;.ctor&gt;b__0(Object o, EventArgs e) at FMStation.VbComGateway.VbService.CloseApplication() at SyncInvokeCloseApplication(Object , Object[] , Object[] )...). </code></pre> <p>Here is the code as follow. This COM object has a Init method and a CloseEvent event.</p> <p><b>.NET</b></p> <pre><code>public interface IVbComGateway { void Init(string namedPipieId); } [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] [Guid("EA9C2EFC-7A13-4944-9901-29263F4F4B32")] [ComVisible(true)] public interface IVbComEventGateway { [DispId(1)] void CloseEvent(); } [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(IVbComEventGateway))] //Our event source is IMathEvents interface [ComDefaultInterface(typeof(IVbComGateway))] public class VbComGateway : IVbComGateway { [ComVisible(false)] public delegate void MyEventHandler(); private readonly VbService vbService; private ServiceHost host; public event MyEventHandler CloseEvent; public VbComGateway() { vbService = new VbService(); vbService.ClosingApplicationSignalReceived += (o, e) =&gt; TriggerCloseEvent(); } public void Init(string namedPipieId) { host = new ServiceHost(vbService, new[] { new Uri("net.pipe://localhost/" + namedPipieId) }); host.AddServiceEndpoint(typeof(IVbService), new NetNamedPipeBinding(), "PipeReverse"); host.Open(); } private void TriggerCloseEvent() { if (CloseEvent != null) CloseEvent(); } } </code></pre> <p>In <b>VB6</b>, I am using WithEvents to hook up this event:</p> <pre><code>Dim WithEvents gateway As FmsVbComGateway.VbComGateway Private Sub gateway_CloseEvent() CloseApplication Dim number As Integer For number = 0 To VB.Forms.Count - 1 Unload VB.Forms(number) Next number End Sub </code></pre> <p>Hope someone can help. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload