Page 1 of 2

How to know path name from whos called

Posted: Tue Nov 27, 2012 1:47 pm
by Pablo César
I have following trouble (I will give example):

Program1.prg (this is HMG IDE which call a Editor)
Function Main()
Local cDir:="\folder1" // this is not fixed. Always changing folder according each project placed
Local cFile:="File1.prg" // this is not fixed too, according project files
Local cApp:="c:\folder2\Program2.exe" // this is fixed

ChangeDir(cDir)
cCommand:=cApp+" "+cFile
MyRun(cCommand)
Return Nil


Program2.prg (this app always will be at c:\folder2 folder)
Function Main(cFile)
MsgInfo( cFile ) // ok showing right file name

MsgInfo(
here I need to Get Folder name of that cFile. But how I do this ? )

Return Nil


All my tries was using GetCurrentFolder() and GetStartUpFolder() but always returning "c:\folder2" and I need to know which folder Program1 was positioned.

Any body to help me please ?

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 1:54 pm
by Rathinagiri
Program2.prg (this app always will be at c:\folder2 folder)
Function Main(cFile)
MsgInfo( cFile ) // ok showing right file name

MsgInfo( here I need to Get Folder name of that cFile. But how I do this ? )

Return Nil
Does the cFile have the full path?

How to know path name from whos called

Posted: Tue Nov 27, 2012 2:01 pm
by Pablo César
Thanks my friend for your interest.

No, this is only file name. It´s an argument received from HMG IDE when call Module Editor at Preferences in Tools IDE menu.

I wish to make some improvements using external programs thru IDE when call source's editor.
Screen47.PNG
Screen47.PNG (11.52 KiB) Viewed 5180 times
In this my test of Demo.exe I will also call Notepad++ (this is already working) but before I need to know from which folder had been called in Program2.

HMG IDE pass only file name when user clicks on PRG name at Project Browser of IDE.

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 2:12 pm
by esgici
Hi Pablo

I'm not sure that right understood you question :?

But I guess TrueName() function may help you.

Regards

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 2:17 pm
by Pablo César
esgici wrote:But I guess TrueName() function may help you.
Ohhh man ! You hit it !!! Right, that's it what I was looking for. This TrueName returning with path, then It will be easy to know from where.

THANK YOU amigo Esgici and Rathinagiri for your attention !

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 3:24 pm
by Rathinagiri
Whenever IDE is started and we click the open project button, the last project folder is displayed irrespective of the HMG/IDE version. That means that IDE stores this folder name somewhere common in registry/ini file. I don't know where!

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 3:45 pm
by Pablo César
rathinagiri wrote:Whenever IDE is started and we click the open project button, the last project folder is displayed irrespective of the HMG/IDE version. That means that IDE stores this folder name somewhere common in registry/ini file. I don't know where!
Yeap, thank for you tip. I understood your idea, GetFile() in the IDE source should have I Default path given by OS. I will look in MSDN if I find something about.

I make some implement in Claudio's View_Build_Log app just to push those info. Because, View_Build_Log shows a list of Projects from Recent Files but needs user click to PRG file thru Windows Explorer for append that list. Otherwise, not by opening thru IDE all project are shown.

Re: How to know path name from whos called

Posted: Tue Nov 27, 2012 11:53 pm
by klauskugel
Hi Pablo,
could it be that you're looking for
these Functions
winnetwk.h // mingw
...

DWORD APIENTRY WNetGetUniversalNameA(LPCSTR,DWORD,PVOID,PDWORD);
DWORD APIENTRY WNetGetUniversalNameW(LPCWSTR,DWORD,PVOID,PDWORD);

If that's wrong,
why not search for the ini-File

GetPrivateProfileStringA kernel32.dll
WritePrivateProfileStringA kernel32.dll

So you can read/write any private ini's like hmg.ini or something,
to store private stuff.

Greetings klauskugel
Hope it helped

Re: How to know path name from whos called

Posted: Wed Nov 28, 2012 12:32 am
by klauskugel
Hi Pablo,

found another function which returns the Fullpath
DWORD GetFullPathName(LPCTSTR lpFileName,DWORD nBufferLength,LPTSTR lpBuffer,LPTSTR *lpFilePart);
http://winapi.freetechsecrets.com/win32 ... thName.htm


Function Main()
Local cDir:="\folder1" // this is not fixed. Always changing folder according each project placed
Local cFile:="File1.prg" // this is not fixed too, according project files
Local cApp:="c:\folder2\Program2.exe" // this is fixed

ChangeDir(cDir)

Why not at 1st set the Set the DriveLetter first?
BOOL SetCurrentDirectory( LPCTSTR lpPathName );

Some of these might hit it.
If not - hmmm., :cry: we go on searching. :D

Happy HMGing
klauskugel

How to know path name from whos called

Posted: Wed Nov 28, 2012 1:39 am
by Pablo César
klauskugel wrote: ...
Local cDir:="\folder1" // this is not fixed. Always changing folder according each project placed

Why not at 1st set the Set the DriveLetter first?

Some of these might hit it.
You are right klauskugel, DriveLetter may contain a drive designator and a path for ChangeDir() function.

I thank you very much for your indications. But this have already solutioned when Esgici has indicated TruName() function. All codes that I posted was just for referance, I was trying to explain the problem. What Mr. Rathinagiri appointed was about last path was accessed when you call GetFile() which it´s means that SO (or properly: Method System IO) keep in some where (we do not know where) to get this information. And this is very interesting now, because I trying to implement a way to keep last project files are accessed for historical proposes. But I probably will take projects files accessed and will store in DBF. Will be more simple and flexible too.

By the other hand, I have another problematic question. I need to know the handle Window of HMG IDE when is open. Upto here, no problem. This is very simple to find by Title name which starts "HMG IDE (c)..." but the problem is when many projects are open and can not know which IDE's window is right for handling. By title with project name would makes easier to identify when you have many IDE's section open. This is really hard to get a solution. I have probably a way, but I not sure. As I said, IDE can call Notepad++ editor when you double click at PRG file in "Project Browser" of IDE. But if you change in preference Notepad++ with your own program, IDE will call it. So I think can be possible to get a handle is calling (in this case: IDE's handle) but I not sure of this.