Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pointer address

Pointer address

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
11 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Frigyes Nagy

    Hi! what is the smallest pointer address? I think a pointer is never 1,2 (or 3) to example : void DrawDFText( LPSTR a) UINT i = (UINT) a; if ( i > 2 ) { TCHAR szBuf[180]; wsprintf(szBuf, "address:%d ", a ); OutputDebugString( szBuf ); return; }; if ( i == 1 ) dothat1; if ( i == 2 ) dothat2; it's right? Regards! Frigyes :confused:

    M Offline
    M Offline
    Magnus Westin
    wrote on last edited by
    #2

    Hi Theoretically there is no smallest address a pointer can point to. In windows and c++ there is. But there is no need to know that value since you should never test against it. If you get a pointer like "LPSTR pStr" you should only check that its "!= NULL". Any thing else and you should assume that it’s a valid pointer. Its to job of the person giving you the pointer to be sure he gives you a valid one. Also since this is c++ you really shouldnt use char arrays. Either use STL std::string or MFC CString when you need strings. If you really want to know about how windows handles the memory and how pointers in it work. I can recomend the following book "Programming Applications for Microsoft Windows" by Jeffrey Richter[^] Magnus

    F 1 Reply Last reply
    0
    • M Magnus Westin

      Hi Theoretically there is no smallest address a pointer can point to. In windows and c++ there is. But there is no need to know that value since you should never test against it. If you get a pointer like "LPSTR pStr" you should only check that its "!= NULL". Any thing else and you should assume that it’s a valid pointer. Its to job of the person giving you the pointer to be sure he gives you a valid one. Also since this is c++ you really shouldnt use char arrays. Either use STL std::string or MFC CString when you need strings. If you really want to know about how windows handles the memory and how pointers in it work. I can recomend the following book "Programming Applications for Microsoft Windows" by Jeffrey Richter[^] Magnus

      F Offline
      F Offline
      Frigyes Nagy
      wrote on last edited by
      #3

      Hi Magnus! many thanks for your answer! > ... there is no need to know that value since you should never test it but I must test it, if I call my Drawtext procedure with 1 should start BeginPaint, if I call with 2 should start EndPaint, if NULL it's a error, otherwise should be draw the text from the pointer, (the procedure is a DLL procedure, and I can't use too many parameters) can be the address from one pointer 1 or 2 ? void __declspec(dllexport) DrawDFText( LPSTR a) { ... } and call like: DrawDFText(1); DrawDFText("line1"); DrawDFText("line2"); ... DrawDFText(2); Regards! Frigyes

      M 1 Reply Last reply
      0
      • F Frigyes Nagy

        Hi Magnus! many thanks for your answer! > ... there is no need to know that value since you should never test it but I must test it, if I call my Drawtext procedure with 1 should start BeginPaint, if I call with 2 should start EndPaint, if NULL it's a error, otherwise should be draw the text from the pointer, (the procedure is a DLL procedure, and I can't use too many parameters) can be the address from one pointer 1 or 2 ? void __declspec(dllexport) DrawDFText( LPSTR a) { ... } and call like: DrawDFText(1); DrawDFText("line1"); DrawDFText("line2"); ... DrawDFText(2); Regards! Frigyes

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #4

        Frigyes Nagy wrote:

        DrawDFText(1); DrawDFText("line1"); DrawDFText("line2"); ... DrawDFText(2)

        This is SO bad !!! Why don't you create a function BeginPaint, EndPaint to do that explicitly ?

        Frigyes Nagy wrote:

        the procedure is a DLL procedure, and I can't use too many parameter

        Huh ?


        Maximilien Lincourt Your Head A Splode - Strong Bad

        F 1 Reply Last reply
        0
        • M Maximilien

          Frigyes Nagy wrote:

          DrawDFText(1); DrawDFText("line1"); DrawDFText("line2"); ... DrawDFText(2)

          This is SO bad !!! Why don't you create a function BeginPaint, EndPaint to do that explicitly ?

          Frigyes Nagy wrote:

          the procedure is a DLL procedure, and I can't use too many parameter

          Huh ?


          Maximilien Lincourt Your Head A Splode - Strong Bad

          F Offline
          F Offline
          Frigyes Nagy
          wrote on last edited by
          #5

          Hi! I know, this is not really pretty, but it's works, and I never find any pointer address less then 1000. (this is one DLL for my DATAFLEX program, I don't like to export 3 procs, if I can make the same work with a ugly one) Regards and sorry my english Frigyes

          M 2 Replies Last reply
          0
          • F Frigyes Nagy

            Hi! I know, this is not really pretty, but it's works, and I never find any pointer address less then 1000. (this is one DLL for my DATAFLEX program, I don't like to export 3 procs, if I can make the same work with a ugly one) Regards and sorry my english Frigyes

            M Offline
            M Offline
            Maxwell Chen
            wrote on last edited by
            #6

            Frigyes Nagy wrote:

            I never find any pointer address less then 1000.

            There is a trick (a MACRO) found in the library to count the memory offset of the data member from the address of the struct which owns the data member. It takes a pointer with the address = 0.


            Maxwell Chen

            1 Reply Last reply
            0
            • F Frigyes Nagy

              Hi! what is the smallest pointer address? I think a pointer is never 1,2 (or 3) to example : void DrawDFText( LPSTR a) UINT i = (UINT) a; if ( i > 2 ) { TCHAR szBuf[180]; wsprintf(szBuf, "address:%d ", a ); OutputDebugString( szBuf ); return; }; if ( i == 1 ) dothat1; if ( i == 2 ) dothat2; it's right? Regards! Frigyes :confused:

              M Offline
              M Offline
              Maxwell Chen
              wrote on last edited by
              #7

              Frigyes Nagy wrote:

              wsprintf(szBuf, "address:%d ", a );

              A pointer should be something like UINT* pNum = &a; And, to observe the address of the pointer, you should do this way: sprintf(szBuf, "address: 0x%p \n", pNum);


              Maxwell Chen

              F 1 Reply Last reply
              0
              • F Frigyes Nagy

                Hi! I know, this is not really pretty, but it's works, and I never find any pointer address less then 1000. (this is one DLL for my DATAFLEX program, I don't like to export 3 procs, if I can make the same work with a ugly one) Regards and sorry my english Frigyes

                M Offline
                M Offline
                Maxwell Chen
                wrote on last edited by
                #8

                Frigyes Nagy wrote:

                I never find any pointer address less then 1000.

                Another instance to see the address less than 1000 is something like this way: class MyTool { public:   WORD MergeValue(BYTE hi, BYTE lo) {     WORD wT = hi;     return (wT << 8) | lo;   } }; // ...     MyTool* pTool = 0;     WORD v = pTool->MergeValue(0x43, 0x21);


                Maxwell Chen

                F 1 Reply Last reply
                0
                • M Maxwell Chen

                  Frigyes Nagy wrote:

                  wsprintf(szBuf, "address:%d ", a );

                  A pointer should be something like UINT* pNum = &a; And, to observe the address of the pointer, you should do this way: sprintf(szBuf, "address: 0x%p \n", pNum);


                  Maxwell Chen

                  F Offline
                  F Offline
                  Frigyes Nagy
                  wrote on last edited by
                  #9

                  Hi! thanks! but LPSTR is also a pointer to a null-terminated string This type is declared in Winnt.h as follows: typedef CHAR *LPSTR; void DrawDFText( LPSTR a) { sprintf(szBuf, "address: %d ", a); }; works for me... Regards Frigyes

                  M 1 Reply Last reply
                  0
                  • M Maxwell Chen

                    Frigyes Nagy wrote:

                    I never find any pointer address less then 1000.

                    Another instance to see the address less than 1000 is something like this way: class MyTool { public:   WORD MergeValue(BYTE hi, BYTE lo) {     WORD wT = hi;     return (wT << 8) | lo;   } }; // ...     MyTool* pTool = 0;     WORD v = pTool->MergeValue(0x43, 0x21);


                    Maxwell Chen

                    F Offline
                    F Offline
                    Frigyes Nagy
                    wrote on last edited by
                    #10

                    Hi! thanks! but this is to complex for me, I speak from pointers to a string, allocated with new, I can't imagine that they have address LT 1000, but ... Regards

                    1 Reply Last reply
                    0
                    • F Frigyes Nagy

                      Hi! thanks! but LPSTR is also a pointer to a null-terminated string This type is declared in Winnt.h as follows: typedef CHAR *LPSTR; void DrawDFText( LPSTR a) { sprintf(szBuf, "address: %d ", a); }; works for me... Regards Frigyes

                      M Offline
                      M Offline
                      Maxwell Chen
                      wrote on last edited by
                      #11

                      Frigyes Nagy wrote:

                      but LPSTR is also a pointer to a null-terminated string

                      ;P I did not notice the first line about the function prototype... :-D


                      Maxwell Chen

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups