1:
2:
3:
4:
5:
6:
7:
8: #include <string.h>
9:
10: static int get_install_dir(char *buf, int buflen,
11: void (*errfn)(const char *msg, ...))
12: {
13: HMODULE mod;
14: DWORD r;
15: int len;
16: const char *mbpath;
17: TCHAR path[MAX_PATH];
18: const TCHAR *libname = _T("libgauche.dll");
19:
20: if ((mod = GetModuleHandle(libname)) == NULL) {
21: errfn("GetModuleHandle failed");
22: }
23: if ((r = GetModuleFileName(mod, path, MAX_PATH)) == 0) {
24: errfn("GetModuleFileName failed");
25: }
26:
27: if (!PathRemoveFileSpec(path)) {
28: errfn("PathRemoveFileSpec failed on %s", SCM_WCS2MBS(path));
29: }
30:
31: if (!PathRemoveFileSpec(path)) {
32: errfn("PathRemoveFileSpec failed on %s", SCM_WCS2MBS(path));
33: }
34: mbpath = SCM_WCS2MBS(path);
35: len = (int)strlen(mbpath);
36: if (len >= buflen-1) {
37: errfn("Pathname too long: %s", mbpath);
38: }
39: strcpy(buf, mbpath);
40: return len;
41: }