What does {0} mean when initializing an object?

后端 未结 10 745
-上瘾入骨i
-上瘾入骨i 2020-11-29 14:46

When {0} is used to initialize an object, what does it mean? I can\'t find any references to {0} anywhere, and because of the curly braces Google s

10条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 15:31

    In answer to why ShellExecuteEx() is crashing: your SHELLEXECUTEINFO "sexi" struct has many members and you're only initializing some of them.

    For example, the member sexi.lpDirectory could be pointing anywhere, but ShellExecuteEx() will still try to use it, hence you'll get a memory access violation.

    When you include the line:

    SHELLEXECUTEINFO sexi = {0};
    

    before the rest of your structure setup, you're telling the compiler to zero out all structure members before you initialize the specific ones you're interested in. ShellExecuteEx() knows that if sexi.lpDirectory is zero, it should ignore it.

提交回复
热议问题