Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- // Alloc bytes for chars
- #define challoc(x) ((char *)malloc((sizeof(char))*(x)))
- // Get a local EXE name.
- // Yes, you cannot do it in one WinAPI function.
- // Returns a naked string containing an EXE name (if successful), OR
- // an empty string (if GetModuleFileNameA failed), OR
- // an empty string (if runtime-linking failed), OR
- // a string with a full path (if PathFindFileNameA failed).
- char * GetExeName (void) {
- char *result = challoc(256);
- char temp[32769]; int temp1;
- HMODULE hShlwapi = LoadLibraryA("shlwapi.dll");
- FARPROC PathFindFileNameA = GetProcAddress(hShlwapi, "PathFindFileNameA");
- if (PathFindFileNameA == 0) return '\0';
- temp1 = GetModuleFileNameA(0, temp, 32769);
- if (temp1 == 0) return '\0';
- strcpy(result, (const char *)PathFindFileNameA(temp));
- FreeLibrary(hShlwapi);
- return result;
- }
- int main() {
- printf("%s\n", GetExeName());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement