Add COM and ActiveX Support in .Net Compact Framework Using Odyssey Software CFCOM (Chinese)

zhaozj2021-02-11  232

Add COM and ActiveX Support in .Net Compact Framework Using Odyssey Software CFCOM (Chinese)

Andy sjöströmbusinessanyPlace.net

September 2003

Applies TO:

Microsoft® .NET Compact Framework 1.0 Microsoft Visual Studio® .NET 2003 Odyssey Software CFCOM 1.0 Microsoft Windows MobileTM -Based Pocket PC

Aawolf: This month, brought you a post on MSDN home page, reader evaluation of 7. Original text issued on September 8, 2003, and the topic is also a more concern to how to call COM and ActiveX components under CF. Therefore, the old wolf took out the time translation in the afternoon, hoping that everyone can understand the latest technology, and keep synchronization with it. But after all, the old wolf is a programmer rather than professional translators, and there is no more time to translate articles, so I hope everyone can read English information, and the translation of the old wolf is only referring to the reference. The original connection is as follows: http://msdn.microsoft.com/library/default.asp? URL = / library / en-us / dnppc2k3 / html / cfcom.asp

Summary: Learn in Visual C # If you add COM and ActiveX support to the .NET Compact Framework application. Also, how to use Macromedia Flash Player 6 for a Microsoft Windows Mobile-Based Pocket PC in the .NET Compact Framework application.

Background: The interoperability of COM and ActiveX is available in Full .NET Framework. Managed .NET Compact Framework code can use Platform Invoke (P / Invoke) to call non-managed code in the DLL, but support for COM and ActiveX in .NET Compact Framework is unavailable. ODYSSEY SOFTWARE CFCM as an intervention layer exposes COM objects and ActiveX controls to the .NET Compact Framework application, using a Memory Foot Print with only 30K.

Odyssey Software CFcom can transparently access controls (such as Windows Media Player) and objects (such as Pocket Outlook Object Model and AdoCE), and actually any third-party COM or ActiveX components. CFCOM can be licensed through Odyssey Software, although the code example in the article can be created in the code through the license key.

Download cfcom.exe from the Microsoft Download Center.

Contents

Introductionodyssey Software CFComcode Walk-Throughmacromedia Flash 6 Player for Pocket Pcflash AnyplaceFlash Anyplace Code Walk-ThroughconClusion

Introduction

No matter whether the size, .NET Compact Framework's namespace and class structure hierarchy and complete .NET Framework are very similar. Of course, because of the problem of volume and execution efficiency, some features of the .NET Framework are removed. One of them is COM intermingness. Many core modules for Microsoft® Windows® CE and Pocket PC are implemented as COM objects and ActiveX controls, such as connectivity, messages, communications, graphics, media, object storage, and personal information management (PIM). There are also many third-party COM and ActiveX controls being used on mobile devices, such as GPS, chart, security, and connectivity. Platform Invoke (P / Invoke) is stored in System.Runtime.InteropServices namespace, which can be used to call simple non-accomplished code functions. An example of a third-party effective provider is SAPPHIRE SOLUTIONS LTD (http://www.sapphire-solutions.co.uk/), using the existing .NET Compact Framework service is sufficient. SAPPHIRE SOLUTIONS Remote Access Service, CPP, and more via components and source code. The SAPPHIRE SOLUTIONS component is loaded into the .NET Compact Framework code example with Platform Invoke, making it earlier to start using these code. Calling more complex non-managed code functions requires a large number of complex codes, including more challenging areas, such as Marshalling. Developing COM packages often require a single function-based interface. Combining COM and ActiveX is challenging in managed code.

Odyssey Software CFCOM

Odyssey Software is not unfamiliar with the Windows CE developer community. Since 1996, they have played an important role in promoting enterprise mobile app development, and their products have Cefusion and Viaxml. The company continuously provides tools for mobile application development communities. This time they brought a conversion layer in the middle of COM and Compact Framework, which allows COM to expose an equivalent .NET interface. CFCOM is converted to COM and ActiveX to Compact Framework applications to provide a wide range of interoperability.

