Browse Source

--- Merging r22612 into '.':
U packages/winunits-base/src/typelib.pas
--- Merging r22613 into '.':
U packages/winunits-base/src/activex.pp
--- Merging r22615 into '.':
U rtl/win/sockets.pp
--- Merging r22618 into '.':
G packages/winunits-base/src/activex.pp
--- Merging r22634 into '.':
U utils/importtl/importtl.pas
G packages/winunits-base/src/typelib.pas
--- Merging r22638 into '.':
U packages/winunits-base/src/comobj.pp
G packages/winunits-base/src/activex.pp

# revisions: 22612,22613,22615,22618,22634,22638
r22612 | marco | 2012-10-11 16:30:34 +0200 (Thu, 11 Oct 2012) | 2 lines
Changed paths:
M /trunk/packages/winunits-base/src/typelib.pas

* Fix for typelib importer by Ludo Mantis #22109
r22613 | marco | 2012-10-11 16:37:24 +0200 (Thu, 11 Oct 2012) | 3 lines
Changed paths:
M /trunk/packages/winunits-base/src/activex.pp

* corrected IPrint and IOleCommandtarget to functions. Patch by Ludo, Mantis #22109
r22615 | marco | 2012-10-12 10:07:17 +0200 (Fri, 12 Oct 2012) | 2 lines
Changed paths:
M /trunk/rtl/win/sockets.pp

* add comment to size_t definition. Documents issue #22834 a bit.
r22618 | yury | 2012-10-12 18:22:38 +0200 (Fri, 12 Oct 2012) | 4 lines
Changed paths:
M /trunk/packages/winunits-base/src/activex.pp

* Fixed declaration of IEnumUnknown.Next().
* Added IOleContainer.EnumObjects() flags.
* Added IObjectWithSite
* Fixed nested comments warnings.
r22634 | marco | 2012-10-13 13:27:20 +0200 (Sat, 13 Oct 2012) | 3 lines
Changed paths:
M /trunk/packages/winunits-base/src/typelib.pas
M /trunk/utils/importtl/importtl.pas

* fix from Ludo to optionally skip generation of "tag" records and associated
symbols. Mantis #23113
r22638 | yury | 2012-10-13 19:16:23 +0200 (Sat, 13 Oct 2012) | 1 line
Changed paths:
M /trunk/packages/winunits-base/src/activex.pp
M /trunk/packages/winunits-base/src/comobj.pp

* Fixed declaration of ITypeInfo.Invoke(). The last 3 parameters should be able accept nil values. This fixes calling late binding methods of ActiveX server implemented with FPC. Patch by Ludo Brands.

git-svn-id: branches/fixes_2_6@22681 -

marco 13 years ago
parent
commit
216def228f

+ 27 - 12
packages/winunits-base/src/activex.pp

@@ -1361,6 +1361,7 @@ TYPE
 
    DVTARGETDEVICE               = TagDVTARGETDEVICE;
    PDVTARGETDEVICE              = ^tagDVTARGETDEVICE;
+   PTAGDVTARGETDEVICE           = PDVTARGETDEVICE;
    LPCLIPFORMAT                 = ^TCLIPFORMAT;
    TCLIPFORMAT                  = Word;
    CLIPFORMAT                   = TCLIPFORMAT;
@@ -2211,7 +2212,7 @@ TYPE
      IEnumUnknown = Interface(IUnknown)
         ['{00000100-0000-0000-C000-000000000046}']
         //    pointer_default(unique)
-     Function Next(Celt:Ulong;out rgelt;out pCeltFetched:pulong):HRESULT;StdCall;
+     Function Next(Celt:Ulong; out rgelt;pCeltFetched:pulong):HRESULT;StdCall;
 //    HRESULT RemoteNext(        [in] ULONG celt,        [out, size_is(celt), length_is( *pceltFetched)]        IUnknown **rgelt,        [out] ULONG *pceltFetched);
      Function Skip(Celt:Ulong):HResult;StdCall;
      Function Reset():HResult;
@@ -2318,14 +2319,14 @@ TYPE
        End;
 
     ISequentialStream = Types.ISequentialStream;
-    {interface(IUnknown)
+    (*interface(IUnknown)
        ['{0c733a30-2a1c-11ce-ade5-00aa0044773d}']
        function Read(pv : Pointer;cb : ULONG;pcbRead : PULONG) : HRESULT;stdcall;
        function Write(pv : Pointer;cb : ULONG;pcbWritten : PULONG): HRESULT;stdcall;
      end;
-    }
+    *)
 
