It is currently Wed Nov 25, 2020 3:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Debugging DLL's and Beta tester program debugging example!
PostPosted: Thu Mar 03, 2005 2:35 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1769
Location: Norway
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:
;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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Apr 10, 2007 5:05 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1769
Location: Norway
Old variant (PB3.x):
Code:
;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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Apr 10, 2007 9:07 am 
Offline
User
User

Joined: Thu Nov 30, 2006 4:57 pm
Posts: 67
Location: I long for the absolute loneliness of the death
Very cool, Rescator
:D :D :D


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Apr 10, 2007 6:31 pm 
Offline
Addict
Addict

Joined: Wed Aug 24, 2005 8:39 am
Posts: 2736
Location: Southwest OH - USA
Debugging? Who has bugs :)

Seriously, nice toolset addition. Thanks.

cheers


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Apr 12, 2007 9:25 pm 
Offline
PureBasic Fanatic
PureBasic Fanatic

Joined: Fri Dec 09, 2005 12:15 pm
Posts: 2236
Location: Elbonia
This is very nice! I really needed this! Thanks!

_________________
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging DLL's and Beta tester program debugging exampl
PostPosted: Sat Feb 16, 2013 2:53 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 5:05 pm
Posts: 1769
Location: Norway
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging DLL's and Beta tester program debugging exampl
PostPosted: Sun Feb 17, 2013 7:54 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4790
Location: Lyon - France
Very usefull, thanks RESCATOR

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging DLL's and Beta tester program debugging exampl
PostPosted: Tue Mar 12, 2013 7:40 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Jan 11, 2004 11:34 am
Posts: 274
Location: France
Another way, use skeleton dll:
Code:
#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:
If OpenLibrary(0, "MyDll.dll")
  If CallFunction(0, "Test")
    Debug "ok"
  EndIf
EndIf


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye