DLL fails to create a window the second time it is called.

Everything else that doesn't fall into one of the other PB categories.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

DLL fails to create a window the second time it is called.

Post by halo »

The first time I call this DLL in the program, everything is fine. If I call it a second time, it fails to create the window. Why?

I am using this as a Blitz3D userlib.

Code: Select all

Global svar.s

ProcedureDLL.l RequestRegkey(title$)
svar=""
If OpenWindow(0,GetSystemMetrics_(#SM_CXSCREEN)/2-150,GetSystemMetrics_(#SM_CYSCREEN)/2-75,300,75,#PB_Window_SystemMenu,title$)
  CreateGadgetList(WindowID())
  TextGadget(#PB_ANY,10,6,280,20,"Enter your registration key:")
  box=StringGadget(#PB_ANY,10,28,280,20,"")
  button=ButtonGadget(#PB_ANY,150-30,52,60,20,"OK")
  Repeat
    Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      exit=1
    Case #PB_Event_Gadget
      Select EventGadgetID()
        Case button
          svar=GetGadgetText(box)
          exit=1
        EndSelect
    EndSelect
    Until exit=1
  Else
  MessageRequester(title$,"Failed to create window.",0)
  EndIf
CloseWindow(0)
ProcedureReturn @svar
EndProcedure
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Did you try setting "exit=0" at the start of your procedure (after svar="")

I have seen DLL's sometimes act quite strange when used with Blitz since Blitz has no way to free up a DLL until it exits. Variables sometimes don't act like you would expect.

By the way, CloseWindow(0) should be after "Until exit=1"
Where you have it right now, if OpenWindow fails, there would be nothing to close ;)
Image Image
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Setting exit to 0 would not affect the result. I get the "Failed to open..." message the second time, so it didn't even go into the loop.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

I solved it like this. I don't think blaming the problem on Blitz is sufficient here:

Code: Select all

Global svar.s
Global box
Global button

OpenWindow(0,GetSystemMetrics_(#SM_CXSCREEN)/2-150,GetSystemMetrics_(#SM_CYSCREEN)/2-75,300,75,#PB_Window_SystemMenu|#PB_Window_Invisible,title$)
CreateGadgetList(WindowID())
TextGadget(#PB_ANY,10,6,280,20,"Enter your registration key:")
box=StringGadget(#PB_ANY,10,28,280,20,"")
button=ButtonGadget(#PB_ANY,150-30,52,60,20,"OK")
CloseGadgetList()

ProcedureDLL.l RequestRegkey(title$)
svar=""
HideWindow(0,0)
SetGadgetText(box,"")
Repeat
  Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
    exit=1
  Case #PB_Event_Gadget
    Select EventGadgetID()
      Case button
        svar=GetGadgetText(box)
        exit=1
      EndSelect
  EndSelect
  Until exit=1
HideWindow(0,1)
ProcedureReturn @svar
EndProcedure
neomancer
User
User
Posts: 14
Joined: Fri Jun 04, 2004 10:25 am

Post by neomancer »

how about destroywindow_(WindowID()) ?
that should clear up windows
They can smash your cookie, but they cant take you fortune
Post Reply