root/src/getdir_win.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_install_dir

   1 /*
   2  * getdir_win.c - get the library directory at runtime (fow windows)
   3  *  included from paths.c
   4  *
   5  * $Id: getdir_win.c,v 1.2 2005/10/27 13:16:55 shirok Exp $
   6  */
   7 
   8 #include <windows.h>
   9 #include <shlwapi.h>
  10 #include <string.h>
  11 
  12 static int get_install_dir(char *buf, int buflen,
  13                            void (*errfn)(const char *msg, ...))
  14 {
  15     HMODULE mod;
  16     DWORD r;
  17     char path[MAX_PATH];
  18     int len;
  19 
  20     if ((mod = GetModuleHandle("libgauche.dll")) == NULL) {
  21         errfn("GetModuleHandle failed");
  22     }
  23     if ((r = GetModuleFileName(mod, path, MAX_PATH)) == 0) {
  24         errfn("GetModuleFileName failed");
  25     }
  26     /* remove \libgauche.dll */
  27     if (!PathRemoveFileSpec(path)) {
  28         errfn("PathRemoveFileSpec failed on %s", path);
  29     }
  30     /* remobe \bin */
  31     if (!PathRemoveFileSpec(path)) {
  32         errfn("PathRemoveFileSpec failed on %s", path);
  33     }
  34     len = strlen(path);
  35     if (len >= buflen-1) {
  36         errfn("Pathname too long: %s", path);
  37     }
  38     strcpy(buf, path);
  39     return len;
  40 }

/* [<][>][^][v][top][bottom][index][help] */