Thursday, July 9, 2009

How to get application name in borland C++ builder 6 ?

I'm writing a windows application, and I need to know the application name ... like argv[0] in C language !


How I can find out the application name ?

How to get application name in borland C++ builder 6 ?
The function 'GetModuleFileName()' can be used...





Code:





// With STL string


#include %26lt;string%26gt;





char szAppPath[MAX_PATH] = "";


std::string strAppName;





::GetModuleFileName(0, szAppPath, MAX_PATH);





// Extract name


strAppName = szAppPath;


strAppName = strAppName.substr(strAppName.rfind("\\") + 1);











// With CString


char szAppPath[MAX_PATH] = "";


CString strAppName;





::GetModuleFileName(0, szAppPath, MAX_PATH);





// Extract name


strAppName = szAppPath;


strAppName = strAppName.Right(strAppName.ReverseFind(... + 1);


No comments:

Post a Comment