What I discovered today was some FUNKY code that Samsung had created to set the Network properties of a Windows Phone 7 handset. Taking a peek under the skirt, I noticed something unreal. The application has unmanaged DLL’s
inside the XAP file!!!
Ok, you’re thinking, so what, this isn’t anything special. All they’ve done is add them manually into the project as a content build action.
True, they have done that, but what’s next is even more UNREAL.
Looking “into” NetworkProfile.dll (Silverlight managed code) reveals the TRUTH we’ve all been waiting to hear, can I run a “native” app for Windows Phone 7? The answer is TRUE (with some caveats).
There’s a funky DLL called Microsoft.Phone.InteropServices that lives in the GAC of all WP7 handsets that we need to enable COM access.
Now for this blog post, we’re only going to cover the “ComBridge” class in the above picture. When you open it in reflector it’s just an empty static method. But it’s magic is hidden.
Now to use this DLL in our application you can’t simply add it as a reference,you need to load the Assembly via reflection,and call its static methods.
Assembly a = Assembly.Load("Microsoft.Phone.InteropServices, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e");
Ok, now we’ve loaded it. We need to get the type (from the namespace), get the method and invoke it.
Type comBridgeType = a.GetType("Microsoft.Phone.InteropServices.ComBridge");
MethodInfo dynMethod = comBridgeType.GetMethod("RegisterComDll", BindingFlags.Public | BindingFlags.Static);
dynMethod.Invoke(null, new object[] { "Assembly.dll", new Guid("SomeGuidHere") });
Ok, now we’re almost ready. We need to clear ALL capabilities in WMAppManifest.xml and add the following line.
<Capability Name="ID_CAP_INTEROPSERVICES"/>
Once you’ve done that, add a blank XML file in the root of the app called “WMInteropManifest.xml” and add the following content to it.
<?xml version="1.0" encoding="UTF-8"?>
<Interop>
</Interop>
Yes I’m aware the tags are empty, they’re not required. Once you’ve done all that, right click and deploy your app. Before this will work, I’ve found you need to reboot your device for it to actually work.
That’s all for now, I’ll be posting more this weekend about how you can get access to the RIL (Radio Interface Layer), Registry & even access to the file system.
Above I mentioned some “caveats”. Sure you’re now loading native DLL’s, but your application is STILL running as a managed instance, and you are still bound to the normal restrictions from the OS. You will still get tombstoned,
killed etc.
这样才Windows Phone中就可以调用Win32 DLL了,也就可以在Windows Phone中调用C/C++写的代码了
分享到:
相关推荐
在C#文件中调用C++文件实现对应用功能
windows phone 8 应用程序调用C++ lib库代码示例
wp7调用webservices 包含页面之间的跳转 因为刚开始学习 也没有对页面进行美化 只是试试如何实现调用Webservices
wp8、wp7典型应用豆瓣搜源代码...
示例代码MusicAndVideosHubSample,windows phone7示例代码,WP7开发源代码。
WP7页面导航代码,非常实用的代码,学习wp开发必会的代码
wp7打砖块游戏代码,XNArkanoid打砖块游戏源码 XNArkanoid是一个Windows Phone 7翻拍的经典的打砖块游戏。它的开发在C#中使用XNA框架V4.0。
wp7调用webservices的例子 包含最基本的页面之间导航 我也刚学 做了个例子
WP7 天气预报代码,非常好的天气预报,希望大家也会喜欢......
wp7应用发开 代码 14-15章
wp7应用发开 代码 11-13章,
一个小WP7计算器加点小地图,试上传。Wp7,看好的是未来。
相信介绍: http://www.cnblogs.com/wildfeng/archive/2012/03/30/2425248.html
wp7工具集,xap12安装器,taskviewer任务查看器,AdvancedExplorer资源浏览器,WP7Booster优化器,wp7sdk_mini
WP7 QRCODE 代码,使用Silverlight_ZXing_Core库
wp7三星i8350刷机工具,不会用啊,有会用的大侠介绍一下啊。。
一个小小的关于WP7存储的代码,共享一下。
这是一个wordpress常用调用php代码,给wp使用者带来方便。
国内最新的wp7游戏程序部署工具,简单大气的界面可以与微软的zune相媲美,使用起来却比zune方便多了。这个最新版的轻量级的工具可以方便地搜索、下载和拖曳的方式部署任何的.xap程序。只要你的wp7手机是破解了的,就...
wp7高级编程中文版,有助于爱好wp7开发者,轻松学习,好好看吧