Page 1 of 1

Debugging DLL's and Beta tester program debugging example!

Posted: Thu Mar 03, 2005 2:35 pm
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

Posted: Tue Apr 10, 2007 5:05 am
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

Posted: Tue Apr 10, 2007 9:07 am
by Max
Very cool, Rescator
:D :D :D

Posted: Tue Apr 10, 2007 6:31 pm
by rsts
Debugging? Who has bugs :)

Seriously, nice toolset addition. Thanks.

cheers

Posted: Thu Apr 12, 2007 9:25 pm
by Inf0Byt3
This is very nice! I really needed this! Thanks!

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

Posted: Sat Feb 16, 2013 2:53 pm
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.

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

Posted: Sun Feb 17, 2013 7:54 pm
by Kwai chang caine
Very usefull, thanks RESCATOR

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

Posted: Tue Mar 12, 2013 7:40 pm
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