- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been troubleshooting a memory access
violation and found the following line of code
in a function that initializes the OPENFILENAME
structure:
OFN%LpStrFileTitle = LOC(gszFileTitle//"*.txt"C)
Where gszFileTitle is a Global variable.
code should have been:
OFN%LpStrFileTitle = NULL
LOC(gszFileTitle//"*.txt"C) does not produce a
compiler error, so I assume that a temporary memory
location is created to hold the string
gszFileTitle//"*.txt"//ACHAR(0). However, after the
function returns I assume the address becomes invalid.
If the paragraph above is correct it would explain
the memory access violation.
Any comments would be appreciated.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your understanding is correct. You are allowed to take LOC(expression), but the expression is on the routine local stack and the address is no longer valid after the routine exits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. The program ran for a couple of years before the memory access violations started to occur.Apparently a minor change in another routinecausedthe fn. GetOpenFileName(OFN) to overwrite a critical memory location. That location was the invalid address retained by OFN%LpStrFileTitle. The OFN structure is alsoGlobal.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page