D - Idea for a core app class or struct
- Ameer (11/11) May 18 2004 Hey all.
- KTC (2/2) May 18 2004 This newsgroup is now deprecated. Try
- J C Calvarese (59/73) May 20 2004 (I'm cross-posting this to the new newsgroup:
- Pablo Aguilar (3/13) May 21 2004 You should try PathRemoveFileSpec from shlwapi.dll (shlwapi.h and
- J C Calvarese (13/33) May 21 2004 I'd rather not. I think I can find the path without using an OS
Hey all. I have been looking at the d specs and am very pleased with what I see; it'll probably hit big pretty soon. I've been wondering, if we could possibly have a generic app class or struct, like in visual basic. In vb, it normally contains the app's name, path, major/minor/revission numbers, and a full version string. This will eliminate the need for a "prog_version.d" file, and a separate variable, among other things; if nothing else, you can tell app.path lot easier than args[0] if it's even still used. Thanks, Ameer
May 18 2004
This newsgroup is now deprecated. Try news://news.digitalmars.com/digitalmars.D
May 18 2004
Ameer wrote:Hey all. I have been looking at the d specs and am very pleased with what I see; it'll probably hit big pretty soon. I've been wondering, if we could possibly have a generic app class or struct, like in visual basic. In vb, it normally contains the app's name, path, major/minor/revission numbers, and a full version string. This will eliminate the need for a "prog_version.d" file, and a separate variable, among other things; if nothing else, you can tell app.path lot easier than args[0] if it's even still used. Thanks, Ameer(I'm cross-posting this to the new newsgroup: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D). It sounds like a job for a library to me. Here's a function that could be used for app.path (I haven't tested it too thoroughly, but it seems to work): /* apppath.d Shows how to find the path of the current executable. (Windows-only) */ 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); alias GetModuleFileNameA GetModuleFileName; alias GetModuleHandleA GetModuleHandle; } char[] CharRetString(char c) { /* return a string from a character */ char[] s = "?"; s[0] = c; return s; } char[] repeatString(int count, ubyte a) { /* returns a string containing 'count' occurences of the character corresponding to the ASCII character code 'a'. */ char[] tmp; for (int i = 0; i < count; i++) tmp ~= CharRetString(a); return tmp; } char[] AppExePath() { /* returns the Path to the current .exe module (e.g. "c:\dmd\src\test\") */ char[] strtmp = repeatString(1024, 32); int j; GetModuleFileName(GetModuleHandle(null), cast(char*) strtmp, 1024); j = rfind(strtmp[0..strlen(strtmp)], "\\"); strtmp = strtmp[0..j] ~ "\\"; return strtmp; } void main() { printf("%.*s\n", AppExePath); } -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 20 2004
char[] AppExePath() { /* returns the Path to the current .exe module (e.g. "c:\dmd\src\test\")*/char[] strtmp = repeatString(1024, 32); int j; GetModuleFileName(GetModuleHandle(null), cast(char*) strtmp, 1024); j = rfind(strtmp[0..strlen(strtmp)], "\\"); strtmp = strtmp[0..j] ~ "\\"; return strtmp; }You should try PathRemoveFileSpec from shlwapi.dll (shlwapi.h and shlwapi.lib)
May 21 2004
Pablo Aguilar wrote:I'd rather not. I think I can find the path without using an OS function. I don't see the advantage in adding a .dll dependency (unless I had a grudge against Windows 95 users who haven't upgraded to IE 4.0): Minimum operating systems Windows 2000, Windows NT 4.0 with Internet Explorer 4.0, Windows 98, Windows 95 with Internet Explorer 4.0 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/path/pathremovefilespec.asp I've attached an improved version of the AppExePath function since I've received such a large response. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/char[] AppExePath() { /* returns the Path to the current .exe module (e.g. "c:\dmd\src\test\")*/char[] strtmp = repeatString(1024, 32); int j; GetModuleFileName(GetModuleHandle(null), cast(char*) strtmp, 1024); j = rfind(strtmp[0..strlen(strtmp)], "\\"); strtmp = strtmp[0..j] ~ "\\"; return strtmp; }You should try PathRemoveFileSpec from shlwapi.dll (shlwapi.h and shlwapi.lib)
May 21 2004