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:
I'm using Win7 and Mingw gcc compiler. Does anybody knows what is wrong with my code? Am I missing something?
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"Debug\SOxyzConsoleEmpty.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /TC /analyze- /errorReport:queue
(Tested with VS2010, running Windows 7)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With