Jul 27, 2010 at 3:31am UTC
I'm not sure how to do it with .net, but I am pretty sure you can use ShellExecute in C++ to open a directory.
Last edited on Jul 27, 2010 at 4:53pm UTC
Aug 16, 2010 at 10:32am UTC
Sorry for the late reply.
So i tried to use ShellExecute:
ShellExecute(NULL,"open","C:/test.txt",NULL,NULL,SW_SHOWNORMAL);
But then i get the following error:
error C2664: 'ShellExecuteW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Aug 16, 2010 at 12:52pm UTC
ShellExecuteW is the unicode Version of the function, to use it you will need
to prefix the strings with 'L'
eg: L"open" and L"C:/text.txt"
or specify the Ansi function by using ShellExecuteA(...)
Aug 16, 2010 at 1:04pm UTC
I have tried that before as well. I then get the below error:
1>Form Test.obj : error LNK2028: unresolved token (0A000015) "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE__@@PAUHWND__@@PB_W111H@Z) referenced in function "private: void __clrcall FormTest::Form1::button2_Click_1(class System::Object ^,class System::EventArgs ^)" (?button2_Click_1@Form1@FormTest@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Form Test.obj : error LNK2019: unresolved external symbol "extern "C" struct HINSTANCE__ * __stdcall ShellExecuteW(struct HWND__ *,wchar_t const *,wchar_t const *,wchar_t const *,wchar_t const *,int)" (?ShellExecuteW@@$$J224YGPAUHINSTANCE__@@PAUHWND__@@PB_W111H@Z) referenced in function "private: void __clrcall FormTest::Form1::button2_Click_1(class System::Object ^,class System::EventArgs ^)" (?button2_Click_1@Form1@FormTest@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
Aug 16, 2010 at 2:19pm UTC
Ok, so i managed to prevent the error. And i can open a folder or file on my PC. But when i try to open a folder on a network, the button does nothing but the program compiles fine.
ShellExecute(NULL,L"open" ,L"\\testpc" ,NULL,NULL,SW_SHOWNORMAL);