2 * Copyright 2003 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 23.07.2003
35 void display_error(HWND hwnd, DWORD error)
39 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
40 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
41 MessageBox(hwnd, msg, TEXT("Winefile"), MB_OK);
43 MessageBox(hwnd, TEXT("Error"), TEXT("Winefile"), MB_OK);
49 BOOL time_to_filetime(const time_t* t, FILETIME* ftime)
51 struct tm* tm = gmtime(t);
57 stime.wYear = tm->tm_year+1900;
58 stime.wMonth = tm->tm_mon+1;
59 /* stime.wDayOfWeek */
60 stime.wDay = tm->tm_mday;
61 stime.wHour = tm->tm_hour;
62 stime.wMinute = tm->tm_min;
63 stime.wSecond = tm->tm_sec;
65 return SystemTimeToFileTime(&stime, ftime);
69 BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow)
71 HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
73 if ((int)hinst <= 32) {
74 display_error(hwnd, GetLastError());
82 BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow)
84 HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
86 if ((int)hinst <= 32) {
87 display_error(hwnd, GetLastError());
96 /* search for already running win[e]files */
98 static int g_foundPrevInstance = 0;
100 static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam)
104 GetClassName(hwnd, cls, 128);
106 if (!lstrcmp(cls, (LPCTSTR)lparam)) {
107 g_foundPrevInstance++;
114 /* search for window of given class name to allow only one running instance */
115 int find_window_class(LPCTSTR classname)
117 EnumWindows(EnumWndProc, (LPARAM)classname);
119 if (g_foundPrevInstance)
126 typedef void (WINAPI*RUNDLLPROC)(HWND hwnd, HINSTANCE hinst, LPCTSTR cmdline, DWORD nCmdShow);
128 BOOL RunDLL(HWND hwnd, LPCTSTR dllname, LPCSTR procname, LPCTSTR cmdline, UINT nCmdShow)
130 HMODULE hmod = LoadLibrary(dllname);
136 It is possible to create a Unicode version of the function.
137 Rundll32 first tries to find a function named EntryPointW.
138 If it cannot find this function, it tries EntryPointA, then EntryPoint.
139 To create a DLL that supports ANSI on Windows 95/98/Me and Unicode otherwise,
140 export two functions: EntryPointW and EntryPoint.
142 RUNDLLPROC proc = (RUNDLLPROC)GetProcAddress(hmod, procname);
148 proc(hwnd, hmod, cmdline, nCmdShow);