Well put. "AS ANY" is a good hint to slow down and read the docs.
It means there are different ways of calling the routine, and you
need to sort out the implications before choosing one.
SysAllocString takes a Unicode string parameter. This is not
compatible with AS ASCIIZ or AS STRING declarations (AS STRING is
"close", but uses ANSI rather than Unicode). PowerBASIC does not
support Unicode directly, so you will need to handle these as
generic pointers (DWORD or LONG values).
The definition (bstr AS ANY) means exactly the same thing
as (BYVAL hBSTR AS DWORD), by the way... the former just
provides a better indication that you're passing a "mystery value",
by reference, where the latter may give the false impression that
you're just passing a number by value.
------------------
Tom Hanlin
PowerBASIC Staff
Announcement
Collapse
No announcement yet.
Declares in WinAPI (maybe mistake ?)
Collapse
X
-
Just my opinion, but whenever you encounter a DECLARE with one or more parameters defined 'AS ANY', take a break to think about it, and maybe read the SDK help file for the function.
AS ANY forces the call to pass the address of the variable or expression used in the CALL (or the implicit CALL when the procedure is a FUNCTION) unless an override is made at the point of the call.
Some of the conversions in the PB versions of the header (*.inc) files required a decision by the person doing the conversion, and the path they chose may not have agreed with the way you would have converted the "C" language reference had you done it yourself. This is not to say those conversions are incorrect - it's just that absent the 'in-line casting' available in C/C++, PB needs to make a decision about conversion.
MCM
Leave a comment:
-
-
The funny part is, if you remove them from the win32api.inc, you'll still able to call these.
The compiler adds them anyway so , another declaration is useless.
I think you should use Byval StrPtr() or VarPtr() to be safe.
+, use the SysAllocStringByte[Len] stuff for single byte..
------------------
http://www.hellobasic.com
Leave a comment:
-
-
Declares in WinAPI (maybe mistake ?)
Hi,
I encountered the following in the latest win32api.inc file.
Code:DECLARE FUNCTION SysAllocString LIB "OLEAUT32.DLL" ALIAS "SysAllocString" (sz AS ANY) AS DWORD DECLARE FUNCTION SysStringLen LIB "OLEAUT32.DLL" ALIAS "SysStringLen" (bstr AS ANY) AS DWORD
Code:DECLARE FUNCTION SysAllocString LIB "OLEAUT32.DLL" ALIAS "SysAllocString" (sz AS ASCIIZ) AS DWORD DECLARE FUNCTION SysStringLen LIB "oleaut32.DLL" ALIAS "SysStringLen" (BYVAL hBSTR AS DWORD) AS DWORD
Any ideas. I think all the ones that state AS ANY should be changed to
AS DWORD except for the SysAllocString
------------------
Tags: None
-
Leave a comment: