سؤال

I'm using a Microsoft Text Object Model type library in Delphi for using some features of the Microsoft RichEdit control. That type library was included in a freeware component and worked very well over the years. For example, here is an ITextDocument interface that it shows:

  ITextDocument = interface(IDispatch)
    ['{8CC497C0-A1DF-11CE-8098-00AA0047BE5D}']
    function Get_Name: WideString; safecall;
    function Get_Selection: ITextSelection; safecall;
    function Get_StoryCount: Integer; safecall;
  ...

I don't know how that was created. Now I want to update it for new interfaces published for RichEdit in Windows 8 (MSFTEDIT.DLL). For example, there is a Range2 method in ITextDocument2 and a new ITextRange2 interface according to MSDN. Is there some way I can use Delphi's Import Type Library feature to make up the definitions of the new interfaces?

Update: I figured out how to generate that unit. In Delphi, click on Import Component and then select "tom" from the registered services. This creates a unit exactly like that. Now the problem is, in order to get the new "tom" interface from Windows 8, it will be too much if I'm required to install Delphi on it. There must be a simpler way. Somehow I have to generate a TLIB on Win 8 and then import it in my Delphi on Windows 7. Anyone knows how to generate a TLIB on Windows 8 for that msftedit.dll or tom interface?

Another find: If I open the msftedit.dll in Delphi by opening as a tlib, it shows all the interfaces. There is an export button too but that does not work when clicked. Nothing happens. I searched for Type Lib Explorer help in the help file and on the web but didn't find anything on why that export button does not work.

هل كانت مفيدة؟

المحلول

You can use the command line utility tlibimp to import the type library on Windows 8. You can find tlibimp.exe in the bin directory of your Delphi installation. Since you want to avoid installing Delphi on your Windows 8 machine, transfer tlibimp.exe to the Windows 8 machine. And then run this command:

tlibimp -P msftedit.dll

This will generate the Pascal type library import file that you need.

نصائح أخرى

I had the same problem with SAPI in Windows 7 x86 and Delphi 7. The SAPI api in 32 bits architecture is the sapi.dll. This DLL is not found on path by tlibimp.exe:

D:\Temp\Merda>tlibimp -P  sapi.dll
Embarcadero TLIBIMP Version 12.16580
Copyright(c) 1995-2010 Embarcadero Technologies, Inc.

Opening  sapi.dll
Error loading type library sapi.dl

I found it using Microsoft OLE/COM Object Viewer. Works like a charm:

D:\Temp>tlibimp -P c:\Windows\System32\Speech\Common\sapi.dll
Embarcadero TLIBIMP Version 12.16580
Copyright(c) 1995-2010 Embarcadero Technologies, Inc.

Opening  c:\Windows\System32\Speech\Common\sapi.dll
Type library loaded ....
Created  D:\Temp\SpeechLib_TLB.dcr
Created  D:\Temp\SpeechLib_TLB.pas

Running tlibimp.exe only works with .net 3.5 using the ".dll"... If you create a ".tlb" of a .net 4.N ".dll", tlibimp.exe will then works fine with the commands below.

"C:\windows\Microsoft.NET\Framework\...\RegAsm.exe" My.Com.dll /tlb

"C:\Program Files (x86)\Borland\...\Bin\tlibimp.exe" My.Com.tlb

This way you don't get the message "Error loading type library".

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top