-    { defined above by pulling it in from types IStream = interface(ISequentialStream)
+    (* defined above by pulling it in from types IStream = interface(ISequentialStream)
        ['{0000000C-0000-0000-C000-000000000046}']
        function Seek(dlibMove : LargeInt; dwOrigin: Longint;
             out libNewPosition : LargeInt): HResult; stdcall;
@@ -2341,7 +2342,7 @@ TYPE
        Function Stat(out statstg : TStatStg; grfStatFlag: Longint): HRESULT;stdcall;
        function Clone(out stm : IStream) : HRESULT; stdcall;
      end;
-    }
+    *)
     IEnumSTATSTG = Interface (IUnknown)
        ['{0000000d-0000-0000-C000-000000000046}']
         Function Next (Celt:ULong;Out xcelt;pceltfetched : PUlong):HResult; StdCall;
@@ -3005,7 +3006,7 @@ TYPE
       Function  LocalGetIDsOfNames():HResult;StdCall;
      {$endif}
      {$ifndef Call_as}
-     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD; VAR pDispParams: DISPPARAMS; OUT pVarResult: VARIANT; OUT pExcepInfo: EXCEPINFO; OUT puArgErr: UINT):HResult;StdCall;
+     Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD; VAR pDispParams: DISPPARAMS; pVarResult: PVARIANT; pExcepInfo: PEXCEPINFO; puArgErr: PUINT):HResult;StdCall;
      {$else}
      Function  LocalInvoke ():HResult;StdCall;
      {$endif}
@@ -3240,6 +3241,15 @@ TYPE
      Function ParseDisplayName(CONST bc: IBindCtx; pszDisplayName: POleStr;OUT chEaten: Longint; OUT mkOut: IMoniker): HResult;StdCall;
      End;
 
+const
+     // IOleContainer.EnumObjects() flags
+     OLECONTF_EMBEDDINGS    = 1;
+     OLECONTF_LINKS         = 2;
+     OLECONTF_OTHERS        = 4;
+     OLECONTF_ONLYUSER      = 8;
+     OLECONTF_ONLYIFRUNNING = 16;
+
+type
    IOleContainer = interface(IParseDisplayName)
      ['{0000011B-0000-0000-C000-000000000046}']
      Function EnumObjects(grfFlags: Longint; OUT Enum: IEnumUnknown):HResult;StdCall;
@@ -3510,15 +3520,15 @@ type
 
     IPrint = interface(IUnknown)
        ['{B722BCC9-4E68-101B-A2BC-00AA00404770}']
-       procedure SetInitialPageNum(nFirstPage:Integer);stdcall;
-       procedure GetPageInfo(out pnFirstPage:Integer;out pcPages:Integer);stdcall;
-       procedure RemotePrint(grfFlags:LongWord;var pptd:PDVTARGETDEVICE;var pppageset:PtagPAGESET;var pstgmOptions:tagRemSTGMEDIUM;pcallback:IContinueCallback;nFirstPage:Integer;out pcPagesPrinted:Integer;out pnLastPage:Integer);stdcall;
+       function SetInitialPageNum(nFirstPage:Integer):HRESULT;stdcall;
+       function GetPageInfo(out pnFirstPage:Integer;out pcPages:Integer):HRESULT;stdcall;
+       function RemotePrint(grfFlags:LongWord;var pptd:PtagDVTARGETDEVICE;var pppageset:PtagPAGESET;var pstgmOptions:tagRemSTGMEDIUM;pcallback:IContinueCallback;nFirstPage:Integer;out pcPagesPrinted:Integer;out pnLastPage:Integer):HRESULT;stdcall;
       end;
-
+  
     IOleCommandTarget = interface(IUnknown)
        ['{B722BCCB-4E68-101B-A2BC-00AA00404770}']
-       procedure QueryStatus(var pguidCmdGroup:GUID;cCmds:LongWord;var prgCmds:_tagOLECMD;var pCmdText:_tagOLECMDTEXT);stdcall;
-       procedure Exec(var pguidCmdGroup:GUID;nCmdID:LongWord;nCmdexecopt:LongWord;var pvaIn:OleVariant;var pvaOut:OleVariant);stdcall;
+       function QueryStatus(var pguidCmdGroup:GUID;cCmds:LongWord;var prgCmds:_tagOLECMD;var pCmdText:_tagOLECMDTEXT):HRESULT;stdcall;
+       function Exec(var pguidCmdGroup:GUID;nCmdID:LongWord;nCmdexecopt:LongWord;var pvaIn:OleVariant;var pvaOut:OleVariant):HRESULT;stdcall;
       end;
 
     IContinueCallback = interface(IUnknown)
