NO

Author Topic: FTypeLib OLE/COM plain 'C' header generator  (Read 5331 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
FTypeLib OLE/COM plain 'C' header generator
« on: May 03, 2013, 12:49:51 am »
Sometime ago Timovjl asked me if could be a good idea to concentrate some development efforts on OLE/COM technologies. Following this Idea I wrote this software.
This program scans type libraries and produce a 'C' header that can then be used to write programs with OLE/COM functionalities under plain 'C'.
This allows to use any control or COM object even when you don't have the IDL descriptor (and don't want to fight with MS bloated headers).
Of course to use an object you must know what it does and you must know the OLE/COM object programming. To learn about OLE/COM I suggest to read the excellent articles from Jeff Glatt on codeproject.com.
This is an alpha release with some known limitations:
1. The program don't looks for definition order, some type definitions can follow their usage. In this case you have to manually reorder the record or unions definition.
2. Actually stub and proxies are not emitted.
The stubs and proxies are functions that are directly available from COM DLL's and are callable without using lpvtbl's.
Of course there will be some other bugs that I've not discovered yet. I'll be glad if you would report them.
In the thread you will also find the sample 'SimpleWebPage' that use the headers generated with FTypeLib.
'SimpleWebPage' is a demo from Jeff Glatt adapted and revised. You will find in the comments some notes about the use of FTypeLib.

05/04/2013 New Release V0.5.9.0a

05/12/2013 New Release V0.6.9.1a:
  • Completely rewrote the function generation. The previous one was very buggy.
  • Fixed Interface generation for bugs, and fixed the GUID generation
  • Added structures predefinitions to reduce manual adjustments on generated headers
  • The sample use *only* FtypeLib generated headers
  • This code is original and doesn't resemble anymore any previous work (too much bugs there)

03/08/2015 New Release V0.7.0.1a
   Fixed 2 major bugs:
  • In not dual interfaces methods inherited from interfaces other than IDispatch and IUnknown were dropped. Now all inherited methods are correctly added.
  • The property get methods don't used pointers. Corrected.

03/08/2015 New Release V0.7.0.2a
   Fixed a major bug (thanks to Timo):
  • The LRH (Last Right Hand Method) was not correctly handed when interface class had inherited members. Fixed.

03/09/2015 New Release V0.7.0.4a
   Fixed some minor bugs and added functionalities:
  • Now you can select if to emit documented or undocumented code, using Settings menu.

03/13/2015 New Release V0.8.0.0a
   Fixed some minor bugs and added functionalities:
  • 32 and 64 bits versions
  • Addin for PellesC IDE to replace old and limited TypeLib addin
  • Better GUI
  • Generated code now is \n separated for correct file encoding (removed dangling \r in header files).
  • The result from generation is a standard malloced memory that user can free with free() without using dynamic strings functions.
  • Dynamic strings library tuned for faster code
P.S. The sample is reposted below.
« Last Edit: March 13, 2015, 05:07:54 pm by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1891
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #1 on: May 03, 2013, 05:52:31 am »
Nice work frankie!

Maybe better using this:
Code: [Select]
HRESULT hRes = LoadTypeLibEx(globals.wszFileName, REGKIND_NONE, &hTypeLib);
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #2 on: May 03, 2013, 12:18:43 pm »
Thanks Timo.  :)
Yes you are right. Without registration process the scanning could be a little bit faster and guarantee against registry modifications.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1891
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #3 on: May 03, 2013, 02:56:43 pm »
COM functions should always return HRESULT ??
Examples:
MSScript.ocx
-    VOID (*put_Language)(IScriptControl *This, BSTR Language);
+   HRESULT (*put_Language)(IScriptControl *This, BSTR Language);

-    VARIANT (*Eval)(IScriptControl *This, BSTR Expression);
+   HRESULT (*Eval)(IScriptControl *This, BSTR Expression, VARIANT*);
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #4 on: May 03, 2013, 04:58:14 pm »
Thanks Timo.
I'll look again the proto generation for put properties and the handling of 'retval'.
I'll be back with a new version.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #5 on: May 04, 2013, 09:30:04 pm »
Above you'll find the new release V0.5.9.0a
I fixed almost all reported issues (I hope).
As a new feature now the header comments are doxygen compliant. So you can run doxygen and create documentation.
Please test it and report problems found.

For a next release I would add a feature that builds a 'C' file with skeleton of an interface. A list will show all available interfaces to selected the one for wich to build the skeleton.
« Last Edit: May 05, 2013, 01:04:47 pm by frankie »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #6 on: May 12, 2013, 06:55:26 pm »
Above you'll find a new release V0.6.9.1a of FTypeLib.
Timo about your former comments you will find the answers in the code comments.
Everybody please help to debug.
« Last Edit: May 13, 2013, 10:39:30 am by frankie »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #7 on: March 08, 2015, 01:54:04 am »
New version.
Fixed 2 major bugs.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #8 on: March 08, 2015, 05:33:35 pm »
 V0.7.0.2a 7.Fixed LRH handling.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #9 on: March 09, 2015, 04:38:56 pm »
 V0.7.0.4a  - Produce documented or undocumented header.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1757
Re: FTypeLib OLE/COM plain 'C' header generator
« Reply #10 on: March 13, 2015, 05:20:59 pm »
03/13/2015 New Release V0.8.0.0a
   Fixed some minor bugs and added functionalities:
  • 32 and 64 bits versions
  • Addin for PellesC IDE to replace old and limited TypeLib addin
  • Better GUI
  • Generated code now is \n separated for correct file encoding (removed dangling \r in header files).
  • The result from generation is a standard malloced memory that user can free with free() without using dynamic strings functions.
  • Dynamic strings library tuned for faster code
The sample has been moved here for space reasons.