ShutdownBlockReasonCreate

Just starting out? Need help? Post your questions and find answers here.
auser
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Sep 06, 2006 6:59 am

ShutdownBlockReasonCreate

Post by auser »

I've tried to create a ShutdownBlockReason for Vista/Win7 Users to show them a reason for the block (instead Windows shows just that it's blocking for unknown reason). It works as I need it so far if I use via Prototype. But if I use via "Import" I got Unresolved symbol error instead. I prefer to use as "Import" cause there is a *.lib available I guess... so I wonder how to do it via import?

Code: Select all

; Does not work via Import that way:
; Import("user32.lib") 
;   ShutdownBlockReasonCreate(hWnd.i, *pwszReason)
;   ShutdownBlockReasonDestroy(hWnd.i)
; EndImport


Prototype ProtoShutdownBlockReasonCreate(hWnd.i, *pwszReason)
Prototype ProtoShutdownBlockReasonDestroy(hWnd.i)

If OpenLibrary(0, "user32.dll") 
  Global ShutdownBlockReasonCreate.ProtoShutdownBlockReasonCreate = GetFunction(0, "ShutdownBlockReasonCreate")
  Global ShutdownBlockReasonDestroy.ProtoShutdownBlockReasonDestroy = GetFunction(0, "ShutdownBlockReasonDestroy")
  CloseLibrary(0)
EndIf 

Procedure unicodePtr(string.s)
  If string.s
    *ptr = AllocateMemory(StringByteLength(string.s,#PB_Unicode))
    PokeS(*ptr,string.s,StringByteLength(string.s,#PB_Unicode),#PB_Unicode)
    ProcedureReturn(*ptr)
  EndIf     
EndProcedure
Procedure WindowsCallback(WindowID,Message,wParam,lParam)
  If Message=#WM_QUERYENDSESSION
    
    block_reason.s = "Download is still in progress."
    
    ShutdownBlockReasonCreate(WindowID(0), unicodePtr(block_reason.s))
    result = MessageRequester("Warning", block_reason.s+" Abort shutdown?", #PB_MessageRequester_YesNoCancel)
    If result = #PB_MessageRequester_Yes
      AbortSystemShutdown_(#Null)
    Else  
      ShutdownBlockReasonDestroy(WindowID(0))
      ProcedureReturn #True
    EndIf 
    ProcedureReturn #False
  Else
    ProcedureReturn #PB_ProcessPureBasicEvents
  EndIf
EndProcedure


; Testing 
If OpenWindow(0,0,0,200,100,"Shutdown and wait")
  SetWindowCallback(@WindowsCallback())
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf 
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ShutdownBlockReasonCreate

Post by netmaestro »

The user32.lib that ships with Purebasic doesn't contain all of the functions available in user32.dll. The user32.lib that ships with pellesc has that function. One option you have is to create a folder on your dev machine for non-native .lib files and reference them with the full path in your code. So you can put user32.lib from pellesc in there, reference it fully and your code will work.
BERESHEIT
auser
Enthusiast
Enthusiast
Posts: 195
Joined: Wed Sep 06, 2006 6:59 am

Re: ShutdownBlockReasonCreate

Post by auser »

Thank you. :)
Post Reply