@@ -3552,6 +3562,11 @@ type
     function GetExtent(dwDrawAspect:dword;lindex:DWord;ptd:pDVTARGETDEVICE;lpsizel:LPSIZEL):HRESULT;stdcall;
     end;
 
+  IObjectWithSite = interface
+    ['{FC4801A3-2BA9-11CF-A229-00AA003D7352}']
+    function SetSite(const pUnkSite: IUnknown):HRESULT; stdcall;
+    function GetSite(const riid: TIID; out Site: IUnknown):HRESULT; stdcall;
+  end;
 
 
 { COMCAT}

+ 2 - 2
packages/winunits-base/src/comobj.pp

@@ -1598,7 +1598,7 @@ HKCR
         else
       //  Function  Invoke(pvInstance: Pointer; memid: MEMBERID; wFlags: WORD; VAR pDispParams: DISPPARAMS; OUT pVarResult: VARIANT; OUT pExcepInfo: EXCEPINFO; OUT puArgErr: UINT):HResult;StdCall;
       //  Result := fTypeInfo.Invoke(IDispatch(Self), DispID, Flags, TDispParams(params), PVariant(VarResult)^, PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);
-          Result := fTypeInfo.Invoke(fInterfacePointer, DispID, Flags, TDispParams(params), PVariant(VarResult)^, PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);
+          Result := fTypeInfo.Invoke(fInterfacePointer, DispID, Flags, TDispParams(params), VarResult, ExcepInfo, ArgErr);
       end;
 
     function TAutoIntfObject.InterfaceSupportsErrorInfo(const riid: TIID): HResult;
@@ -1700,7 +1700,7 @@ HKCR
         begin
           Result := TAutoObjectFactory(Factory).DispTypeInfo.Invoke(Pointer(
             PtrUint(Self) + TAutoObjectFactory(Factory).DispIntfEntry^.IOffset),
-            DispID, Flags, TDispParams(Params), PVariant(VarResult)^, PExcepInfo(ExcepInfo)^, PUINT(ArgErr)^);
+            DispID, Flags, TDispParams(Params), VarResult, ExcepInfo, ArgErr);
         end;
       end;
 

+ 38 - 8
packages/winunits-base/src/typelib.pas

@@ -53,7 +53,7 @@ To load a different type of library resource, append an integer index to 'FileNa
 Example:  C:\WINDOWS\system32\msvbvm60.dll\3
 }
 function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
-  bActiveX,bPackage:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
+  bActiveX,bPackage,bRemoveStructTag:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
 
 
 Type
@@ -66,6 +66,7 @@ Type
     FAppendVersionNumber: Boolean;
     FCreatePackage: Boolean;
     FDependencies: TStringList;
+    FRemoveStructTag: Boolean;
     FUnitSource: TStringList;
     FPackageSource: TStringList;
     FPackageRegUnitSource: TStringList;
@@ -93,6 +94,7 @@ Type
     procedure SetActiveX(AValue: Boolean);
     procedure SetCreatePackage(AValue: Boolean);
     procedure SetOutputFileName(AValue: String);
+    procedure SetRemoveStructTag(AValue: Boolean);
     procedure SetUnitName(AValue: string);
   Protected
     bIsCustomAutomatable,bIsInterface,bIsAutomatable,bIsExternalDecl,bIsUserDefined:boolean;
@@ -116,6 +118,7 @@ Type
     function ValidateIDAgainstDeclared(id: string): boolean; virtual;
     function MakeValidId(id:string;var valid:string): boolean; virtual;
     function MakeValidIdAgainstDeclared(id:string;var valid:string): boolean;
+    function RemoveTag(typename: string): string;
     // The actual routines that do the work.
     procedure CreateCoClasses(const TL: ITypeLib; TICount: Integer); virtual;
     procedure CreateForwards(const TL: ITypeLib; TICount: Integer); virtual;
@@ -145,11 +148,13 @@ Type
     // Append version number to unit name.
     Property AppendVersionNumber : Boolean Read FAppendVersionNumber Write FAppendVersionNumber Default True;
     // Create lpk package for ActiveXContainer descendant: default false
