Silverlight5 RC calls WIN32API

Source: Internet
Author: User

That's right. As you know, silverlight5 RC has provided support for P/invoke to call local functions! At that time, I was a little excited. I immediately wrote a demo to test the effect.

It has been confirmed that it can be called normally only in silverlightoob trust mode! Client elevation of permission requires signing the certificate when the Silverlight application is released!

Set OOB mode to check to enhance the trust permission.


Example 1Example of calling the Windows Prompt box.

CodeAs follows:

[Dllimport("User32.dll", Entrypoint ="Messageboxa")]Static Extern IntMsgbox (IntHwnd,StringMSG,StringCaption,IntType );
 
 
Private VoidButton#click (ObjectSender, system. Windows.RoutedeventargsE) {msgbox (0,"This is the prompt box for calling DLL with dllimport! ","Prompt", 0x30 );}


Example 2 set the Silverlight window to the top


[ Dllimport ( "User32.dll" , Charset = Charset . Auto)] Private  Static  Extern  Int Setwindowpos ( Intptr Hwnd, Int Hwndinsertafter, Int X, Int Y, Int Width, Int Height, Int Flags ); ///     <Summary>  ///  Get the current activity window  ///    </Summary>  ///     <Returns> </returns> [ Dllimport ( "User32.dll" , Charset = Charset . Auto)] Private  Static  Extern System.Intptr Getforegroundwindow ();
 
 
 
Private VoidButton#click (ObjectSender, system. Windows.RoutedeventargsE) {setwindowpos (getforegroundwindow (),-1, 0, 0, 0, 0, 1 | 2 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.