Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this tiny programm, which is intened to show windows file/folder properties dialog on the specified info.lpFile:

#include <windows.h>

main() {
   SHELLEXECUTEINFO info = {0};

   info.cbSize = sizeof(SHELLEXECUTEINFO);
   info.lpFile = "C:\test.txt";
   info.nShow = SW_SHOW;
   info.fMask = 0x00000000;
   info.lpVerb = "properties";

   ShellExecuteEx(&info);
}

When I compile and execute it, I get the following error message:

Error message

I'm using Win7 and Mingw gcc compiler. Does anybody knows what is wrong with my code? Am I missing something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
706 views
Welcome To Ask or Share your Answers For Others

1 Answer

1st of all the code as shown does not properly initialise info.

To fix this change

  SHELLEXECUTEINFO info;

to be

  SHELLEXECUTEINFO info = {0};

2ndly use SEE_MASK_INVOKEIDLIST for SHELLEXECUTEINFO's member fMask.

For your reference: https://msdn.microsoft.com/en-us/library/windows/desktop/bb759784%28v=vs.85%29.aspx

Please note that to see the properties window open, the invoking code must not end immediately. So add something like

  Sleep(10000);

to the end of your test code as shown.


Full code that works for me:

#include <windows.h>

int main(void) 
{
  SHELLEXECUTEINFO info = {0};

  info.cbSize = sizeof info;
  info.lpFile = L"C:\tmp\tmp.txt";
  info.nShow = SW_SHOW;
  info.fMask = SEE_MASK_INVOKEIDLIST;
  info.lpVerb = L"properties";

  ShellExecuteEx(&info);

  Sleep(10000);
}

Build options:

/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"DebugSOxyzConsoleEmpty.pch" /Fa"Debug" /Fo"Debug" /Fd"Debugvc100.pdb" /Gd /TC /analyze- /errorReport:queue 

(Tested with VS2010, running Windows 7)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...