Application.StartupPath

Hi,

In a previous thread I asked about reading the path of an executable in Visual C++. I was told to use Application.StartupPath . Unfortuantly I cannot get it to work.

I've tried using the forms:

path = Application.StartupPath();

and

path = Application:Tongue TiedtartupPath;

The compiler reports the following errors:

'Application' is not a class or namespace name.

'StartupPath' undeclared identifier

Could someone please suggest what I may be doing wrong, and what header file I need to include.

Thanks in advance

Andrew Ellis

[757 byte] By [AndrewEllis] at [2008-1-7]
# 1
Andrew Ellis wrote:

path = Application:tartupPath;

The compiler reports the following errors:

'Application' is not a class or namespace name.

'StartupPath' undeclared identifier

You must be trying that in an MFC Application ? You can use GetCommandLine() if it's an MFC app. It will give you the path and the exe name.

e.g.

Code Snippet


void
CMFCDialogDlg::OnBnClickedButton1() {

CString s = GetCommandLine();

Label1.SetWindowTextW(s);

}

Regards

Sahir Shah

SahirShah at 2007-10-2 > top of Msdn Tech,Visual C++,Visual C++ General...
# 2

You should at least provide a link to Saving a file in the same directory as the program's .exe file.

If you are using MFC then you should have said so in your first question. I assume you are not. Are you using MFC or are you using CLI or are you using the Windows SDK directly or something else?

SimpleSamples at 2007-10-2 > top of Msdn Tech,Visual C++,Visual C++ General...