- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am developing a windows dialog based program and have a problem with:
num = GetDlgItemText(hwDlg, IDC_M1, myBuffer,20)
If (num /= 0) Then
iostatus = 1
do while (iostatus /= 0)
Read(myBuffer,*,iostat=iostatus) X
end do
myBuffer = '25.6 '
num = 4
and X = garbage
iostatus = 59
without the do while and the iostat, the program has a break at the read statement. When I programmed in C++, there was a lock function to keep myBuffer in real ,memory so the i/o works. This is part of a callback routine. What can I do to fix this?
Brooks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you saying, without the do while, you suspect that between the GetDlgItemText into myBuffer, and the internal READ from the text in myBuffer into the numeric X, that the O/S paging system paged out the memory with myBuffer?
If there is a paging issue, and I emphasize if, then it is possible that only part of myBuffer was touched (and paged in) by GetDlgItemText. If this is the case, then immediately preceeding GetDlgItemText, insert
myBuffer = ' '
Note, if the above causes a fault, then your myBuffer address is corrupted or uninitialized.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I should have mentioned that paging should not have caused a problem.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Two points. ISTATUS=0 OK read /= 0 is a read error. You logic this seems strange! Secondly what is the value of IOSTAT after the first read, that this give you the indication of why it failed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Andrew,
he is setting IOSTATUS=1 prior to the do while loop. He expects it to iterate once, but is stating he is experiencing it iterating more than once. His suspicion is that myBuffer experiences a page fault, and that this fault returns an error (status) that is non-zero. Then the second time through, no page fault, no error. Page faults should not be returned as an error (except for non-pagable interrupt level code).
GetDlgItemText will not padd the buffer with blanks, it returns the number of valid bytes. Brooks should pre-set the buffer to ' ' prior to call (or use the length returned to restrict the "input" to the valid bytes:
Read(myBuffer(1:num),*,iostat=iostatus) X
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
D'oh, I should have read more closely. But 59 is a read format error so the buffer string presumably has some junk in it that cannot translate to a number? Is buffer actually declared as 20 long? I normally pass len(buffer) BTW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's always difficult to diagnose a problem when all we have is snippets, descriptions and pseudo code, but I am going to guess that the callback routine does not include a !DEC$ ATTRIBUTES STDCALL directive, leading to stack corruption. (Note that STDCALL by itself will change to pass-by-value, so add REFERENCE if you want that.) Windows dialog callback routines must be STDCALL. I don't think page faults have anything to do with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
Read(myBuffer(1:num),*,iostat=iostatus) X
Effectively, that's the way the read from the string returned by GetDlgItemText must be done.
Fix your code before searching for another error
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page