CFcom can be seen as a package that enables COM and .NET objects to run in the same application. A Compact Framework object is constrained in the managed memory when a COMMON LANGUAGE RUNTIME (CLR) is saved in non-accomplished memory. CFcom enables a transparent conversion layer that allows managed and non-accomplished components to interact: set or acquire attribute values, call methods, capture COM events, process advanced type conversion functions (AKA Marshalling) and from non-accomplished code The local .NET exception is generated in the abnormal event.

For developers, cfcom consists of three files:

· Odyssey.cfcom.dll contains CFCOM runtime.

· Odyssey.cfcom.design.dll provides the design period support for Visual Studio. This file is installed in the C: / Program Files / Microsoft Visual Studio .NET 2003 / CompactFrameworksDK / V1.0.5000 / Windows CE / Designer directory.

· ODYSSEY.CFCOM.1248.DLL is the runtime component of local (device support).

Figure 1 shows that the COMOBJECT and COMCONTROL tools are added to Toolbox.

Figure 1. COMOBJECT AND COMCONTROL Tools Added to the Toolboxodyssey Software also includes an example Windows Media Player Wrapper Designer, developers can add to Toolbox and set attribute values ​​during the design period. Compact Framework applications using Windows Media Player can be created quickly.

For Embedded Visual Basic developers, cfcom means they can use familiar COM objects and ActiveX components without learning C / C and P / Invoke. Embedded Visual C Developers can continue to use C to write the performance-critical section of their application without creating a local package and use Custom Marshalling.

ODYSSEY SOFTWARE CFCOM, you can read Microsoft Case Study, COM Interop Library Gives Compact Framework Applications Easy Access To CoM Components and Activex Controls.

Code Walk-Through

The design idea of ​​CFCOM is to achieve transparent conversion. Just do two things before using the ActVIEX control or COM object.

· ActiveX control or progid or CLSID of the COM object.

· License Key from the CFcom obtained from ODYSSEY SOFTWARE.

After that, you can start using the CFCM's call method to use the components. The following code shows how to use Windows Media Player in a Compact Framework application.

License Key is set at the main function entry of the application.

COMOBJECT.ADDLICENSE (CFcom_LicenseKey);

One-form application can start using Windows Media Player.

Public Class frmmain: System.Windows.Forms.form

