possible bug - thread crashing due to an unknown reason

Just starting out? Need help? Post your questions and find answers here.
reijin
New User
New User
Posts: 4
Joined: Sun Jun 08, 2008 1:19 pm
Location: Germany

possible bug - thread crashing due to an unknown reason

Post by reijin »

Hello!!
Im not new to PB and i already tried to fix this problem. And posted it in the german forum - without any result.

This code is part of a dll. It will be injected into a process.
What is should do:
Showing a messagerequester.
waiting for pushing the HOME-Key.
OPening a window.

Code: Select all

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Text_0
  #val
  #Button_1
EndEnumeration

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Courier New", 10)

Procedure.l HexDec(h$)
  h$=UCase(h$)
  For r=1 To Len(h$)
    d<<4 : a$=Mid(h$,r,1)
    If Asc(a$)>60
      d+Asc(a$)-55
    Else
      d+Asc(a$)-48
    EndIf
  Next
  ProcedureReturn d
EndProcedure

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 289, 142, 188, 98, "IngameMenu - TEST",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_WindowCentered )
    If CreateGadgetList(WindowID(#Window_0))
      TextGadget(#Text_0, 10, 10, 90, 30, "Value at 0x004e8154:")
      SetGadgetFont(#Text_0, FontID1)
      StringGadget(#val, 100, 20, 80, 20, "", #PB_String_ReadOnly)
      SetGadgetFont(#val, FontID1)
      ButtonGadget(#Button_1, 10, 60, 170, 30, "Injection-Test")
     
    EndIf
  EndIf
EndProcedure

Procedure main(dummy)
Repeat 
Delay(100)
Until GetAsyncKeyState_(VK_INSERT) <> 0
Open_Window_0()

SetGadgetText(#val, Str(PeekL(HexDec("004e8154"))))


Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadget() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  ;You can place code here, and use the result as parameters for the procedures
  
  If Event = #PB_Event_Gadget
      
    If GadgetID = #Button_1
      MessageRequester("dont klick", ">_<")
    EndIf
    
  EndIf
  
Until Event = #PB_Event_CloseWindow ; End of the event loop
EndProcedure

MessageRequester("hackdll", "I have been injected!")
CreateThread(@main(), dummy)
What it does:
Showing a messagerequester.
Quitting.
By debugging i found out that the code keeps crashing, when it reaches the "delay".
Is this a bug? Thanks in advice.

greetings, reijin
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Have you compiled with the threadsafe option enabled?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: possible bug - thread crashing due to an unknown reason

Post by tinman »

reijin wrote:

Code: Select all

MessageRequester("hackdll", "I have been injected!")
CreateThread(@main(), dummy)
What it does:
Showing a messagerequester.
Quitting.
By debugging i found out that the code keeps crashing, when it reaches the "delay".
Is this the code you are testing? Because you will create the thread but the main thread will come to the end of the program and exit (including destroying your thread).

It would appear to be caused by the delay() command because when your new thread calls delay execution would switch back to the main thread (which would be when the program would exit).
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
IceSoft
Addict
Addict
Posts: 1684
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Solved.

The # was missed on

Code: Select all

GetAsyncKeyState_(VK_INSERT)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

IceSoft wrote:Solved.

The # was missed on

Code: Select all

GetAsyncKeyState_(VK_INSERT)
You should use EnableExplicit; always!!

> Procedure.l HexDec(h$)
Äh... The function Val(), does also support Bin- and Hex-numbers since version 4.20!

P.S.:
if you're german, feel free to join the german PB-Forum: http://www.pure-board.de
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply