Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capturing the name of a running prg

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU

My app consists of a large number of prg files. I would like to mantain a record of which prg is running at any one time and
record that in a log file.
I have the prg for a log file ('logging.prg') and would hope to add a call to it like
logging(myprogname) each time the subject prg is run.

So is there a way of saying myprogname = (program) at the top of each prg?

GenDev
 
Hi mJindrova
Your link didn't work but I got to the vfp area anyway.
Unfortunately my PC will not allow me to open the downloaded file cvp_1.19.0018_9.0_sc_20140918.zip
Is there any other way of getting this utility?

GenDev
 
The link works for me.

It's not a link to a web page, it's a direct link to the download of a zip file. And after waiting a few seconds I'm asked where to store that download, that's the usual reaction of a browser to a doenload link clicked.

I can also unzip this file, there's nothing broken with it. Have you never unzipped a zip archive (aka zip file), gendev? Windows even has unzipping as an onboard feature, you don't need any software for unzipping a zip file. So I don't know, maybe you just try once more.

Chriss
 
mJindrova: The first start of cvp.exe showed a message "XX_SYSTEM is not an object".
I can't reproduce that, so the problem seems to be resolved with whatever runs after the message is displayed.

When I try to process a small log file csv tells me it needs 6MB on drive C:, well there are a few GB, so what's up with that?

Chriss
 
Hi Chriss,

XX_SYSTEM is a main object and it's very strange so doesn't exists. And I can't reproduced too.
You got error message "... Small diskspace for temporary files. ... "? Really? Hmm.

1) Menu File->Open and check "Log debug message" choice in Options dialog.
2) Menu View->Output window

and try process log file again.


mJindrova
 
Hi gendev,

This old server uses http only and modern web viewers penalise http protocol.


mJindrova
 
mJindrova,

I used the debugoutput and then
Open->New
picking acoverage.log file

This is the ouput:
[pre] File Length: 1496
AVG Row Length: 63
Row Count: 24
Root: C: Disk Free Space: -629145600,0
Root: C: Disk Free Space: -629145600,0
Full Size: 6188278[/pre]

So, clearly, your code doesn't register the right free disk space.
Diskspace('C:\') gives the right amount of free space, what are you using to determine free disk space?

Chriss
 
Chris,


It's a good question why API function GetDiskFreeSpaceEx return weird values.
Because you download source code, you can do small test:

[pre]
SET PROCEDURE TO "kernel.PRG"
?DiskSpaceEx("c:\",0)[/pre]

I have not problem in W7 or W10 with 2TB HDD.



mJindrova
 
No. it didn't come with sources. This is all I got:
cvpdir_xurexb.jpg


Chriss
 
Thanks, I'll try to reproduce. In the meantime I just made a lot of space by moving a lot to an external drive and then cvp.exe works, so it returns positive disk space when it's higher.

But I remember about which size made the code determine a negative disk space. There must be something in the evalutaion of the API return values that leads to a negative disk space under specific circumstances, I think you could reverse engineer it if you turn -629145600 into the bit representaiton opf a 32bit signed integer and then interpret it again as unsigned.

Anyway, the evaluation should always result in a positive number, so I think there's just a conversion error.

Edition Windows 10 Pro
Version 22H2
Installed on ‎11/‎03/‎2022
OS build 19045.4291
Experience Windows Feature Experience Pack 1000.19056.1000.0

Chriss
 
Your conversion from lpTotalNumberOfFreeBytes is wrong:

Code:
#DEFINE maxInt 4294967296
lpTotalNumberOfFreeBytes = 0h000080DA

liDFS = (CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,5,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,8,1)),24))*maxInt+;
           CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,1,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,4,1)),24)
You have to interpret this unsigned, which means the actual result is given by

Code:
#DEFINE maxInt 4294967296
lpTotalNumberOfFreeBytes = 0h000080DA

liDFS = (CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,5,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,8,1)),24))*maxInt+;
           CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,1,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,4,1)),24)
