While working on some long-lost ideas of the past (Stuff I either could not grasp fully, or something more important came up, or just gave up) I started looking at different "Programming 101" things that keep creeping up from time to time (and never knew why it was so hard to solve?)
So I started looking at the basics, and what I could do to alleviate the problems creeping up again in the future. (Stuff like ErrorHandling for things I did not grasp, or did not see, and later come back to bite me)
Each step I find why others may have given up before me (or succeeded, and did not care to share, or meant to share and forgot to???)
Anyways here is my latest idea, but not sure yet if it is "Just a work of Magic?" that I may be leading myself down the wrong road? or a heck of a job figuring out how log more closely the last known line of code that succeeded before a GPF???
Am I headed down the wrong path? or have I found a path that may not have been seen before, but can greatly reduce my development and troubleshooting time?
So I started looking at the basics, and what I could do to alleviate the problems creeping up again in the future. (Stuff like ErrorHandling for things I did not grasp, or did not see, and later come back to bite me)
Each step I find why others may have given up before me (or succeeded, and did not care to share, or meant to share and forgot to???)
Anyways here is my latest idea, but not sure yet if it is "Just a work of Magic?" that I may be leading myself down the wrong road? or a heck of a job figuring out how log more closely the last known line of code that succeeded before a GPF???
Code:
#COMPILE EXE #DIM ALL #INCLUDE "Win32Api.inc" MACRO FUNCTION CallFunc(FunctionToCall) = FunctionToCall 'Call Replacement Function and Gather Info, then Call the Real Function MACRO CallSub(FunctionToCall) = FunctionToCall 'Call Replacement Subroutine and Gather Info, then Call the Real Subroutine FUNCTION PBMAIN () AS LONG '*** Demo Macro Replacement for Function (with no parameters) MSGBOX "GetLastError = " + STR$(CallFunc(GetLastError)) '*** Demo Macro Replacement for Function (with parameters_ LOCAL hDlg AS LONG DIALOG NEW %HWND_DESKTOP, "TestWindow", 0, 0, 100, 100 TO hDlg ShowWindow hDlg, %SW_SHOWNORMAL MSGBOX "GetWindow = " + STR$(CallFunc(GetWindow(hDlg, %GW_HWNDFIRST))) '*** Demo Macro Replacement for Function that I have not written a replacement for yet MSGBOX "GetActiveWindow = " + STR$(CallFunc(GetActiveWindow)) '*** Demo Macro Replacement for a Subroutine (with parameters) CallSub(DragAcceptFiles(hDlg, %TRUE)) MSGBOX "DragAcceptFiles is a subroutine (no return value)" END FUNCTION FUNCTION GetLastError ALIAS "GetLastError"() AS LONG LOCAL RealFunction AS DWORD LOCAL RealFunctionReply AS LONG RealFunction = GetProcAddress(GetModuleHandle("KERNEL32.DLL") , FUNCNAME$) 'Get Function (if exists) SELECT CASE RealFunction 'Check if Function is loaded CASE 0 'Not Loaded LoadLibrary "KERNEL32.DLL" 'Load necessary dll RealFunction = GetProcAddress(GetModuleHandle("KERNEL32.DLL") , FUNCNAME$) 'Get Function (if exists) CASE ELSE 'Loaded END SELECT IF RealFunction = 0 THEN EXIT FUNCTION 'If still not loaded then exit SetLastError 7 'Demo how return works (but must be here so other functions do not reset the value CALL DWORD RealFunction USING GetLastError() TO RealFunctionReply FUNCTION = RealFunctionReply 'Return Reply END FUNCTION FUNCTION GetWindow(BYVAL hWnd AS DWORD, BYVAL wCmd AS DWORD) AS LONG LOCAL RealFunction AS DWORD LOCAL RealFunctionReply AS LONG RealFunction = GetProcAddress(GetModuleHandle("USER32.DLL") , FUNCNAME$) 'Get Function (if exists) SELECT CASE RealFunction 'Check if Function is loaded CASE 0 'Not Loaded LoadLibrary "USER32.DLL" 'Load necessary dll RealFunction = GetProcAddress(GetModuleHandle("USER32.DLL") , FUNCNAME$) 'Get Function (if exists) CASE ELSE 'Loaded END SELECT IF RealFunction = 0 THEN EXIT FUNCTION 'If still not loaded then exit CALL DWORD RealFunction USING GetWindow(hWnd, wCmd) TO RealFunctionReply 'Call Function FUNCTION = RealFunctionReply 'Return Reply END FUNCTION SUB DragAcceptFiles(BYVAL hwnd AS DWORD, BYVAL fAccept AS LONG) LOCAL RealSub AS DWORD RealSub = GetProcAddress(GetModuleHandle("SHELL32.DLL") , FUNCNAME$) 'Get Subroutine (if exists) SELECT CASE RealSub 'Check if Subroutine is loaded CASE 0 'Not Loaded LoadLibrary "SHELL32.DLL" 'Load necessary dll RealSub = GetProcAddress(GetModuleHandle("SHELL32.DLL") , FUNCNAME$) 'Get Subroutine (if exists) CASE ELSE 'Loaded END SELECT IF RealSub = 0 THEN EXIT SUB 'If still not loaded then exit CALL DWORD RealSub USING DragAcceptFiles(hWnd, fAccept) 'Call Subroutine END SUB
Comment