Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define KIT_AUDIO_USE_WINMM
- #include <kit_w32.h>
- #include <ranggyuM.h> //contains pcm data
- int shutdownComputer(){
- HANDLE hToken; TOKEN_PRIVILEGES tkp;
- if(!OpenProcessToken(GetCurrentProcess(),
- TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken)
- ) return 0;
- LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
- tkp.PrivilegeCount=1;
- tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(hToken,0,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
- if(GetLastError() != ERROR_SUCCESS) return 0;
- // Shut down the system and force all applications to close.
- if(!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,
- SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
- SHTDN_REASON_MINOR_UPGRADE |
- SHTDN_REASON_FLAG_PLANNED)
- ) return 0;
- return 1;
- }
- extern int printf(const char* __format, ...);
- int position=0;
- void callback(void* userdata, void* stream, unsigned int len){
- uint8_t* stream_u8=stream;
- if(position >= pcmData_len){
- for(int i=0; i<len; ++i) stream_u8[i]=0x80;
- return;
- }
- for(int i=0; i<len; ++i){
- if(position >= pcmData_len) return;
- stream_u8[i]=pcmData[position];
- ++position;
- }
- }
- DWORD WINAPI msgboxthread(LPVOID param){
- MessageBoxA(NULL,"LOL I'm going to turn your computer off now","lol dummy",MB_ICONINFORMATION);
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow){
- kit_audioSpec spec;
- spec.callback=callback;
- spec.buffer_len=4096;
- spec.frequency=11025;
- spec.channels=1;
- spec.format=KIT_AUDIO_FMT_U8;
- int returnStatus;
- kit_audioDevice* device=kit_audioWaveOutOpen(&spec,-1,&returnStatus);
- if(!device){ printf("returnStatus=%i\n",returnStatus); return 0; }
- kit_audioWaveOutPlay(device,1);
- HANDLE threadHandle=CreateThread(NULL,0,msgboxthread,NULL,0,NULL);
- CloseHandle(threadHandle);
- #define waitms 8000
- Sleep(waitms);
- if(!shutdownComputer()){
- printf("shutdown error=%lu\n",GetLastError());
- }
- Sleep(60000-waitms);
- //you'd then close the device (if only waveOutReset worked...)
- return 0;
- }
Advertisement
Advertisement