SImple C++ code to D

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 13 19:16:53 PDT 2014


On 07/13/2014 05:21 PM, Alexandre wrote:
> Ok, thanks thanks!!!
> Have a lot of thinks I need to learn....
>
> When I generate the exe file, something is wrong with this:
> dosh.e_magic = cast(WORD)*"MZ".ptr;
>
> When the PE file is generate in EXE have just the "M" of "MZ"...

You put the * outside the cast. bearophile had

dosh.e_magic = cast(WORD*)"MZ".ptr;

However, one needs to copy the content to e_magic, which happens to be a 
WORD. The endianness may be off but it should be something like this:

import std.stdio;

void main()
{
     alias WORD = ushort;
     WORD w = *cast(WORD*)"MZ".ptr;
     writefln("%02x", w);
}

Ali



More information about the Digitalmars-d-learn mailing list