-    Property CreatePackage : Boolean Read FCreatePackage write SetCreatePackage Default False;
+    Property CreatePackage : Boolean read FCreatePackage write SetCreatePackage  Default False;
     // File to read typelib from.
     Property InputFileName : WideString Read FInputFileName Write FInputFileName;
     // If set, unit source will be written to this file.
     Property OutputFileName : String Read FOutputFileName Write SetOutputFileName;
+    // Remove tag from struct names
+    Property RemoveStructTag : Boolean read FRemoveStructTag write SetRemoveStructTag Default False;
     // Set automatically by OutputFileName or by Execute
     Property UnitName : string Read FUnitname Write SetUnitName;
   end;
@@ -161,7 +166,7 @@ Resourcestring
   SErrInvalidUnitName = 'Invalid unit name : %s';
 
 function ImportTypelib(FileName: WideString;var sUnitName:string;var slDependencies:TStringList;
-  bActiveX,bPackage:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
+  bActiveX,bPackage,bRemoveStructTag:boolean;var sPackageSource,sPackageRegUnitSource:String):string;
 var i:integer;
 begin
   With TTypeLibImporter.Create(Nil) do
@@ -169,6 +174,7 @@ begin
       InputFileName:=FileName;
       ActiveX:=bActiveX;
       CreatePackage:=bPackage;
+      RemoveStructTag:=bRemoveStructTag;
       Execute;
       Result:=UnitSource.Text;
       sUnitname:=UnitName;
@@ -301,6 +307,18 @@ begin
     MakeValidIdAgainstDeclared(id+'_',valid);
 end;
 
+function TTypeLibImporter.RemoveTag(typename: string): string;
+begin
+  result:=typename;
+  if FRemoveStructTag and (pos('tag',typename)>0) then
+    if (copy(typename,1,3)='tag') then
+      delete(result,1,3)
+    else if (copy(typename,1,4)='_tag') then
+      delete(result,2,3)
+    else if (copy(typename,1,5)='__tag') then
+      delete(result,3,3);
+end;
+
 
 function TTypeLibImporter.TypeToString(TI:ITypeInfo; TD:TYPEDESC):string;
 
@@ -331,9 +349,11 @@ begin
       TD:=TD.lptdesc^;
     OleCheck(TI.GetRefTypeInfo(TD.hreftype,TIref));
     OleCheck(TIRef.GetDocumentation(DISPID_UNKNOWN, @BstrName, nil, nil, nil));
-    MakeValidId(BstrName,result);
     OleCheck(TIRef.GetTypeAttr(TARef));
     bIsCustomAutomatable:=TARef^.typekind in [TKIND_DISPATCH,TKIND_INTERFACE,TKIND_ENUM,TKIND_COCLASS];
+    if TARef^.typekind in [TKIND_RECORD,TKIND_UNION,TKIND_ALIAS] then
+      BstrName:=RemoveTag(BstrName);
+    MakeValidId(BstrName,result);
     if TARef^.typekind=TKIND_ALIAS then
       begin
       TypeToString(TIRef,TARef^.tdescAlias); //not interested in result, only bIsCustomAutomatable and bIsInterface
@@ -568,7 +588,8 @@ begin
         if not MakeValidId(BstrName,sMethodName) then
           AddToHeader('//  Warning: renamed method ''%s'' in %s to ''%s''',[BstrName,iname,sMethodName],True);
         bIsFunction:=(bIsDispatch and (FD^.elemdescFunc.tdesc.vt<>VT_VOID)) or