{

Private const string cfcom_licensekey = "xxxxxxxxxxxxxxxxxxxxxxxx";

Public frmmain ()

{

InitializationComponent ();

mpc.progid = "wmpceocx.wmp";

Mpc.invoke ("ShowControls", Invokeflags.SetProperty, False);

Mpc.invoke ("ShowaudioControls", Invokeflags.SetProperty, False);

Mpc.invoke ("ShowPositionControls", Invokeflags.SetProperty, False);

Mpc.invoke ("ShowTracker", Invokeflags.SetProperty, False);

Mpc.invoke ("ShowStatusbar", Invokeflags.SetProperty, true);

Mpc.invoke ("AutoStart", Invokeflags.SetProperty, True;

Mpc.invoke ("FileName", Invokeflags.SetProperty, "http://news.com.com/1604-2-966406-1.asx?msft_aw win"" MPC.INVOKE ("sendMouseClicKevents ", Invokeflags.SetProperty TRUE);

Mpc.comObject.comEvent = new comventhandler (mpc_comevent);

}

Note How to set up ProgID and how to set properties through the Invoke method. Invokeflags Enumeration includes SetProperty, GetProperty, and CallMethod.

For more information on these codes and how to add multimedia information in the Compact Framework application, "Play Media with .NET CF USING CFCOM" http://www.businessanyPlace.net/?p=cfcommedia.

Figure 2 shows the application using Windows Media Player ActiveX.

Figure 2. Windows Media Player Active X Control

Macromedia Flash 6 Player for Pocket PC

Macromedia has exited the free Pocket PC player playing the Macromedia Flash content. Flash is a popular platform for publishing High Profile Content, Movies, can even be used for mobile applications. The Flash development group is active and growing. Based on Visual Studio .Net and the Compact Framework, developers use Flash in mobile applications to easily create singular content and applications. Pocket PC Player's personal version can be found on the Macromedia Web server: http://www.macromedia.com/software/flashplayer/pocketpc/2002.html.

The player is an ActiveX control, mostly in Pocket Internet Explorer, physically as Flash.dll is installed in the / windows / macromedia directory. Once the player is installed, the user can watch the Macromedia Flash content via Pocket Internet Explorer. One way is to place a flash content file (.swf) and HTML files in the same directory and open the HTML file. This HTML file shows how the ActiveX control is called. The following fragments are from the HTML file:

book </ title></p> <p></ HEAD></p> <p><Body bgcolor = "# 53695c"></p> <p><Object classid = "CLSID: D27CDB6E-AE6D-11CF-96B8-444553540000"</p> <p>Codebase = "http://active.macromedia.com/flash2/cabs/swflash.cab#version=6, 0, 0"</p> <p>ID = rapier4 width = 230 height = 255></p> <p><Param name = movie value = "book.swf"></p> <p><Param name = menu value = false></p> <p><Param name = Quality value = high></p> <p><Param name = bgcolor value = # 53695c></p> <p></ Object></p> <p></ Body></p> <p></ Html></p> <p>After the "param" property, the ActiveX control is called using the parameter reference. The movie called "book.swf" is played, the Flash content menu is turned off, the playback quality is high, the background color is set to # 53695c.</p> <p>Figure 3 shows the effects in Pocket Internet Explorer.</p> <p>Figure 3. Pocket PC Flash Player in Action</p> <p>The Macromedia Flash Content in this example is designed by the flash developer Phillip Torrone Phillip Torrone, from FlashenAbled.com (http://www.flashenabled.com/). More similar examples and about Pocket PC and Macromedia Flash-related information can be viewed to Pocket PC Flash (http://www.pocketpcflash.net/home.htm).</p> <p>For more information about the FALSH player parameters, see "Scripting with Flash Player and ActiveX" from the Macromedia web server: http://www.macromedia.com/support/flash/ts/documents/activex_script.htm.</p> <p>Let us see how to use Flash Player in a Compact Framework application.</p> <p>Flash Anyplace</p> <p>Flash AnyPlace is an application using the CFCOM using the Flash ActiveX control. Flash AnyPlace can play content and user control how to play content. Figure 4 shows the first form.</p> <p>Figure 4. Flash Player Settings</p> <p>In this form, the user can set which flash file and control the behavior of the Flash file play. The second form (Figure 5) shows the actual flash file being played.</p> <p>Figure 5. Viewing the file</p> <p>Flash Anyplace Code Walk-Through</p> <p>This project contains two forms. The following code is executed when the user clicks on the "Play" button in the first form:</p> <p>Private void btnplay_click (Object Sender, System.EventArgs E)</p> <p>{</p> <p>Cursor.current = cursors.waitcursor;</p> <p>frmFlashAnyplacePlayer flashAnyplacePlayer = new frmFlashAnyplacePlayer (this, this.txtFlashFile.Text, this.cmbQuality.SelectedIndex, this.cmbScale.SelectedIndex, this.chkLoop.Checked, this.chkMenu.Checked, this.txtBackgroundColor.Text);</p> <p>FlashanyPlacePlayer.showDialog ();</p> <p>}</p> <p>The parameters are passed to the second form, and a cfcom comControl is in this form. Macromedia Flash Player's Progid is ShockWaveflash.shockwaveflash. Below is the initialization of this form InitializeComponent section:</p> <p>This.FlashPlayer = New Odyssey.cfcom.comControl ();</p> <p>This.FlashPlayer.Progid = "ShockWaveflash.shockwaveflash"; use CLSID creation as in the HTML file of playing Flash content in Pocket Internet Explorer. This line will write this:</p> <p>THIS.FLASHPLAYER.Progid = "{D27CDB6E-AE6D-11CF-96B8-444553540000}"</p> <p>Note that the license key has been set before ComconTrol works. First, set the License Key string in the declaration.</p> <p>Private const string cfcom_licensekey = "xuhxratlauvkl96efvbh9beuv7";</p> <p>This license key is CFCOM that can only use Flash Player (using progID) and can only be used in this project. The AddLicense method should be prioritized in the location of the form in Application.Run. CFCOM will find this license during each process.</p> <p>Static void main ()</p> <p>{</p> <p>// set License Key</p> <p>Comcontrol.addlicense (cfcom_licensekey);</p> <p>Application.run (New frMflashanyPlace ());</p> <p>}</p> <p>If the Flash file is on the Internet, use the URL as a movie address. For example http://www.businessanyPlace.net/files/flashanyper.swf. If the Flash file is located on the Pocket PC, use the following format:</p> <p>File: ///my documents/mymovie.swf</p> <p>The Flash AnyPlace project will use a Flash file as a Content Item installed in the application directory. Get the current application directory and use this Flash file as the default, the following code will execute:</p> <p>// Get Application Directory</p> <p>String currentdir = new fileInfo (asmbly.getexecutingassembly (). getname (). Codebase) .directoryName;</p> <p>// set default values</p> <p>TXTFLASHFILE.TEXT = @ "file: //" Currentdir @ "/ book.swf";</p> <p>The second form of the LOAD event is passed to the Flash Player by cfcom:</p> <p>Try</p> <p>{</p> <p>FlashPlayer.Invoke ("Quality", Invokeflags.SetProperty, Quality;</p> <p>FlashPlayer.Invoke ("BGColor", Invokeflags.SetProperty, BackgroundColor;</p> <p>FlashPlayer.Invoke ("Scale", Invokeflags.SetProperty, Scale);</p> <p>FlashPlayer.Invoke ("Loop", Invokeflags.SetProperty, LOOP;</p> <p>FlashPlayer.Invoke ("Menu", Invokeflags.SetProperty, Menu;</p> <p>FlashPlayer.Invoke ("Movie", Invokeflags.SetProperty, Flashfile;</p> <p>}</p> <p>Catch (Exception EX)</p> <p>{</p> <p>Messagebox.show (ex.Message);</p> <p>}</p> <p>Finally {</p> <p>Parentform.hide ();</p> <p>Cursor.current = CURSORS.DEFAULT;</p> <p>}</p> <p>If we try to pass an invalid parameter name to Macromedia Flash Player, the exception handle will return an appropriate exception. For example, when "MOVIE1" is passed, "MOVIE" is replaced by an attribute, and CFcom will throw an exception "0x80020006: DISP_E_UNKNOWNNAME."</p> <p>Finally, when the user leaves this form with Flash Player, the cfcom comControl needs to be released:</p> <p>Private void frMflashanyPlacePlayer_closing (Object Sender, System.componentmodel.canceleventargs E)</p> <p>{</p> <p>FlashPlayer.dispose ();</p> <p>ParentForm.show ();</p> <p>}</p> <p>From cfcom help: "Maybe as simple as CFCOM, there is a very important issue that needs to be understood, that is, the uncertainty of garbage collection, often manually recycling COM resources is necessary .comobject.dispose and Comcontrol.Dispose method is mature Some ActiveX controls, such as Windows Media Player, when they are released before being released by garbage, "</p> <p>Conclusion</p> <p>Odyssey Software CFCOM</p> <p>Dedicate</p> <p>Compact Framework</p> <p>Some very challenging areas in development:</p> <p>ActiveX</p> <p>with</p> <p>COM</p> <p>Interoperability. By performing a conversion layer between the managed code and the non-accomplished code, developers can commit to the core challenge to bring their customers to their customers.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5036.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5036" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.040</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'yUUAI3myX1rd4LnSXM7Riz0ODAkAJUg4ZGhH30tYGr9FVYvV3QxKWJ9KIIv_2Bl4puPT1dxZhT6UtlOF6yn5DF5Q_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>