https://github.com/fafalone/tbShellLib/blob/93346dece996ba12da8526ad21a923bdb95cc00f/Export/Sources/slTypelib.twin#L33
This should return LongPtr I believe (it is PVOID)
Also I wonder how you would feel about 2 (or 3) improvements to make this more idiomatic:
https://github.com/fafalone/tbShellLib/blob/93346dece996ba12da8526ad21a923bdb95cc00f/Export/Sources/slTypelib.twin#L30
In my code, I have declared this as
Sub GetDocumentation(ByVal memid As MEMID, Optional ByRef pBstrName As String, Optional ByRef pBstrDocString As String = vbNullString, Optional ByRef pdwHelpContext As Long, Optional ByRef pBstrHelpFile As String)
with 2 changes: The Optional arguments, since these are optional from the API point of view. You can specify default of =vbNullString and =NULL_PTR or =0 if needed
Second change is I do
Public Enum MEMID
[_]
End Enum
This does a sort of typedef for DWORD types which improves readability IMO
3rd change is I rename parameters to for example
Sub GetDocumentation(ByVal memid As MEMID, Optional ByRef outName As String, ...)
Since ByRef pBstrName to me is
- Too much information; I don't need to know about Bstr as a VBA developer, just String
ByRef and p both mean kinda the same thing, doubling up makes me expect to get a pointer to a string out, not just a string
- I think the
outParam prefix is good from a VBA consumer point of view to make it clear. Attributes may be better in future tB.
I think this may be a harder sell as it is backwards incompatible for your library interface. However in my experience when I declare the APIs this way it makes me much less likely to need to look at the MSDN documentation. But it's still easy to look up online even if I've renamed the params, the function name is the same and the order of params is the same. Maybe for version 3.x of your package.
https://github.com/fafalone/tbShellLib/blob/93346dece996ba12da8526ad21a923bdb95cc00f/Export/Sources/slTypelib.twin#L33
This should return LongPtr I believe (it is PVOID)
Also I wonder how you would feel about 2 (or 3) improvements to make this more idiomatic:
https://github.com/fafalone/tbShellLib/blob/93346dece996ba12da8526ad21a923bdb95cc00f/Export/Sources/slTypelib.twin#L30
In my code, I have declared this as
with 2 changes: The Optional arguments, since these are optional from the API point of view. You can specify default of
=vbNullStringand=NULL_PTRor=0if neededSecond change is I do
This does a sort of typedef for DWORD types which improves readability IMO
3rd change is I rename parameters to for example
Since
ByRef pBstrNameto me isByRefandpboth mean kinda the same thing, doubling up makes me expect to get a pointer to a string out, not just a stringoutParamprefix is good from a VBA consumer point of view to make it clear. Attributes may be better in future tB.I think this may be a harder sell as it is backwards incompatible for your library interface. However in my experience when I declare the APIs this way it makes me much less likely to need to look at the MSDN documentation. But it's still easy to look up online even if I've renamed the params, the function name is the same and the order of params is the same. Maybe for version 3.x of your package.