Professional IronPython


using the Windows Media Player Interop DLL



Download 20,35 Mb.
Pdf ko'rish
bet199/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   195   196   197   198   199   200   201   202   ...   453
using the Windows Media Player Interop DLL
It’s finally time to use early binding to create a connection to the Windows Media Player. This example 
uses the Windows Media Player as a control. You might find a number of online sources that say it’s 
impossible to use the Windows Media Player as a control, but it’s actually quite doable. Of course, you 
need assistance from yet another one of Microsoft’s handy utilities, Resource Generator (ResGen) to 
do it. The example itself relies on the normal combination of a form file and associated application file. 
The following sections provide everything needed to create the example.
Working with ResGen
Whenever you drop a control based on a COM component onto a Windows Forms dialog box, the 
IDE creates an entry for it in the 
.RESX
file for the application. This entry contains binary data that 
describes the properties for the COM component. You may not know it, but most COM components 
have a Properties dialog box that you access by right-clicking the control and choosing Properties from 
the context menu. These properties are normally different from those shown in the Properties window 
for the managed control. Figure 9-13 shows the Properties dialog box for the Windows Media Player.
fIguRE 9-13: 
The COM component has properties that
differ from the managed control.
548592c09.indd 180
2/24/10 12:48:21 PM
www.finebook.ir


Defining an Interop DLL
 

 
181
It’s essential to remember that the managed control is separate from the COM component in a 
Windows Forms application. The COM component properties appear in a separate location and 
the managed environment works with them differently. If you look in the 
.RESX
file, you see some-
thing like this:


AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAywAAAAIB
AAAAAQAAAAAAAAAAAAAAALYAAAAAAwAACAAUAAAAQgBlAGwAbABzAC4AdwBhAHYAAAAFAAAAAAAAAPA/
AwAAAAAABQAAAAAAAAAAAAgAAgAAAAAAAwABAAAACwD//wMAAAAAAAsA//8IAAIAAAAAAAMAMgAAAAsA
AAAIAAoAAABmAHUAbABsAAAACwAAAAsAAAALAP//CwD//wsAAAAIAAIAAAAAAAgAAgAAAAAACAACAAAA
AAAIAAIAAAAAAAsAAAAuHgAAfhsAAAs=

This binary data contains the information needed to configure the COM aspects of the component. 
When the application creates the form, the binary data is added to the component using the 
OcxState
property like this:
this.MP.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject(“MP.OcxState”)));
Because of the managed code/COM component duality of a Windows Forms application, you can’t 
simply embed the COM component into an IronPython application using techniques such as the one 
shown at 
http://msdn.microsoft.com/library/dd564350.aspx
. You must provide the binary data 
to the COM component using the 
OcxState
property. Unfortunately, IronPython developers have an 
added twist to consider. The C# code shown previously won’t work because you don’t have access to a 
ComponentResourceManager
for the IronPython form. Instead, you must read the resource from disk 
using code like this (note the code will appear on a single line in the source code file, even though it 
appears on multiple lines in the book):
self.resources = System.ComponentModel.ComponentResourceManager.
CreateFileBasedResourceManager(
‘frmUseWMP’, ‘C:/0255 - Source Code/Chapter09’, None)
Now, here’s where the tricky part begins (you might have thought we were there already, but 
we weren’t). The 
CreateFileBasedResourceManager()
method doesn’t support 
.RESX
files. 
Instead, it supports 
.RESOURCES
files. The ResGen utility can create 
.RESOURCES
files. You might 
be tempted to think that you can duplicate the binary data from the 
.RESX
file using 
.TXT
files as 
suggested by the ResGen documentation. Unfortunately, 
.TXT
files can only help you create string 
data in 
.RESOURCES
files.
So your first step is to create a Windows Forms application, add the component to it, perform any 
required COM component configuration (no need to perform the managed part), save the result, and 
then take the resulting 
.RESX
file for your IronPython application. You can then use ResGen to create 
the 
.RESOURCES
file using a command line like this:
ResGen frmUseWMP.RESX
548592c09.indd 181
2/24/10 12:48:21 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   195   196   197   198   199   200   201   202   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish