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:idea 3:::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.
::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.
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.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;
This is post is derived from rt://78081.
In reply to RFC Win32::API's API by bulk88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |