www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Windows - ZeroMemory macro

reply "dnewbie" <run3 myopera.com> writes:
In C I can write

OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));

In D, there is no ZeroMemory. Please help me.
May 26 2012
next sibling parent reply "jerro" <a a.com> writes:
On Sunday, 27 May 2012 at 03:29:17 UTC, dnewbie wrote:
 In C I can write

 OPENFILENAME ofn;
 ZeroMemory(&ofn, sizeof(ofn));

 In D, there is no ZeroMemory. Please help me.
You could use c memset: import std.c.string; memset(cast(void*)&ofn, 0, ofn.sizeof); or this: (cast(byte*)& a)[0 .. a.sizeof] = 0;
May 26 2012
parent "dnewbie" <run3 myopera.com> writes:
On Sunday, 27 May 2012 at 03:55:58 UTC, jerro wrote:
 On Sunday, 27 May 2012 at 03:29:17 UTC, dnewbie wrote:
 In C I can write

 OPENFILENAME ofn;
 ZeroMemory(&ofn, sizeof(ofn));

 In D, there is no ZeroMemory. Please help me.
You could use c memset: import std.c.string; memset(cast(void*)&ofn, 0, ofn.sizeof); or this: (cast(byte*)& a)[0 .. a.sizeof] = 0;
Thank you.
May 27 2012
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 5/27/12, dnewbie <run3 myopera.com> wrote:
 In C I can write

 OPENFILENAME ofn;
 ZeroMemory(&ofn, sizeof(ofn));

 In D, there is no ZeroMemory. Please help me.
I've never had to use this with WinAPI. The default .init value usually works well, especially if the struct is well-defined, e.g.: struct Foo { int x; // default 0-initialized float y = 0; // without this y would be NaN by default } I think all bits will be set to 0 for a 'Foo' instance.
May 27 2012