No announcement yet.

Difference : CodePtr & DataPtrr

  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference : CodePtr & DataPtrr

    Hi, Lance and all

    Can you explain me what the different is about codeptr and data
    When do I use them?


    Ps: Sorry for repeating Lance. I promise that doesn't happens it


  • #2
    Hi Stephane,

    First, thank you for responding to my messaage in the other thread!

    To answer your question: A data pointer and a code pointer are essentially just an address, stored as a 32-bit LONG or (more usually) a DWORD value. However, how they are used in an application is what sets them apart.

    A CodePtr is useful for directly calling a sub, function or label by it's address (ie, using CALL DWORD or GOSUB DWORD, etc). A classic example is a window or dialog callback - you usually pass a CODEPTR to Windows to inform it of the address of a callback routine. DDT simplifies this by enabling you to specify the CALLBACK FUNCTION directly by name, but API functions that expect to receive a callback address will need to be passed the address via the CODEPTR() function. Since the code segment of a protected mode application is read-only, a code pointer generally cannot be written to, but can be read from using conventional (data) pointers, PEEK/PEEK$, inline-assembler, etc. Reading {data} from a code pointer address is rarely (if ever) required by most programmers.

    A data pointer is quite different. A data pointer is a pointer to data that resides in the data segment of an application (process) address space. For example, obtaining the address of a dynamic string's data storage can be obtained with STRPTR(), and then the actual bytes that comprise the string can be read with, say, a BYTE POINTER or an indexed pointer. Data that resides at the target address of a data pointer can be read or written (provided you do not try to read or write beyond the range of the data at that address, or memory-corruption and/or a GPF fault will likely occur).

    I hope this explains things more clearly for you. When dealing with COM libraries, you will need a good understanding of these two types of pointers.

    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    mailto:[email protected]