Utility for importing type libraries does not handle correctly function parameters of pointer types
Original Reporter info from Mantis: lacak @lacak.sk
-
Reporter name: LacaK
Original Reporter info from Mantis: lacak @lacak.sk
- Reporter name: LacaK
Description:
There is packages\winunits-base\src\typelib.pas unit which is used for importing type libraries into pascal units. (procedure ImportTypelib)
However when we have function parameter(s) which should be passed by reference this is not taken into account and in output pascal unit is only "param: type" instead of "var param: type"
Example:
function func(Type_:Integer;Value:WideString):Integer;dispid 33;
but it should be:
function func(Type_:Integer;var Value:WideString):Integer;dispid 33;
Now look into typelib.pas in method TTypeLibImporter.interfacedeclaration
There are around line 631 handled function parameters.
TypeToString(TI,FD^.lprgelemdescParam[k].tdesc) returns 'PWideString' (in my case) but later because of test on line 634 bParamByRef is 'P' deleted.
Later on line 643 is tested FD^.lprgelemdescParam[k].paramdesc.wParamFlags but it is 0 (PARAMFLAG_NONE), so no 'var' nor 'out' is added.
Steps to reproduce:
Try import any type library which published function/procedure with parameter of any pointer type (BSTR* , long*, etc.)
Additional information:
in Delphi is same type library imported with "var" before function parameter name.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa367051(v=vs.85).aspx
"The [in] attribute is applied to a parameter by default when no directional parameter attribute is specified."
https://msdn.microsoft.com/en-us/library/cc237804.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms221019(v=vs.85).aspx
"PARAMFLAG_NONE: The behavior of the parameter is not specified."