Originally posted by Michael Mattias
View Post
Announcement
Collapse
No announcement yet.
Problem with Pointer to UDT
Collapse
X
-
What would also be really handy is to be able to see a block of memory "at" the pointer address
Code:FUNCTION Foo (address, size) AS STRING LOCAL S AS STRING, T AS STRING, Z AS LONG S = PEEK$ (address, size) FOR Z = 1 TO LEN (S) T = T & HEX$(ASC(S,Z,1),2) NEXT FUNCTION = T END FUNCTION .... ..... LOCAL W AS STRING W = Foo(Address, len) '[b]Watch 'W'[/b]
Leave a comment:
-
-
Originally posted by Michael Mattias View PostI would expect the IDE to correctly copy whatever it needs to copy to accomplish this.
What would also be really handy is to be able to see a block of memory "at" the pointer address.
Leave a comment:
-
-
>the main problem was between my ears.
???
> "Watch @DummpPtr.Value1", the prefix @ is not copied ...
Don't know about you, but were I to select this option, I would expect the IDE to correctly copy whatever it needs to copy to accomplish this.
Leave a comment:
-
-
Hello All,
I was just responding to PB's support people, when I figured out what the problem is.
When you highlight a variable like @gDummyPtr.Value1, right click the mouse and select "Watch @DummpPtr.Value1", the prefix @ is not copied to the “Watch Window” and consequently the correct value is not “watched”. Adding the @ enables a correct reading.
I probably didn’t notice this at first because I ran into the problem very late last night.
Once again, thank you for your help, even though the main problem was between my ears.
PatLast edited by Pat Bullman; 21 Apr 2008, 09:51 PM.
Leave a comment:
-
-
Originally posted by Kev Peel View PostSomeone correct me if I'm wrong.
Code:TYPE tMyUDT s AS STRING * 20 l AS LONG END TYPE GLOBAL myudt AS tmyudt '-------------------------------------- CALLBACK FUNCTION ShowDIALOG1Proc() LOCAL p AS tMyUDT PTR SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG MyUDT.s = "hello" MyUDT.l = 123 p = VARPTR(myudt)
Leave a comment:
-
-
Michael,
Yes, I've sent a report in to Support.
Kev,
I'm not aware of any limitations of the watch window. If there is, I'm sure PB will let me know.
Thanks for your assistance.
Pat
Leave a comment:
-
-
IIRC, I don't think the debugger supports indirection for the watch window. It will display the pointer address, not the data value. Someone correct me if I'm wrong.
Leave a comment:
-
-
it appears that PB's "Variable Watcher" used when debugging doesn't give a valid answer when dealing with pointers to UDT's.
That's only fair, as others have invested their time in the problem, too, and a little return on investment is in order.
MCM
Leave a comment:
-
-
Hello All,
Oh dear, it appears that PB's "Variable Watcher" used when debugging doesn't give a valid answer when dealing with pointers to UDT's. When I assigned the UDT values to local variables, I got the correct results.
So, for me, it's back to the drawing board. I have "Memory Access Violation" error somewhere else.
Sorry about all this
Pat
Leave a comment:
-
-
Eddy,
Here's the defintion:
Code:TYPE GridDetails hGridWnd AS DWORD ' Grid handle for this data DataPtr AS LONG ' Cell text data base pointer CellPtr AS LONG ' Absolute ptr to CellDetails ColPtr AS LONG ' Absolute ptr to ColDetails RowPtr AS LONG ' Absolute ptr to RowDetails Cols AS BIT * 30 IN DWORD ' Column count FixedCol AS BIT * 2 ' %NO_FIXED_COL, %FIXED_COL or ' %OUTLINE_COL ColWidth AS BIT * 31 IN DWORD ' Default Column width AdjustCol AS BIT * 1 ' %NO_ADJUST_WIDTH or ' %ALLOW_ADJUST_WIDTH Rows AS BIT * 31 IN DWORD ' Row Count FixedRow AS BIT * 1 ' %NO_FIXED_ROW OR %FIXED_ROW ' RowHeight AS BIT * 31 IN DWORD ' Row height in pixels AdjustRow AS BIT * 1 ' %NO_ADJUST_HEIGHT or ' %ALLOW_ADJUST_HEIGHT hFont AS DWORD ' Default is SYSTEM_FONT BackColour AS LONG ' Default to %COLOR_WINDOW ForeColour AS LONG ' Default to %COLOR_WINDOWTEXT DefaultFont AS DWORD ' Default font for cell data Alignment AS BIT * 31 IN DWORD ' %TEXT_LEFT_ALIGN or ' %TEXT_RIGHT_ALIGN or ' %TEXT_CENTRE_ALIGN DataType AS BIT * 1 ' %TEXT_DATA_TYPE Row AS BIT * 30 IN DWORD ' Selected Row GridCursor AS BIT * 2 ' %CURSOR_CELL, %CURSOR_ROW or ' %CURSOR_NONE Col AS BIT * 31 IN DWORD ' Selected Column GridLines AS BIT * 1 ' %SHOW_GRID_LINES OR END TYPE ' %NO_GRID_LINES GLOBAL gGd AS GridDetails ' LEN(GridDetails) = 64 '**************************************************************************************** ' Global Variables GLOBAL gGdPtr AS GridDetails POINTER ' Pointer to GridDetails
Pat
Leave a comment:
-
-
Pat,
Can you show us your 'GridDetails' definition ?
Kind regards
Leave a comment:
-
-
Michael,
ghHeap is set elsewhere. The comments for Malloc() says that it expects ghHeap to be a valid handle.
There's no test code, per se, although I've placed various bits of code trying to figure the problem out. I've been using PB's debug feature to test values - these's no problem with that is there?
Malloc appears to be returning correct values. BUT, the assigning to the UDT members doesn't make sensse.
For example, using the code I originally provided, all the UDT members have the same value, being the value of the UDT pointer "gGdPtr". Even if I comment out all the other allocations, the values are still there.
Eddy,
I haven't tried the dummy code out. I put that together just to show in a simple way what I was trying to do. If you like I can send you the real code to look at - to your private email address.
The more I look at it the more I think I've made a simple mistake here BUT for the life of me, I just can't see it.
Pat
Leave a comment:
-
-
Pat,
This displays 10, 20, 30 on my pc.
Does it not on yours ?
Code:#COMPILE EXE #DIM ALL TYPE Dummy Value1 AS LONG Value2 AS LONG Value3 AS LONG END TYPE GLOBAL Dumb AS dummy GLOBAL gDummyPtr AS dummy POINTER #IF NOT %DEF(%WINAPI) DECLARE FUNCTION GETPROCESSHEAP LIB "KERNEL32.DLL" ALIAS "GetProcessHeap" () AS LONG DECLARE FUNCTION HEAPALLOC LIB "KERNEL32.DLL" ALIAS "HeapAlloc" (BYVAL hHeap AS DWORD, BYVAL dwFlags AS DWORD, BYVAL dwBytes AS DWORD) AS DWORD DECLARE FUNCTION HEAPFREE LIB "KERNEL32.DLL" ALIAS "HeapFree" (BYVAL hHeap AS DWORD, BYVAL dwFlags AS DWORD, BYVAL lpMem AS DWORD) AS LONG DECLARE FUNCTION HEAPREALLOC LIB "KERNEL32.DLL" ALIAS "HeapReAlloc" (BYVAL hHeap AS DWORD, BYVAL dwFlags AS DWORD, BYVAL lpMem AS DWORD, BYVAL dwBytes AS DWORD) AS DWORD %HEAP_NO_SERIALIZE = &H00000001 %HEAP_GENERATE_EXCEPTIONS = &H00000004 %HEAP_ZERO_MEMORY = &H00000008 #ENDIF #IF NOT %DEF(%HEAP_ALLOC_FLAGS) ' See MSDN for options for flags. %HEAP_ALLOC_FLAGS = %HEAP_ZERO_MEMORY OR %HEAP_GENERATE_EXCEPTIONS %HEAP_FREE_FLAGS = 0& #ENDIF FUNCTION malloc (BYVAL NumberOfBytes AS LONG) AS DWORD ' returns: address of block of size NumberOfBytes FUNCTION = HEAPALLOC (GETPROCESSHEAP(), %HEAP_ALLOC_FLAGS, NumberOfBytes) END FUNCTION FUNCTION PBMAIN gDummyPtr = Malloc( SIZEOF( dummy ) ) 'gDummyPtr = VARPTR(Dumb) @gDummyPtr.Value1 = 10 @gDummyPtr.Value2 = 20 @gDummyPtr.Value3 = 30 msgbox STR$(@gDummyPtr.Value1) msgbox STR$(@gDummyPtr.Value2) MSGBOX STR$(@gDummyPtr.Value3) END FUNCTION
Leave a comment:
-
-
>IF ISFALSE ghHeap THEN
Where is your heap handle obtained?
Looks to me like malloc should be failing. Unless you are not showing us the code where you call HeapCreate.
BTW, my code was updated to include the 'private heap' versions of same.
(Look ma no globals.)
One more possibility... malloc and subsequent assignments are working perfectly but the code you are using to test the results (not shown) is in error.
MCM
Leave a comment:
-
-
Michael,
Compiler version?
The malloc function is something which I stole from you, as in:
Code:FUNCTION Malloc( lBytes AS LONG ) AS LONG '************************************************************************************** ' Purpose: This function allocates lBytes from the Heap using HeapAlloc() with the * ' flags %HEAP_ZERO_MEMORY and %HEAP_NO_SERIALIZE. It assumes ghHeap is a * ' valid handle from a call to HeapCreate(). * ' * ' Parameter: lBytes - The number of bytes to allocate. * ' * ' Returns: Pointer to allocated memory or Null on failure. * ' * '************************************************************************************** IF ISFALSE ghHeap THEN ' Check we have Heap pointer FUNCTION = 0 EXIT FUNCTION END IF FUNCTION = HeapAlloc( ghHeap, _ %HEAP_ZERO_MEMORY OR %HEAP_NO_SERIALIZE, _ lBytes ) END FUNCTION
Kev,
the code:
Code:GLOBAL Dumb AS dummy
has no purpose. A bad habit I picked, but I commented it out without seeing any change.
I agree that it's not likely to be a compiler problem, but I can't see what I've done wrong. I've used pointers to UDT's in PowerBASIC before without problems.
Pat
Leave a comment:
-
-
>gDummyPtr = Malloc( SIZEOF( dummy ) )
Compiler version?
SIZEOF(UDTName) was not supported until... 7x? Prior to that SIZEOF( ) required a VARIABLE as an argument. (In this case it could be gDummyPtr = malloc (SIZEOF(@gDummyPtr))
Also you might want to show us your malloc function.
MCM
Leave a comment:
-
-
Looks fine to me, although from your description it sounds as if "Dummy" is declared as a UNION. What about Malloc(), are you sure that's working correctly? What about "Dumb As Dummy", what is that used for?
I use pointers and dynamic allocation (ie. GlobalAlloc) constantly without any trouble, so I doubt it's a compiler problem.
Leave a comment:
-
-
Kev,
The following code illustrates simply what I'm trying to do:
Code:' In an include file: TYPE Dummy Value1 AS LONG Value2 AS LONG Value3 AS LONG END TYPE GLOBAL Dumb AS dummy GLOBAL gDummyPtr AS dummy POINTER ' In main code: gDummyPtr = Malloc( SIZEOF( dummy ) ) @gDummyPtr.Value1 = 10 @gDummyPtr.Value2 = 20 @gDummyPtr.Value3 = 30
Pat
Leave a comment:
-
Leave a comment: