2

How do I create foo.spec files like this one from a C header file?

i.e. I'm looking for an automated way to convert all of a header file's declarations into something simple like:

stdcall CreateFileW(wstr long long ptr long long long)

which I can easily use to perform operations later. I realize it might not be possible for some types, but it should be possible in a large number of cases.

How do I do this?

osgx
  • 90,338
  • 53
  • 357
  • 513
user541686
  • 205,094
  • 128
  • 528
  • 886
  • You can write a declaration parser. If you don't handle struct/union/enum and do minimal validation, you're looking at around 600 lines of C code. Not too bad. Or maybe if the compiler can generate something, you could use that. – Alexey Frunze Dec 03 '11 at 23:26
  • Alex, do you think that [example file](http://source.winehq.org/source/dlls/kernel32/kernel32.spec) was written by hand? – osgx Dec 03 '11 at 23:34
  • @osgx: Possible, but I don't believe so because it'll have to be maintained (that is, redone). Why? – Alexey Frunze Dec 04 '11 at 02:58
  • The spec is text dump of DLL exports, not of headers (there should be no headers of kernel32 outside MS/goverment). If your task to simulate DLL interface, use winedump; if your task to work with list of functions defined in project, use `ctags` or `cscope`. – osgx Dec 04 '11 at 04:28
  • @osgx: Right. But the question was about source code, not binaries. – Alexey Frunze Dec 04 '11 at 05:05
  • source code of what (code of some DLL library? any code)? spec is not for new code; it is only for dumping interface of DLLs. Does Mehrdad want to generate `.so` for wine or to parse and work with list of functions? Also, the question is titled "how spec files created" - they created from existing DLL using windump (and can be manually edited to update or add something). – osgx Dec 04 '11 at 05:24

1 Answers1

1

Ok, there is the tool likely used in wine project: http://www.winehq.org/docs/winedump

Intro:

winedump is a Wine tool which aims to help:

   A: Reimplementing a Win32 DLL for use within Wine, or
   B: Compiling a Win32 application with Winelib that uses x86 DLLs
  For both tasks in order to be able to link to the Win functions some
  glue code is needed.  This 'glue' comes in the form of a .spec file.
  The .spec file, along with some dummy code, is used to create a
  Wine .so corresponding to the Windows DLL.  The winebuild program
  can then resolve calls made to DLL functions.

  Creating a .spec file is a labour intensive task during which it is
  easy to make a mistake. The idea of winedump is to automate this task
  and create the majority of the support code needed for your DLL. In
  addition you can have winedump create code to help you re-implement a
  DLL

Spec generation mode:

Spec mode:

  <dll>  Use dll for input file and generate implementation code.

....

Files output in spec mode for foo.dll:

  foo.spec

         This is the .spec file.

  foo_dll.h
  foo_main.c

         These are the source code files containing the minimum set
         of code to build a stub DLL. The C file contains one
         function, FOO_Init, which does nothing (but must be
         present).

  Makefile.in

         This is a template for 'configure' to produce a makefile. It
         is designed for a DLL that will be inserted into the Wine
         source tree.

So, winedump will dump DLL interface to SPEC file. The Spec file can be additionaly edited by hand.

And the spec describes real DLL interface, not a high-level language interface (like it is encoded in .h headers). So, you can compile your code (.h and .c and maybe something like .def to fix DLL function numbers) on win32 to DLL as usual and then dump the spec from DLL.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • 1
    Ahhh that seems to be what I need -- I just gave it a source code and a DLL and it created the specs for me. Thanks a lot! – user541686 Dec 04 '11 at 08:03