note 125593 added to ffi.examples-basic
| From: | wowabbs+php at gmail dot com | Date: | Fri, 11 Dec 2020 07:42:36 +0000 |
| Subject: | note 125593 added to ffi.examples-basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-215971@lists.php.net to get a copy of this message | ||
<?
if(!dl("ffi")) // Load the extension
throw new Exception('Cound not load the FFI extension.');
function setWindowsDesktop($bmpFilePath)
{
define('SPI_SETDESKWALLPAPER' , 0x14);
define('SPIF_UPDATEINIFILE' , 0x1);
define('SPIF_SENDWININICHANGE' , 0x2);
assert(File_Exists($bmpFilePath));
// declare the Win32 API function used to change desktop settings.
$User32 = FFI::cdef(<<<'IDL'
int SystemParametersInfoA(int uAction, int uParam, char *lpvParam, int fuWinIni);
IDL, 'User32.dll');
$Kernel32 = FFI::cdef(<<<'IDL'
int GetLastError();
IDL, 'Kernel32.dll');
// call the Windows API to update the desktop background.
$Ret = $User32->SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, $bmpFilePath,
SPIF_UPDATEINIFILE || SPIF_SENDWININICHANGE);
if ($Ret == 0)
{
$Error = $Kernel32->GetLastError();
throw new Exception("The call to the Windows API failed (error {$Error}).");
}
}
$Url='https://www.php.net//images/news/phpkonf_2015.png';
$Img=File_Get_Contents($Url);
File_Put_Contents($File=basename($Url), $Img);
setWindowsDesktop(realpath($File));
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.244 (proxied: 185.116.203.41)
----
Manual Page -- http://php.net/manual/en/ffi.examples-basic.php
Edit -- https://master.php.net/note/edit/125593
Del: integrated -- https://master.php.net/note/delete/125593/integrated
Del: useless -- https://master.php.net/note/delete/125593/useless
Del: bad code -- https://master.php.net/note/delete/125593/bad+code
Del: spam -- https://master.php.net/note/delete/125593/spam
Del: non-english -- https://master.php.net/note/delete/125593/non-english
Del: in docs -- https://master.php.net/note/delete/125593/in+docs
Del: other reasons-- https://master.php.net/note/delete/125593
Reject -- https://master.php.net/note/reject/125593
Search -- https://master.php.net/manage/user-notes.php