Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Application path

Part of TutorialAdvanced

Description

Shows how to find the path of the current executable (Windows-only).

Example

/* Tested with DMD 1.0 */

import std.c.windows.windows;
import std.c.stdio;
import std.string;


extern(C) int strlen(char* c);

extern(Windows) 
{
    DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);   
    HMODULE GetModuleHandleA(LPCSTR lpModuleName);
}


char[] AppExePath()
{
    /* returns the Path to the current .exe module (e.g. "F:\PGM\D\TRAYICON\") */

    char[] strtmp;
    strtmp.length = 1024;

    GetModuleFileNameA(GetModuleHandleA(null), cast(char*) strtmp.ptr, 1024);
    int j = rfind(strtmp[0..strlen(strtmp.ptr)], "\\");

    strtmp = strtmp[0..j+1];
    return strtmp;
}


void main()
{  
    printf("%.*s\n", AppExePath);    
}

Source

Link http://www.dsource.org/tutorials/index.php?show_example=91
Posted by jcc7
Date/Time Thu Sep 23, 2004 9:44 am