Page 1 of 1

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

Posted: Sun May 30, 2004 11:23 pm
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

Posted: Mon May 31, 2004 12:41 am
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 ;)

Posted: Mon May 31, 2004 1:28 am
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.

Posted: Mon May 31, 2004 1:46 am
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

Posted: Tue Jun 08, 2004 1:04 pm
by neomancer
how about destroywindow_(WindowID()) ?
that should clear up windows