Am 26.05.20 um 16:17 schrieb Vinod K Chandran: > On Tuesday, 26 May 2020 at 13:48:52 UTC, ag0aep6g wrote: >> On 26.05.20 15:43, Vinod K Chandran wrote: >>> So far now, two solutions are very clear for this problem. >>> 1. As per John Chapman's suggestion - use >>> cast(DWORD_PTR)cast(void*)this). >>> 2. Use another varibale to use as an lvalue. - >>> Button dummyBtn = this; >>> cast(DWORD_PTR)&dummyBtn; >>> Among these two, i think 2nd option is good. Am i right ? >> >> No. Use option 1. > > Could you please tell me why ? With option 2, you will not actually get a pointer to the object but a pointer to the local variable which is a reference to the object. `this` and the local variable both are references to the object, so internally they already are pointers. Their usage is just restricted in regular D code. This is also why simply casting it to a pointer works. You need to cast to void* in between because that's just the way to tell the compiler to ignore the restrictions you usually have for references.
Re: How to get the pointer of "this" ?
Johannes Loher via Digitalmars-d-learn Tue, 26 May 2020 07:25:52 -0700
- Re: How to get the point... Mike Parker via Digitalmars-d-learn
- Re: How to get the p... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get t... bauss via Digitalmars-d-learn
- Re: How to ... Vinod K Chandran via Digitalmars-d-learn
- Re: How to ... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get the point... John Chapman via Digitalmars-d-learn
- Re: How to get the p... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get t... Vinod K Chandran via Digitalmars-d-learn
- Re: How to ... ag0aep6g via Digitalmars-d-learn
- Re: How... Vinod K Chandran via Digitalmars-d-learn
- Re: How... Johannes Loher via Digitalmars-d-learn
- Re: How to get t... John Chapman via Digitalmars-d-learn
- Re: How to get the pointer of &qu... welkam via Digitalmars-d-learn
- Re: How to get the pointer o... Adam D. Ruppe via Digitalmars-d-learn
- Re: How to get the point... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get the p... Adam D. Ruppe via Digitalmars-d-learn
- Re: How to get the pointer o... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get the point... Adam D. Ruppe via Digitalmars-d-learn
- Re: How to get the p... Vinod K Chandran via Digitalmars-d-learn
- Re: How to get t... Adam D. Ruppe via Digitalmars-d-learn
- Re: How to ... Vinod K Chandran via Digitalmars-d-learn