水無瀬の部屋 > Programming > sample > tools > toolsysx.cpp |
---|
1: //*********************************************************
2: // プロジェクト: TOOLS
3: // ファイル名: toolsysx.cpp
4: //*********************************************************
5: #define USE_SHELLEXECUTE // [unsafe]
6: #define USE_SHGETPATHFROMIDLIST // [unsafe]
7: #include <header/toolsysx.h> //
8: #include <header/tooldbg.h> //
9: #include <header/toolbase.h> //
10: #include <header/toolwind.h> //
11: #include <header/toolsys.h> //
12:
13:
14: //------------------------------------------------------------------------------------------------------------------
15: // a
16: //------------------------------------------------------------------------------------------------------------------
17:
18: //------------------------------------------------------------------------------------------------------------------
19: // b
20: //------------------------------------------------------------------------------------------------------------------
21:
22: //------------------------------------------------------------------------------------------------------------------
23: // c
24: //------------------------------------------------------------------------------------------------------------------
25:
26: //------------------------------------------------------------------------------------------------------------------
27: // d
28: //------------------------------------------------------------------------------------------------------------------
29:
30: //------------------------------------------------------------------------------------------------------------------
31: // e
32: //------------------------------------------------------------------------------------------------------------------
33:
34: //------------------------------------------------------------------------------------------------------------------
35: // f
36: //------------------------------------------------------------------------------------------------------------------
37:
38: //------------------------------------------------------------------------------------------------------------------
39: // g
40: //------------------------------------------------------------------------------------------------------------------
41: //*********************************************************
42: // GetPathFromIDList
43: //*********************************************************
44: bool
45: GetPathFromIDList
46: (
47: const ITEMIDLIST *pidl,
48: char *buffer,
49: int bufsize
50: )
51: {
52: // パラメタの仮定
53: ASSERT( IsEnoughPathBufferSize( bufsize ) ); // [WARN]
54: ASSERT( IsValidReadPtr( pidl, sizeof( *pidl ) ) );
55: ASSERT( IsValidStringBufferPtr( buffer, bufsize ) );
56: DESTROY_TEXT_BUFFER( buffer, bufsize );
57:
58: //
59: char work[ USHRT_MAX ];
60: if ( ! SHGetPathFromIDList( pidl, work ) )
61: {
62: return false;
63: }
64: ASSERT( IsValidLocalPathString( work ) );
65:
66: //
67: strcopy( buffer, bufsize, work );
68: ASSERT( IsValidLocalPathString( buffer ) );
69: ASSERT( (int)strlen( buffer ) < bufsize );
70:
71: return true;
72: }//GetPathFromIDList
73:
74:
75: //------------------------------------------------------------------------------------------------------------------
76: // h
77: //------------------------------------------------------------------------------------------------------------------
78:
79: //------------------------------------------------------------------------------------------------------------------
80: // i
81: //------------------------------------------------------------------------------------------------------------------
82:
83: //------------------------------------------------------------------------------------------------------------------
84: // j
85: //------------------------------------------------------------------------------------------------------------------
86:
87: //------------------------------------------------------------------------------------------------------------------
88: // k
89: //------------------------------------------------------------------------------------------------------------------
90:
91: //------------------------------------------------------------------------------------------------------------------
92: // l
93: //------------------------------------------------------------------------------------------------------------------
94:
95: //------------------------------------------------------------------------------------------------------------------
96: // m
97: //------------------------------------------------------------------------------------------------------------------
98:
99: //------------------------------------------------------------------------------------------------------------------
100: // n
101: //------------------------------------------------------------------------------------------------------------------
102:
103: //------------------------------------------------------------------------------------------------------------------
104: // o
105: //------------------------------------------------------------------------------------------------------------------
106:
107: //------------------------------------------------------------------------------------------------------------------
108: // p
109: //------------------------------------------------------------------------------------------------------------------
110:
111: //------------------------------------------------------------------------------------------------------------------
112: // q
113: //------------------------------------------------------------------------------------------------------------------
114:
115: //------------------------------------------------------------------------------------------------------------------
116: // r
117: //------------------------------------------------------------------------------------------------------------------
118:
119: //------------------------------------------------------------------------------------------------------------------
120: // s
121: //------------------------------------------------------------------------------------------------------------------
122: //*********************************************************
123: // MyShellExecute
124: //*********************************************************
125: HINSTANCE
126: MyShellExecute
127: (
128: HWND hWnd,
129: const char *verb,
130: const char *path,
131: const char *param,
132: const char *workdir,
133: int nShow
134: )
135: {
136: // パラメタの仮定
137: ASSERT( IsPathExist( path ) );
138: ASSERT( !hWnd || IsValidWindow( hWnd ) );
139: ASSERT( !verb || IsValidStringPtr( verb ) );
140: ASSERT( !param || IsValidStringPtr( param ) );
141: ASSERT( !workdir || IsPathDirectory( workdir ) );
142:
143: //
144: IMalloc *pMalloc;
145: if ( NOERROR != SHGetMalloc( &pMalloc ) )
146: {
147: DBG_TRACE( "%s(%d) : %s \r\n", __FILE__, __LINE__,
148: "関数 SHGetMalloc() が失敗しました。" );
149: }
150: else
151: {
152: //
153: IShellLink *psl = CreateShellLinkInstanceEx( CLSCTX_INPROC_SERVER, path, param, workdir, STGM_READ );
154: if ( ! psl )
155: {
156: DBG_TRACE( "%s(%d) : %s \r\n", __FILE__, __LINE__,
157: "関数 CreateShellLinkInstanceEx() が失敗しました。" );
158: }
159: else
160: {
161: ITEMIDLIST *pidl;
162: if ( S_OK != psl->GetIDList( &pidl ) )
163: {
164: DBG_TRACE( "%s(%d) : %s \r\n", __FILE__, __LINE__,
165: "関数 psl->GetIDList() が失敗しました。" );
166: }
167: else
168: {
169: SHELLEXECUTEINFO sei;
170: memzero( &sei, sizeof( sei ) );
171: sei.cbSize = sizeof( sei );
172: sei.fMask = SEE_MASK_IDLIST;
173: sei.hwnd = hWnd;
174: sei.nShow = nShow;
175: sei.lpVerb = verb;
176: sei.lpFile = path;
177: sei.lpParameters = param;
178: sei.lpDirectory = workdir;
179: sei.lpIDList = pidl;
180: if ( ! ShellExecuteEx( &sei ) )
181: {
182: DBG_TRACE( "%s(%d) : %s \r\n", __FILE__, __LINE__,
183: "関数 ShellExecuteEx() が失敗しました。" );
184: }
185: else
186: {
187: pMalloc->Free( pidl );
188: psl->Release();
189: pMalloc->Release();
190:
191: return sei.hInstApp;
192: }
193: pMalloc->Free( pidl );
194: }
195: psl->Release();
196: }
197: pMalloc->Release();
198: }
199:
200: return null;
201: }//MyShellExecute
202:
203:
204: //------------------------------------------------------------------------------------------------------------------
205: // t
206: //------------------------------------------------------------------------------------------------------------------
207:
208: //------------------------------------------------------------------------------------------------------------------
209: // u
210: //------------------------------------------------------------------------------------------------------------------
211:
212: //------------------------------------------------------------------------------------------------------------------
213: // v
214: //------------------------------------------------------------------------------------------------------------------
215:
216: //------------------------------------------------------------------------------------------------------------------
217: // w
218: //------------------------------------------------------------------------------------------------------------------
219:
220: //------------------------------------------------------------------------------------------------------------------
221: // x
222: //------------------------------------------------------------------------------------------------------------------
223:
224: //------------------------------------------------------------------------------------------------------------------
225: // y
226: //------------------------------------------------------------------------------------------------------------------
227:
228: //------------------------------------------------------------------------------------------------------------------
229: // z
230: //------------------------------------------------------------------------------------------------------------------
231:
232:
233: //** end **
参照:
水無瀬の部屋 > sample > tools > toolsysx.cpp |
---|
このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/tools/toolsysx_cpp.shtml
同人ダウンロード販売|DL.Getchu.com