BCX COM Interface
BCX_DISPATCHOBJECT function
Purpose: BCX_DISPATCHOBJECT
creates an instance of specified COM object based on IUnknown interface passed
as a parameter. It is similar to the CREATEOBJECT
function which creates an instance of COM object based on COM object name
(registered progid).
It can be used to manipulate properties/methods of ActiveX objects given ActiveX object IUnknown interface.
Note well that Nothing must be called for each created COM/ActiveX object otherwise memory leaks will occur!
Syntax: oBj = BCX_DISPATCHOBJECT(iunknown_ptr, release_param = FALSE) Parameters:
|
Example:
'************************************************************************
' BCX Media Player (0.3) by Kevin Diggins and Mike Henning
' Based on original PBWIN 7.0 code by Jose Roca
' Requirements: Windows Media Player, Automatic Template Libraries (ATL)
'************************************************************************
' Embeds the Windows Media PLayer ACTIVEX control within a BCX Form!
'************************************************************************
' Ljubisa Knezevic Added new late binding COM code that demonstrates
' use of BCX_DispatchObject. It allows easier manipultaion of ActiveX objects.
$LIBRARY
<oleaut32.lib>$LIBRARY
<uuid.lib>#include <oaidl.h>
GUI
"BCX Media Player"
CONST
IDC_CTRL=
1001
CONST
IDC_BUTT=
1002
GLOBAL
hWmpAS
HWNDGLOBAL
FormAS
HWNDGLOBAL
ButtAS
HWNDGLOBAL
pUnkAS
IUnknownPTR
'GLOBAL hr AS HRESULT
GLOBAL
Pth$GLOBAL
objWmpas
Object'DIM RAW mydispid = DISPID_PROPERTYPUT AS DISPID
DIM
RAW
Style=
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDRENSUB
FORMLOADBCX_SHOW_COM_ERRORS
(
TRUE)
Pth$=
SYSDIR$
&
"\atl.dll"
' Make it work on \WINDOWS\ and \WINNT\ systems
AtlAxWinInit(
lib
Pth$)
' Initialize ATL lib
Form=
BCX_FORM
(
"BCX Media Player"
,0
,0
,300
,200
, Style, WS_EX_CONTROLPARENT)
hWmp=
BCX_CONTROL
(
"AtlAxWin"
, Form,"WMPlayer.OCX"
, IDC_CTRL,0
,0
,0
,0
)
Butt=
BCX_BUTTON
(
"Load"
, Form, IDC_BUTT)
AtlAxGetControl(
lib
Pth$, hWmp,&
pUnk)
objWmp=
BCX_DispatchObject
(
pUnk, TRUE)
' pass IUnknown interface of object,
' TRUE - means release pUnk because
' we are not going to use it anymore.
CENTER
(
Form)
SHOW
(
Form)
IF
COMMAND$
>""
THEN
LoadWmp(
COMMAND$
)
END
SUB
BEGIN
EVENTS
DIM
RAW
rcAS
RECTSELECT
CASE
CBMSG
CASE
WM_SYSCOMMAND'*****************************************************
' Capture this message and send a WM_DESTROY
' message or the program will remain in memory
'*****************************************************
IF
(
wParamBAND
0xFFF0
)
=
SC_CLOSETHEN
SendMessage(
hWnd, WM_DESTROY, wParam, lParam)
EXIT
FUNCTION
END
IF
'*****************************************************
CASE
WM_COMMANDSELECT
CASE
LOWORD(
wParam)
CASE
IDC_BUTTDIM
A$ A$=
GETFILENAME$
(
"Open Media File"
,"*.*"
,0
, Form,0
,"C:\Recordings"
)
IF
A$ >""
THEN
LoadWmp(
A$)
A$=
""
END
IF
CASE
IDOKIF
HIWORD(
wParam)
=
BN_CLICKEDTHEN
END
IF
CASE
IDCANCELIF
HIWORD(
wParam)
=
BN_CLICKEDTHEN
SendMessage(
hWnd, WM_DESTROY, wParam, lParam)
EXIT
FUNCTION
END
IF
END
SELECT
'*****************************************************************************************
CASE
WM_SIZEIF
wParam <> SIZE_MINIMIZEDTHEN
GetClientRect(
hWnd,&
rc)
MoveWindow(
GetDlgItem(
hWnd,IDC_CTRL)
,0
,25
, rc.right-
rc.left, rc.bottom-
rc.top-
25
, TRUE)
END
IF
'*****************************************************************************************
CASE
WM_DESTROYSet
objWmp=
Nothing
PostQuitMessage(
0
)
EXIT
FUNCTION
'*****************************************************
END
SELECT
END
EVENTS
SUB
LoadWmp(
A$)
objWmp.url=
A$END
SUB
For examples of the BCX_DISPATCHOBJECT function see the COM folder in the Files section of the BCX Group on Yahoo.
Related topics: Object data type definition | CreateObject List of all COM Interface Functions