[highlight #FCE94F]liDFS = IIf(liDFS<0,maxInt+liDFS)[/highlight]


Chriss
 
My approach of turning a 64bit unsigned integer into a VFP numeric value is this, by the way:

Code:
 Procedure Convert64bitUInt(tc64bitUInt)
   #DEFINE maxInt 4294967296
   Local liLo, liHi
   liLo = CToBin(Right(m.tc64bitUInt,4),"4RS")
   liLo = Iif(m.liLo<0,maxInt+m.liLo,m.liLo) && we want the unsigned interpretation
   liHi = CToBin(Left(m.tc64bitUInt,4),"4RS")
   liHi = Iif(m.liHi<0,maxInt+m.liHi,m.liHi) && we want the unsigned interpretation
   liFull = 
   Return liHi*maxInt+liLo

Well, and the way the 64bits are sorted into the 8 bytzes in case of the GetDiskFreeSpaceEx API function requires the inverse interpretation of the first and last 4 bytes:

Code:
Procedure Convert64bitUInt(tc64bitUInt)
   #DEFINE maxInt 4294967296
   Local liLo, liHi
   liLo = CToBin([highlight ]Left[/highlight](m.tc64bitUInt,4),"4RS")
   liLo = Iif(m.liLo<0,maxInt+m.liLo,m.liLo) && we want the unsigned interpretation
   liHi = CToBin([highlight ]Right[/highlight](m.tc64bitUInt,4),"4RS")
   liHi = Iif(m.liHi<0,maxInt+m.liHi,m.liHi) && we want the unsigned interpretation
   Return liHi*maxInt+liLo

I use the other version for the return values of GetSystemTimePreciseAsFileTime, where the out parameter is a simpler 64bit unsigned struct:
Code:
typedef struct _FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;

vs what GetDiskFreeSpaceEx uses:
Code:
typedef union _ULARGE_INTEGER {
  struct {
    DWORD LowPart;
    DWORD HighPart;
  } DUMMYSTRUCTNAME;
  struct {
    DWORD LowPart;
    DWORD HighPart;
  } u;
  ULONGLONG QuadPart;
} ULARGE_INTEGER;

So, in shbort: your 64bit unsigned integer interpretation for GetDiskFreeSpaceEx doesn't work in a range of about 3.5 GB, where you get negtive values despite what I see you doing to prevent misinterpretation of the sign bit. They way to convert correctly must understnad which 4 bytes are the high part of the 64bit integer and which 4 bytes are the low part. That differs in many API functions, unfortunately.

Chriss
 
Regarding the other error "XX_SYSTEM is not an object" I got on the first run of cvp.exe, I think it's the use of XX_SYSTEM in the _CVP_toolbar class definition, because I remember in that first run after clicking "OK" on the error message, I had no tolbar, but in consecutive runs I had the toolbar. So, I don't know how or why, but maybe under some circumstances you create the toolbar before xx_system?

Chriss
 
Hi Chris,

Thank you. This code is older and I don't see a bug in a procedure.

Creating toolbars is last step befor showing main window. I did delete branch for CVP in registry, but I don't got a error.

mJindrova
 
I don't know which registry entry you mean, but I did merge English.reg into the registry before first time running cvp.exe and got that error, also only for that first run. Is there anything else that could be reset?

Chriss
 
Strange, the EXE within the zip that has sourcecode is saying it's product version 1.20.4, whlie the EXE in the zip you initially posted is 1.20.6, so actually the newer EXE exposes this error.

The 64bit conversion you use definitely is creating negative results for numbers in the range of about 3.41GB, you can verify that.

To be more precise´, than I was before, the character composition of the lpTotalNumberOfFreeBytes return value is like this:
Code:
#DEFINE maxInt 4294967296
lpTotalNumberOfFreeBytes = chr(0)+chr(0)+chr(128)+chr(218)+chr(0)+chr(0)+chr(0)+chr(0)

liDFS = (CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,5,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,8,1)),24))*maxInt+;
           CTOBIN(SUBSTR(lpTotalNumberOfFreeBytes,1,3)+CHR(0),"RS")+BITLSHIFT(ASC(SUBSTR(lpTotalNumberOfFreeBytes,4,1)),24) 

? liDFS
? maxInt+liDFS
The uncorrected liDFS is what came from the debug output I posted earlier, well, and adding maxInt to it is the real free diskspace.

The error becomes most pronounced, perhaps if you examine what your conversion gives you for
Code:
lpTotalNumberOfFreeBytes = chr(0)+chr(0)+chr(0)+chr(128)+chr(0)+chr(0)+chr(0)+chr(0)
In short, you didn't expect BITLSHIFT giving negative values, but it does:
Code:
? BITLSHIFT(128,24)

Ironically, this shows the method of code coverage unit testing does not necessarily ensure every case is covered in terms of things like numerical range processed by a line of code that is called in your coverage testing, yet not with a critical case. Unit testing is more than coverage testing.

Chriss
 
I can not reproduce bug at first runs.
CVP save all settings to windows registry. I did test two scenarios:
- run cvp without registry settings and not cvp.ini in APP data folder
- run cvp with language in registry settings and not cvp.ini in APP data folder


Fixed hdd free space bug
Source code: EXE:
mJindrova
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top