[RESOLVED] How to unload WMP in custom ActiveX Control?
I'm using VB5.
I've tried some methods I've seen on here and other places for unloading the Windows Media Player ActiveX control, (specifically the newer one, "wmp.dll"), but those methods seem to only work if I have it embedded in a Standard EXE project's form. My project is an ActiveX Control, (specifically an OCX), and unloading it from my control produces a runtime error and a crash.
What is the proper way to remove/unload Windows Media Player, (for video playback specifically), in an ActiveX OCX Control?
I've tried stopping the video and making the URL property reference a vbNullString, and after that I tried both:
Code:
Unload WindowsMediaPlayer
Set WindowsMediaPlayer = Nothing
And just this by itself:
Code:
Unload WindowsMediaPlayer
Both produce the same runtime error and crash.
Any help or suggestions are greatly appreciated.
(Why has no one replied to me here on any of my topics yet?)
Thanks!
Samuel
Last edited by Samuel Venable; Feb 11th, 2018 at 12:14 AM.
Well it's not in a VB form, and yes the WMP control is in a UserControl. The ActiveX control is made in VB5, but the actual executable I want to embed it in is not a VB5 application, (it's not VB at all for that matter).
If no one else knows of a quick solution for me I guess I will have a look at that user guide CD that comes with VB5.
Thank you!
Edit: I found the solution.
I need this API function and Windows Message Constant:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10
And do this when right before the UserControl reaches its Terminate event:
Re: [RESOLVED] How to unload WMP in custom ActiveX Control?
Originally Posted by Samuel Venable
Edit: I found the solution.
I don't think that's a "clean" way of unloading an ActiveX control. An ActiveX control is composed of not just a child window but also COM code that exposes properties, methods and events relevant to the child window being wrapped. Simply closing the child window in that manner1 is most likely not going to destroy the COM portion of the ActiveX control as well. So, it may look like the ActiveX control is gone, but it is actually still loaded in memory.
Properly unloading the ActiveX control depends on how it was created. If it was placed on a VB5/6 Form/UserControl at design time, you won't be able to remove it until the Form/UserControl is unloaded. If it was loaded dynamically (either via the aforementioned Control Arrays or via the Controls collection), then it can be unloaded dynamically as well. If you're using a different ActiveX host container, it will depend on whether that container exposes an option to remove ActiveX controls dynamically.
Note that the control array approach requires that at least one element of the control array is already present on the Form/UserControl during design time. The Controls collection option2 has no such requirement, so it might be the more appropriate choice in your situation. You might want to check out these links to learn more about them:
1 According to MSDN, the Player.close method just "closes the current digital media file, not Windows Media Player itself." 2 I'm not sure if this is available in VB5.