Как создаются C "spec" файлы, подобные этому? - PullRequest
2 голосов
/ 04 декабря 2011

Как мне создать foo.spec файлы типа этот из заголовочного файла C?

т.е. Я ищу автоматический способ преобразования всех объявлений файла заголовка в нечто простое, например:

stdcall CreateFileW(wstr long long ptr long long long)

, который я могу легко использовать для выполнения операций позже. Я понимаю, что это может быть невозможно для некоторых типов, но это должно быть возможно в большом количестве случаев.

Как мне это сделать?

1 Ответ

1 голос
/ 04 декабря 2011

Хорошо, в винном проекте, вероятно, используется инструмент: http://www.winehq.org/docs/winedump

Введение:

winedump - это инструмент Wine, который призван помочь:

   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

Режим генерации спецификаций:

Режим спецификаций:

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

....

Вывод файлов в режиме спецификации для 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.

Итак, winedump выведет интерфейс DLL в файл SPEC.Файл Spec может быть дополнительно отредактирован вручную.

И спецификация описывает реальный интерфейс DLL, а не интерфейс языка высокого уровня (как он закодирован в заголовках .h).Таким образом, вы можете скомпилировать свой код (.h и .c и, возможно, что-то вроде .def для исправления номеров функций DLL) на win32 в DLL как обычно, а затем вывести спецификацию из DLL.

...