Handling a VB6 event in C# - why does it only work sometimes? -
I have a VB6 application that has been implemented as an ActiveX exe. I have C # apps that interact with the VB 6 app via COM
All this works well except for a scenario.
If the VB6 app has been removed from the C # app, everything is fine. If, however, the VB6 app is already running alone, even when the COM interface still works, then C # event handlers never fire.
A (very simplified) removal code, Name & amp; GUIDs have been changed to protect the innocent.
(Partial) IDL generated from written VB6 exe:
... [uuid (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx), version (1.10), epobject] colacel mache {{default } _myApp interface; [Default, source] dispenser __myApp; }; ... [Yyyudyaya (Yayyyyyya-Yaya-Yaya-Yyyyyyyyyya), version (1.10), hidden, disliked] Dispersface __myApp {properties: methods: ... [id (0x00000005)] zero myEvent (); ...}; ...
C # app:
public class myAppInterface: IDisposable, ImyAppEvents {public representative zero myEventDelegate (); Public event myEventDelegate myEventHandler; Private object _myApp = null; Private IConnectionPoint _connectionPoint; Private intuspicious cookie; Public myAppInterface () {_myApp = Activator.CreateInstance (Type.GetTypeFromProgID ("myVB6ProjectName.myApp")); Guid G = New Guid ("Yyayayyay-Yaya-Yayay-Yyyayyayya"); ConnectionPointContainer.FindConnectionPoint (reference g, outside _connectionpoint); _connection.point.Advise (this, outside _sinkcookie); } Public zero myEvent () {if (myEventHandler! = Null) {myEventHandler (); [Interface Type Attribute (Com Entererface Type.Interface IidiIPP)] Public Interface EmeeApEvent [[Law Impulse (Method Implication) [Commeimport, Guide ("Yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyya") InstantCall, MethodDodep = MethodCodeType.Runtime), DispId (5)] zero myEvent (); } Public class myC # app {Private static myAppInterface _vb6App; Public stable myAppInterface VB6Application {Receive (if (_vb6App == zero) {_vb6App = new myAppInterface (); _vb6App.myEventHandler + = new myAppInterface.myEventDelegate (DoSomething);} return _vb6App;}} static zero zero () {// Actually to handle the event code}}
As I said, if at that point that activator.CreateInstance
runs, currently VB6 exe Everything is expected to work, and the code in DoSomething ()
is executed when myEvent
is removed in the VB6 app.
If the VB6 app is already standing alone, the C # app can still control it via COM (methods shown above for clarity), but DoSomething ()
code never runs in response to myEvent
.
Any ideas where I am getting wrong?
I think the problem lies in setting up sync for this event. At a quick estimate, I would say that you are building a new example of the VB component and assigning a new sync in the incidents that occur instead of the frequency already running.
Comments
Post a Comment