I FINALLY had some time to work on some of my ongoing attempt at error handling routines and have run into a few problems that I just cant seem to solve.
1.) SetError and GetLastError - If I set an error and then the next line in the same function is GetLastError then all is fine, but if that next line is a Macro, or a call to a function then GetLastError returns 0 so from the docs where is says
Is this what is happening when I leave my function where it is set (even momentarily) to call a function or Macro, and internally the value is being re-set????
2.) This is a bit trickier and some people don't like the concept, but PB suppt says its perfectly fine, so I will run with it. What I am doing is for logging purposes is the ability to log the API function called and the responses without adding extra lines of code to purposely say "I called this with these parameters" but more let macros wrap the whole thing so something like
can break it all down on its own and write to a file if I want it to.
Anyways things work great so far, until I hit a function that a parameter is declared "AS ANY" or more specifically if I declare
is legal but using it creates a compiler error if I have a wrapper called
My only choice so far is to rename the wrapping function and change the variable to a variant? like
I think its because the docs say
But I found nothing that says I can use "AS ANY" in a declare, but not in the actual function as a parameter?
If I change the ANY to a Variant in the actual function then I get a error that the declare does not match the actual wrapper. and if I keep the wrapper as ANY then I get another compiler error, so I ask, is the only way around to rename the function and use VARIANT where-ever I see "AS ANY" and then handle it????
1.) SetError and GetLastError - If I set an error and then the next line in the same function is GetLastError then all is fine, but if that next line is a Macro, or a call to a function then GetLastError returns 0 so from the docs where is says
You should call the GetLastError function immediately when a function's return value indicates that such a call will return useful data. That is because some functions call SetLastError(0) when they succeed, wiping out the error code set by the most recently failed function.
2.) This is a bit trickier and some people don't like the concept, but PB suppt says its perfectly fine, so I will run with it. What I am doing is for logging purposes is the ability to log the API function called and the responses without adding extra lines of code to purposely say "I called this with these parameters" but more let macros wrap the whole thing so something like
Code:
MacroReturnedValue = CallMacro(CallFunc(GetLastError()))
Anyways things work great so far, until I hit a function that a parameter is declared "AS ANY" or more specifically if I declare
Code:
DECLARE FUNCTION BackupRead ALIAS "BackupRead" (BYVAL hFile AS DWORD, lpBuffer AS BYTE, BYVAL nNumberOfBytesToRead AS LONG, lpNumberOfBytesRead AS LONG, BYVAL bAbort AS LONG, BYVAL bProcessSecurity AS LONG, lpContext AS ANY) AS LONG
Code:
FUNCTION BackupRead ALIAS "BackupRead" (BYVAL hFile AS DWORD, lpBuffer AS BYTE, BYVAL nNumberOfBytesToRead AS LONG, lpNumberOfBytesRead AS LONG, BYVAL bAbort AS LONG, BYVAL bProcessSecurity AS LONG, lpContext AS ANY) AS LONG End Function
Code:
FUNCTION PbBackupRead ALIAS "BackupRead" (BYVAL hFile AS DWORD, lpBuffer AS BYTE, BYVAL nNumberOfBytesToRead AS LONG, lpNumberOfBytesRead AS LONG, BYVAL bAbort AS LONG, BYVAL bProcessSecurity AS LONG, lpContext AS VARIANT) AS LONG DeclareFunctionSubParams REDIM FunctionParams(6) FunctionParams(0) = hFile FunctionParams(1) = lpBuffer FunctionParams(2) = nNumberOfBytesToRead FunctionParams(3) = lpNumberOfBytesRead FunctionParams(4) = bAbort FunctionParams(5) = bProcessSecurity FunctionParams(6) = lpContext LookUpFunctionSubParams CALL DWORD RealFunction USING BackupRead (BYVAL hFile, lpBuffer, BYVAL nNumberOfBytesToRead, lpNumberOfBytesRead, BYVAL bAbort, BYVAL bProcessSecurity , lpContext) TO RealFunctionReply 'Call Function FUNCTION = RealFunctionReply 'Return Reply END FUNCTION
Using ANY disables type checking for a given parameter, and passes the full 32-bit address of the variable passed on the stack. Since the internal format of variables differ greatly by type, you must use caution to be absolutely certain your code knows the data type in each invocation. Normally, a second parameter is used to specify the actual type of the ANY parameter.
If I change the ANY to a Variant in the actual function then I get a error that the declare does not match the actual wrapper. and if I keep the wrapper as ANY then I get another compiler error, so I ask, is the only way around to rename the function and use VARIANT where-ever I see "AS ANY" and then handle it????
Comment