Let's make a little tool that will bring up a browser dialog that lists some commonly used User32 and Kernel32 functions and procedures, and inserts the appropriate Declare statements for 32 and/or 64-bit. There should be a small description for each function, and a small preview box showing the code to be inserted.
When 64-bit is selected, declare statement should use the PtrSafe keyword, and when both 32 and 64 bit are selected, code should include an #If directive to conditionally compile the declaration.
The helper should allow inserting multiple declarations at once, and place the multiple x64 declarations inside a single #If directive.
Does this feature need to work in conjunction with SmartIndenter, so that compiler directives and declare statements are indented and line-continued _upon insertion_?
Would also be great if this helper could create the required Types for function structs, and enums for function parameters.
@ThunderFrame I wouldn't make it _depend_ on the indenter; the code could easily be inserted "pre-formatted" - running the indenter would then make it conform to whatever options the user configured it for.
And yeah, it should create the needed types on the fly if they don't already exist in the active project.
Might be good to put the definitions into XML format. That would allow us to filter/find functions suitable for the platform, apply category tags, define dependencies.
It would also allow obscure MS APIs and 3rd party APIs to be added to the project, or by end users.
:+1: I like that, very very much!
Sent from my Toaster
might also be nice to build classes and callbacks for functions that require them. Eg. CopyFileEx and CopyFile2ProgressRoutine
and finally (this might be a separate issue)...
Encapsulate, by library, the RegisteredFunctions under Excel, so you can call a function with Intellisense, instead of Application.Run(...)
I had a look at how the PInvoke VS extension gets function declarations. The extenaion gets the full declaration (in both VB.Net and C#) in an XML SOAP request.
Being a full declaration, it doesn't break the arguments, types and return types down into XML nodes.
But the XML schema could be enhanced to handle that.
:+1:
This probably isn't capturing enough detail, and the schema could probably be tweaked, but this is what I'm thinking...
<?xml version="1.0" encoding="UTF-8"?>
<signatures>
<types>
<struct name="RECT">
<member ordinal="0" name="Left" type="Long" />
<member ordinal="1" name="Top" type="Long" />
<member ordinal="2" name="Right" type="Long" />
<member ordinal="3" name="Bottom" type="Long" />
</struct>
<types>
<functions>
<function library="user32" name="GetWindowRect" Win64="1" Win32="1" WinMin="5" WinMax="-1" tags="window,rectangle" Unicode="-1" ANSI="-1">
<argument ordinal="0" name="hWnd" direction="in" type="Long" />
<argument ordinal="1" name="lpRect" direction="out" type="struct.RECT" />
<return type="Boolean" />
</function>
</functions>
</signatures>
Hi guys,
I'm not sure if this is helpful since @ThunderFrame might have a way to implement PInvoke's VS extension method already, but I requested a copy of a sqlite database from Dennis Wallentin via Ron de Bruin's website who compiled the api declarations for vba some time ago. It's also not very granular but a fair amount of work has been done and it looks to be high quality after some perusal of tricky cases.
I was going to use this personally. I don't know if this would be overkill for rd but my thought was to store the declarations in an external repository, scan my projects (or a helper class) for api calls just in time for compilation, and then write the found api references to a public module in my project using the proper conditional compilation constants for supporting 32bit, 64bit, vba7 etc.
Either way, here is the database attached:
win32 declarations vba.zip
Hey @coramuirgen! Thank you very much for the leg work! The team appreciates it.
Dennis, who contributed the db, is really interested to hear about rd and wants to "spread the word"/write a review about it when v2 is out. He occasionally writes pieces for Daily Dose of Excel. I'll let him know, and his address is Dennis Wallentin [email protected].
out of scope. a plugin for this isn't out of question though
Most helpful comment
Hi guys,
I'm not sure if this is helpful since @ThunderFrame might have a way to implement PInvoke's VS extension method already, but I requested a copy of a sqlite database from Dennis Wallentin via Ron de Bruin's website who compiled the api declarations for vba some time ago. It's also not very granular but a fair amount of work has been done and it looks to be high quality after some perusal of tricky cases.
I was going to use this personally. I don't know if this would be overkill for rd but my thought was to store the declarations in an external repository, scan my projects (or a helper class) for api calls just in time for compilation, and then write the found api references to a public module in my project using the proper conditional compilation constants for supporting 32bit, 64bit, vba7 etc.
Either way, here is the database attached:
win32 declarations vba.zip