Win32::API is a Foreign function interface module. It contains a OO C Struct parser module called Win32::API::Struct. There is a bug in it. The bug is that, in a parent (or any) struct, you can't have a pointer to another Win32::API::Struct struct as a member of the parent (or any) struct. If the root struct contains a child Win32::API::Struct, the child struct is placed normally as in C inline in memory in the root struct. So my question is, what should the API design be to specify a child member that is a pointer to a struct?

I have 5 ideas at the moment

Win32::API::Struct::typedef is way to define a new struct type to Win32::API::Struct, it does not create a blessed instance of the struct
=item C<typedef NAME, TYPE, MEMBER, TYPE, MEMBER, ...> idea 1: typedef(POINTERNAME, EXISTING_TYPE) or typedef(NAME, TYPE, MEMBER, TYPE, MEMBER, ...) #legacy proto with die "usage Win32::API::Struct->typedef( NAME, [NON_POINTER_STRUCT_NAME +] | [TYPE, MEMBER, TYPE, MEMBER, ...])" if scalar(@_) % 2 == 1 && scalar +(@_) != 3; #or approx that, didn't run it

an odd @_ is broken usage currently (class name makes valid @_ be even, "@_ = ($ignoredclass, $typename, $membertype, $membername)"), if @_ is odd and @_ has 3 slices, instead of broken usage, have that be pointer typedef mode

idea 2:
::Struct::typedef unchanged ::Struct::make_pointer($name, $existing_struct); # named after an exis +ting private api sub in Win32::API (is_pointer) #or decl_pointer instead of make_pointer? #someone might think make_pointer returns an IV to the packed struct i +nstance.
idea 3:
::Struct::typedef unchanged $ret_bool = Win32::API::Struct::is_pointer($name [, $set_bool]) #name +after private api in Win32::API::Type, proto is different though

permanently converts struct $name to a struct pointer, user should probably have $name begin with LP or P for user's sanity but not enforced, you must call typedef again and recreate the struct from the member elements all over again under a new name if you want the non-pointer version after calling is_pointer

idea 4:

add * detection to Win32::API::Type::typedef so "Win32::API::Type->typedef('LPMY_STRUCT', 'MY_STRUCT *');" works

idea 5:

expose as public api of Win32::API::Struct getting the pointer suitable for passing to a UINT_PTR/void * param (really the struct * param in C), from a Win32::API::Struct object instance. Document it in the POD how to get raw pointer from a Win32::API::Struct object instance. This is easiest solution. Its still not possible to create a struct with a literal struct * member, idea 5 is just a permanent documented workaround.

quasi idea 6:

change ::Type::typedef to have 3 parameters, 3rd param signals struct pointer creation mode

I dont like it.

not an idea:
No extending the "LP" detection. Many late 2000s added to Platform SDK MS structs only come in P variants, not LP. Something like
typedef struct pvalueW { // Provider supplied value/context. LPWSTR pv_valuename; // The value name pointer int pv_valuelen; LPVOID pv_value_context; DWORD pv_type; }PVALUEW, FAR *PPVALUEW;
would be a problem if struct detection on letter P alone. Expecting the user to play with the C prototypes/declarations in a workaround because letter P prefix to the struct name doesn't trigger struct * pointer I think negates the purpose of Win32::API::Struct.

original module author's idea:
fix the LP prefix detection, that is the only struct pointer member API, I dont agree with it because of my previous paragraph

This is post is derived from rt://78081.


In reply to RFC Win32::API's API by bulk88

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.