-          (not bIsDispatch and (FD^.cParams>0) and ((FD^.lprgelemdescParam[FD^.cParams-1].paramdesc.wParamFlags and PARAMFLAG_FRETVAL ) <>0));
+          (not bIsDispatch and (FD^.cParams>0) and ((FD^.lprgelemdescParam[FD^.cParams-1].paramdesc.wParamFlags and PARAMFLAG_FRETVAL ) <>0)) or
+          (sConv<>'safecall');
         if bIsFunction then
           sFunc:=format('    // %s : %s '#13#10'   function %s(',[sMethodName,BstrDocString,sMethodName])
         else
@@ -682,7 +703,10 @@ begin
           sEventImplementations:=sEventImplementations+';'#13#10;
           end;
         if bIsFunction then
-          sFunc:=sFunc+format(':%s',[sType]);
+          if (sConv<>'safecall') then
+            sFunc:=sFunc+':HRESULT'
+          else
+            sFunc:=sFunc+format(':%s',[sType]);
         if bIsDispatch then
           s:=s+sFunc+format(';dispid %d;'#13#10,[FD^.memid])
         else
@@ -1206,7 +1230,7 @@ begin
     case TIT of
       TKIND_RECORD,TKIND_UNION:
         begin
-        if not MakeValidId(BstrName,sRecordName) then
+        if not MakeValidId(RemoveTag(BstrName),sRecordName) then
           AddToHeader('//  Warning: renamed record ''%s'' to ''%s''',[BstrName,sRecordName],True);
         AddToInterface(' P%s = ^%s;'#13#10,[sRecordName,sRecordName]);
         FTypes.Add('P'+sRecordName);
@@ -1256,7 +1280,7 @@ begin
         stype:=TypeToString(TI, TA^.tdescAlias);
         if bIsUserDefined and not ValidateID(stype) then
           stype:=stype+'_';
-        if not MakeValidId(BstrName,sRecordName) then
+        if not MakeValidId(RemoveTag(BstrName),sRecordName) then
           AddToHeader('//  Warning: renamed alias ''%s'' to ''%s''',[BstrName,sRecordName],True);
         sl:=format(' %s = %s;',[sRecordName,stype]);
         if bIsUserDefined and not bIsExternalDecl and (FTypes.IndexOf(stype)=-1) then //not defined yet, defer
@@ -1806,6 +1830,12 @@ begin
   SetUnitName(UN)
 end;
 
+procedure TTypeLibImporter.SetRemoveStructTag(AValue: Boolean);
+begin
+  if FRemoveStructTag=AValue then Exit;
+  FRemoveStructTag:=AValue;
+end;
+
 procedure TTypeLibImporter.SetUnitName(AValue: string);
 begin
   if FUnitname=AValue then Exit;

+ 5 - 0
rtl/win/sockets.pp

@@ -22,6 +22,11 @@ Interface
      winsock2,ctypes;
 
 Type
+  // the common socket functions are defined as size_t.
+  // without defining them for Windows this way, the 
+  // sockets unit is not crossplatform. This is not a mistake
+  // wrt 64-bit, the types are "INT" in the headers.
+  // Mantis #22834
   size_t  = cuint32;
   ssize_t = cint32;
   tsocklen= cint;

+ 5 - 3
utils/importtl/importtl.pas

@@ -11,7 +11,7 @@ var
   F:text;
   slDep:TStringList;
   i:integer;
-  bNoRecurse,bHelp,bActiveX,bPackage:boolean;
+  bNoRecurse,bHelp,bActiveX,bPackage,bRemoveStructTag:boolean;
 begin
   slDep:=TStringList.Create;
   bNoRecurse:=false;
@@ -25,6 +25,7 @@ begin
     else if pos('-a',ParamStr(i))>0 then bActiveX:=true
     else if pos('-h',ParamStr(i))>0 then bHelp:=true
     else if pos('-p',ParamStr(i))>0 then bPackage:=true
+    else if pos('-t',ParamStr(i))>0 then bRemoveStructTag:=true
     else if pos('-d',ParamStr(i))>0 then
       begin
       sOutDir:=trim(copy(ParamStr(i), pos('-d',ParamStr(i))+2, 260));  // windows MAX_PATH
@@ -53,16 +54,17 @@ begin
     writeln('  -h    : displays this text.');
     writeln('  -a    : create ActiveXContainer descendants');
     writeln('  -d dir: set output directory. Default: current directory.');
-    writeln('  -n    : do not recurse typelibs. Default: create bindingss for all');
+    writeln('  -n    : do not recurse typelibs. Default: create bindings for all');
     writeln('          dependencies.');
     writeln('  -p    : create lazarus package for ActiveXContainer descendants');
+    writeln('  -t    : remove "tag" prefix from structs');
     exit;
     end;
   slDep.Add(paramstr(Paramcount));
   i:=0;
   repeat
     writeln('Reading typelib from '+slDep[i]+ ' ...');
-    sTL:=ImportTypelib(slDep[i],unitname,slDep,bActiveX,bPackage,sPackageSource,sPackageRegUnitSource);
+    sTL:=ImportTypelib(slDep[i],unitname,slDep,bActiveX,bPackage,bRemoveStructTag,sPackageSource,sPackageRegUnitSource);
     unitname:=sOutDir+unitname;
     if (bPackage) and (sPackageSource<>'') then
       begin