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 );}