GetCurrentDirectory is not working for real application path

H

Hasan O.

Hi ,

I have a simple program thats open some file a.txt. When program starts it
gets GetCurrentDirectory and finds / opens the a.txt file. But if i create
a shortcut on desktop it couldnot find real working directory. How can i do
this ?

this is not working for shortcuts
char buf[2001];
GetCurrentDirectory(2000, buf);
m_strCurrentDir = buf;

thanks in advance
 
J

Jochen Kalmbach [MVP]

Hi Hasan!
I have a simple program thats open some file a.txt. When program starts it
gets GetCurrentDirectory and finds / opens the a.txt file. But if i create
a shortcut on desktop it couldnot find real working directory. How can i do
this ?

this is not working for shortcuts

It works perfectly for shortcuts!

But maybe you expected some other results as GetCurrentDirectory returns.
GetCurrentDirectory returns always the current directory. And for
shortcuts this is mostly "c:\windows\system32".

If you want to have the directory of your EXE, then you must use
"GetModuleFileName(NULL, ...)" and retrive the path from the returned
string.

Greetings
Jochen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top