Pointer address
-
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: -
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: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
-
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
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 -
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! FrigyesFrigyes 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
-
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
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
-
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
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
-
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: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
-
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
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
-
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
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 -
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
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
-
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 FrigyesFrigyes 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