waitingsong / node-win32-api

win32 api
MIT License
430 stars 55 forks source link

awsome! universal support possible? #11

Open Dogan1938 opened 5 years ago

Dogan1938 commented 5 years ago

Can you make it generic so that any dll can be used?

there is a software called dependencywalker, i am assume you made use of some similar principle to get the functions of the dll's, but if it can be made universal to get all functions of any dll and make them usable via intellisense it would save you adding the dll's manually i guess.

just an idea, don't know if it is possible or too much work :smile:

sancarn commented 4 years ago

I'm fairly certain, that with dependency walker (or even walking through a dll in general) you can only get the function names, and not the named parameters and parameter types.

Quote from dependency walker page:

For most functions, this information is simply not present in the module. The Windows' module file format only provides a single text string to identify each function. There is no structured way to list the number of parameters, the parameter types, or the return type. However, some languages do something called function "decoration" or "mangling", which is the process of encoding information into the text string. For example, a function like int Foo(int, int) encoded with simple decoration might be exported as _Foo@8. The 8 refers to the number of bytes used by the parameters. If C++ decoration is used, the function would be exported as: ?Foo@@YGHHH@Z , which can be directly decoded back to the function's original prototype:  int Foo(int, int) . Dependency Walker supports C++ undecoration by using the Undecorate C++ Functions Command.

The Win32 APIs aren't decorated. If one wanted to automate the definition of FFI calls the best way would be data driven via MSDN (though mind even these are sparsely documented) or an open source documentation site like pinvoke.

It could also in theory be built off of source code from windows compatible systems or off of wine entries (which could either be extracted via HTTP request or directly if possible...).


Edit: to be honest, wine source code is probably the best place to start:

User32 Wine Spec. User32 Wine Src