Debugging DLL's and Beta tester program debugging example!

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Debugging DLL's and Beta tester program debugging example!

Post by Rescator »

Use this code and then simply provide a copy of, or give your testers the url to a DebugView tool.
A free debug viewer can be found at http://technet.microsoft.com/en-us/sysi ... 96647.aspx

Code: Select all

;This is an example of using the Windows system debugger
;A free debug viewer can be found at
;http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
;The following debugging is of most use when debugging DLL's,
;or when your beta testers are helping you to debug your programs.
;Big thanks to NoahPhense for mentioning the API function and
;and mentioning where to find Sysinternals debugview program.
;Edit: Updated url, macros instead of procedure, toggles native/api debug string output.

#ApiDebug=#True     ;#False to turn off API debugging, #True to activate API debugging
#ApiDebugName$="PB Test"

CompilerIf #ApiDebug=#True
 Macro DebugString(debug_text)
  OutputDebugString_(#ApiDebugName$+": "+debug_text)
 EndMacro
CompilerElse
 Macro DebugString(debug_text)
  Debug debug_text
 EndMacro
CompilerEndIf

;Use the below line wherever you wish to output debug hints/tests in your code.

DebugString("Just Testing!")
For more info on OutputDebugString see http://msdn2.microsoft.com/en-us/library/aa363362.aspx
Last edited by Rescator on Sat Feb 16, 2013 2:52 pm, edited 5 times in total.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Old variant (PB3.x):

Code: Select all

;This is an example of using the Windows system debugger
;A free debug viewer can be found at
;http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
;The following debugging is of most use when debugging DLL's,
;or when your beta testers are helping you to debug your programs.
;Big thanks to NoahPhense for mentioning the API function and
;and mentioning where to find Sysinternals debugview program.


#Debug=#True     ;#False to turn off debugging, #True to activate debugging
#DebugName="Test"

CompilerIf #Debug=#True
 Procedure OutputDebugString(debug_text$)
  OutputDebugString_(#DebugName+": "+debug_text$)
 EndProcedure
CompilerEndIf

;Use the below line wherever you wish to output debug hints/tests in your code.

CompilerIf #Debug : OutputDebugString("Just Testing!") : CompilerEndIf
Last edited by Rescator on Sat Feb 16, 2013 2:50 pm, edited 1 time in total.
Max
User
User
Posts: 67
Joined: Thu Nov 30, 2006 4:57 pm
Location: I long for the absolute loneliness of the death

Post by Max »

Very cool, Rescator
:D :D :D
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Debugging? Who has bugs :)

Seriously, nice toolset addition. Thanks.

cheers
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

This is very nice! I really needed this! Thanks!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: Debugging DLL's and Beta tester program debugging exampl

Post by Rescator »

Edited the first post (moved the old PB3.x code to 2nd post as well), and updated the sysintenals link as the old did not work any more.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Debugging DLL's and Beta tester program debugging exampl

Post by Kwai chang caine »

Very usefull, thanks RESCATOR
ImageThe happiness is a road...
Not a destination
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Re: Debugging DLL's and Beta tester program debugging exampl

Post by Nico »

Another way, use skeleton dll:

Code: Select all

#ApiDebug = #True     ;#False to turn off API debugging, #True to activate API debugging
  
CompilerIf #ApiDebug = #True
Global HandleListBox.i   
CompilerEndIf

Macro DebugEx(String)
  CompilerIf #ApiDebug = #True
    
    If HandleListBox <> 0
      Delay(50)
      SendMessage_(HandleListBox, #LB_INSERTSTRING, -1 , String)
    EndIf
    
    CompilerEndIf
EndMacro

CompilerIf #ApiDebug = #True
Procedure EnumChildWindowsProc(hwnd.i, *lParam.integer)
  Protected Class.s
  
  Class.s = Space (1024)
  GetClassName_(hwnd, @Class, 1024)
  
  If Class = "ListBox"
    *lParam\i = hwnd
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True 
EndProcedure

Procedure EnumWindowsProc(hwnd.i, *lParam.integer)
  Protected Title.s
  
  Title.s = Space (1024)
  GetWindowText_(hwnd, @Title, 1024)

  If LCase(Left(Title, 12)) = LCase("Debug Output")
    *lParam\i = hwnd
    ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True 
EndProcedure
CompilerEndIf

ProcedureDLL AttachProcess(Instance)
  CompilerIf #ApiDebug = #True

  Protected  HandleDebug.i
  
  EnumWindows_(@EnumWindowsProc(), @HandleDebug) 
  If HandleDebug <> 0
    ShowWindow_(HandleDebug, #SW_SHOW)
    EnumChildWindows_(HandleDebug, @EnumChildWindowsProc(), @HandleListBox) 
  EndIf
  
  CompilerEndIf
  
EndProcedure

ProcedureDLL DetachProcess(Instance)
EndProcedure

ProcedureDLL AttachThread(Instance)
EndProcedure

ProcedureDLL DetachThread(Instance)
EndProcedure

ProcedureDLL Test()
  DebugEx("PureBasic is Great")
  ProcedureReturn 1
EndProcedure
Code to test dll:

Code: Select all

If OpenLibrary(0, "MyDll.dll")
  If CallFunction(0, "Test")
    Debug "ok"
  EndIf 
EndIf
Post Reply