May 25, 2020
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. In this case T is long.
May 25, 2020
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
May 25, 2020
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 specify that you want to cast to a pointer of type T. In this case T is long.

Hi,
Thanks for the reply. Well, DWORD_PTR is a win32 data type. It is defined in the file windows.h.  A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck.
May 25, 2020
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 but without opCast it should just work

Hi,
What is an opCast ?
May 25, 2020
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.
May 25, 2020
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.
May 26, 2020
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 size_t or void* depending on context.

Okay, but uint is working perfectly.
May 26, 2020
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 number where the error showing is the one with the "SetWindowSubclass" function.  In pastebin, the line number is 124.
>
> Need to see the Control  class too.
>
> I think the problem might be something you're referencing from there but need to be sure.

Here is some code to reproduce the error in your system.
https://pastebin.com/rgN3ug1e
'this' is not an lvalue.
May 26, 2020
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 &this might be what you need?
>
> No. A class reference is a pointer under the hood. Getting its address will result in a pointer to the reference variable itself, not to the class instance. When passing a reference to a C API, casting it directly to the C type is correct.

Try this code. This will reproduce the same error.
import std.stdio : log = writeln;
void main() {
     log("Let's check whether 'this' is an lvalue or not.");
     Button btn = new Button("A button");
}

class Button {
    this(string btntext)    {
        mtext = btntext;
        log("button created with the name , ", btntext);
        log(&this);
    }
    private:
    string mt
}
May 26, 2020
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 &this might be what you need?
>>
>> No. A class reference is a pointer under the hood. Getting its address will result in a pointer to the reference variable itself, not to the class instance. When passing a reference to a C API, casting it directly to the C type is correct.
>
> Try this code. This will reproduce the same error.
> import std.stdio : log = writeln;

> void main() {
>      log("Let's check whether 'this' is an lvalue or not.");
>      Button btn = new Button("A button");
> }
>
> class Button {
>     this(string btntext)    {
>         mtext = btntext;
>         log("button created with the name , ", btntext);
>         log(&this);
>     }
>     private:
>     string mt
> }
It doesn't compile, the line

string mt

should be

string mtext;

instead. Indeed, we get a compiler error:

Error: this is not an lvalue and cannot be modified.

The problem is in line 11: You are trying to get the address of `this`. But `this` is an lvalue, so it does not have an address you could take. It becomes mir clear that this doesn’t work if you consider other lvalues, like literals:

int* = &1; // doesn’t compile, can’t take the address of an lvalue.

In this code example, the correct thing to do is to simply not take the address but pass `this` to `writeln`. That compiles and results in the following output:

Let's check whether 'this' is an lvalue or not.
button created with the name , A button
onlineapp.Button

(The module is onlineapp because I ran it in run.dlang.io)

I don't know what the correct thing would be in your original code though.