Re: How to get the pointer of "this" ?

2020-05-27 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 22:23:19 UTC, bauss wrote: On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: [...] You can just do this to get around it: auto button = this; log(); True, somebody else posted the same idea already. But as explained, it doesn't do

Re: How to get the pointer of "this" ?

2020-05-26 Thread bauss via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: On Tuesday, 26 May 2020 at 11:44:58 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 14:42:04 UTC, Steven Schveighoffer wrote: On Tuesday, 26 May 2020 at 14:42:04 UTC, Steven Schveighoffer wrote: Hm... According to run.dlang.io, this behavior changed in 2.072 (prior to that it worked). In 2.067.1 to 2.071.2, changing the this reference was

Re: How to get the pointer of "this" ?

2020-05-26 Thread John Chapman via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 13:37:22 UTC, Vinod K Chandran wrote: On Tuesday, 26 May 2020 at 12:41:20 UTC, John Chapman wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to:

Re: How to get the pointer of "this" ?

2020-05-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/26/20 8:08 AM, Johannes Loher wrote: On Tuesday, 26 May 2020 at 11:44:58 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a

Re: How to get the pointer of "this" ?

2020-05-26 Thread Johannes Loher via Digitalmars-d-learn
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).

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
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

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 13:44:24 UTC, Adam D. Ruppe wrote: On Tuesday, 26 May 2020 at 11:35:23 UTC, Vinod K Chandran wrote: Okay, but uint is working perfectly. It won't if you use -m64. Okay. I got it.

Re: How to get the pointer of "this" ?

2020-05-26 Thread ag0aep6g via Digitalmars-d-learn
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) Among these two, i

Re: How to get the pointer of "this" ?

2020-05-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 11:35:23 UTC, Vinod K Chandran wrote: Okay, but uint is working perfectly. It won't if you use -m64.

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 13:37:22 UTC, Vinod K Chandran wrote: On Tuesday, 26 May 2020 at 12:41:20 UTC, John Chapman wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to:

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: On Tuesday, 26 May 2020 at 11:44:58 UTC, Vinod K Chandran wrote: [...] [...] It doesn't compile, the line string mt [...] Hi, Sorry for the typos in my code.

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 12:41:20 UTC, John Chapman wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to: SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID),

Re: How to get the pointer of "this" ?

2020-05-26 Thread John Chapman via Digitalmars-d-learn
On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to: SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR)cast(void*)this); That is, change `` to

Re: How to get the pointer of "this" ?

2020-05-26 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: [...] Small correction: I said that this is an lvalue and that you cannot take the address of lvalues. Of course that is incorrect, I meant to say that rvalues (this is an rvalue and you cannot take the address of rvalues).

Re: How to get the pointer of "this" ?

2020-05-26 Thread Johannes Loher via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 11:44:58 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 18:42:33 UTC, bauss wrote: On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line

Re: How to get the pointer of "this" ?

2020-05-26 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:54:32 UTC, Adam D. Ruppe wrote: On Monday, 25 May 2020 at 22:31:00 UTC, Vinod K Chandran wrote: A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck. A DWORD_PTR is *not* the same as a uint. It is more like a

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:32:52 UTC, Vinod K Chandran wrote: What is an opCast ? operator overload of the cast function. if you didn't write one, you don't have to worry about this.

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:31:00 UTC, Vinod K Chandran wrote: A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck. A DWORD_PTR is *not* the same as a uint. It is more like a size_t or void* depending on context.

Re: How to get the pointer of "this" ?

2020-05-25 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:04:28 UTC, Adam D. Ruppe wrote: On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function

Re: How to get the pointer of "this" ?

2020-05-25 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: cast(DWORD_PTR) this); Where is DWORD_PTR defined? I cant find it in docs. If its an alias of long then you have to cast to a pointer like this cast(long*) this; you need to

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function but without opCast it should just work

Re: How to get the pointer of "this" ?

2020-05-25 Thread welkam via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: cast(DWORD_PTR) this); Where is DWORD_PTR defined? I cant find it in docs. If its an alias of long then you have to cast to a pointer like this cast(long*) this; you need to specify that you want to cast to a pointer of type T.

Re: How to get the pointer of "this" ?

2020-05-25 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 18:42:33 UTC, bauss wrote: On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line

Re: How to get the pointer of "this" ?

2020-05-25 Thread bauss via Digitalmars-d-learn
On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: [...] The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in

Re: How to get the pointer of "this" ?

2020-05-25 Thread John Burton via Digitalmars-d-learn
On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer

Re: How to get the pointer of "this" ?

2020-05-25 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: [...] The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference like an

Re: How to get the pointer of "this" ?

2020-05-25 Thread Mike Parker via Digitalmars-d-learn
On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference

Re: How to get the pointer of "this" ?

2020-05-25 Thread Mike Parker via Digitalmars-d-learn
On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer under the hood. Getting its address will result in a pointer

Re: How to get the pointer of "this" ?

2020-05-25 Thread Vinod K Chandran via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:40:10 UTC, bauss wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: [...] I think your issue might be elsewhere because casting this should be fine and it should not complain about that in your given code. At least you should be able to

Re: How to get the pointer of "this" ?

2020-05-25 Thread John Burton via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:40:10 UTC, bauss wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: [...] I think your issue might be elsewhere because casting this should be fine and it should not complain about that in your given code. At least you should be able to

Re: How to get the pointer of "this" ?

2020-05-24 Thread bauss via Digitalmars-d-learn
On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: Hi all, I have a class like this. class Button : Control { ... HWND createButton(){ ... SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR) this); } } But

How to get the pointer of "this" ?

2020-05-24 Thread Vinod K Chandran via Digitalmars-d-learn
Hi all, I have a class like this. class Button : Control { ... HWND createButton(){ ... SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR) this); } } But compiler says that - "Error: 'this' is not an lvalue and cannot