Click here to Skip to main content
16,004,094 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralAbout ICOPYHOOK Interface... Pin
ZarrinPour14-Apr-04 10:04
ZarrinPour14-Apr-04 10:04 
GeneralRe: About ICOPYHOOK Interface... Pin
vcplusplus14-Apr-04 10:42
vcplusplus14-Apr-04 10:42 
GeneralWINVER related question Pin
Maarten Kools14-Apr-04 9:47
professionalMaarten Kools14-Apr-04 9:47 
GeneralRe: WINVER related question Pin
Joe Woodbury14-Apr-04 10:29
professionalJoe Woodbury14-Apr-04 10:29 
GeneralRe: WINVER related question Pin
Maarten Kools14-Apr-04 10:31
professionalMaarten Kools14-Apr-04 10:31 
GeneralRe: WINVER related question Pin
Joe Woodbury14-Apr-04 13:10
professionalJoe Woodbury14-Apr-04 13:10 
GeneralRe: WINVER related question Pin
Maarten Kools14-Apr-04 13:40
professionalMaarten Kools14-Apr-04 13:40 
Generalreinterpret_cast question Pin
ursus zeta14-Apr-04 9:32
ursus zeta14-Apr-04 9:32 
I am a novice at programming and am working my way through Feng Yuan's book "Windows Graphics Programming". It's great stuff and he includes extensive development of useful graphics classes that can be used in your programs.
Anyway, I'm curious as to why he doesn't use the reinterpret_cast operator in his code when converting pointers. Typically he does something like this:
<br />
// query GDI for image size<br />
GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, NULL, (BITMAPINFO *) & dibinfo, DIB_RGB_COLORS);<br />
int nInfoSize  = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * GetDIBColorCount(dibinfo.bmiHeader);<br />
int nTotalSize = nInfoSize + GetDIBPixelSize(dibinfo.bmiHeader);<br />
BYTE * pDIB = new BYTE[nTotalSize];<br />
if ( pDIB )<br />
{<br />
memcpy(pDIB, & dibinfo, nInfoSize);<br />
if ( ddbinfo.bmHeight != GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, pDIB + nInfoSize, (BITMAPINFO *) pDIB, DIB_RGB_COLORS) )<br />
{<br />
delete [] pDIB;<br />
pDIB = NULL;<br />
}<br />
}<br />
ReleaseDC(NULL, hDC);<br />
return (BITMAPINFO *) pDIB;<br />

This is a segment from one of his functions that converts a Device Dependent Bitmap to a DIB (Device Independent Bitmap) which he will later save to file in the Bitmap format. The recasting of pointers is a critical technique to this operation, because when he makes a call later in his program to WriteFile he just supplies the pointer as the parameter.
Anyway, this is from the documantation at the MSDN site:
C/C++ Language Reference
reinterpret_cast Operator
reinterpret_cast < type-id > ( expression )
The reinterpret_cast operator allows any pointer to be converted into any other pointer type. It also allows any integral type to be converted into any pointer type and vice versa. Misuse of the reinterpret_cast operator can easily be unsafe. Unless the desired conversion is inherently low-level, you should use one of the other cast operators.

I's appreciate any enlightenment on the subject that you can provide, as pointer casting appears to be an operation that could possibly be corrupted. I'm thinking that a special operator could be designed that would be better suited to these types of code transitions.
GeneralRe: reinterpret_cast question Pin
Maarten Kools14-Apr-04 9:40
professionalMaarten Kools14-Apr-04 9:40 
GeneralRe: reinterpret_cast question Pin
ursus zeta14-Apr-04 9:54
ursus zeta14-Apr-04 9:54 
GeneralRe: reinterpret_cast question Pin
Maarten Kools14-Apr-04 10:15
professionalMaarten Kools14-Apr-04 10:15 
GeneralRe: reinterpret_cast question Pin
Gary R. Wheeler14-Apr-04 13:38
Gary R. Wheeler14-Apr-04 13:38 
GeneralRe: reinterpret_cast question Pin
Paul Ranson14-Apr-04 11:08
Paul Ranson14-Apr-04 11:08 
GeneralThanks for info Pin
ursus zeta14-Apr-04 12:39
ursus zeta14-Apr-04 12:39 
QuestionHow do I display image data? Pin
Member 15847214-Apr-04 9:22
Member 15847214-Apr-04 9:22 
AnswerRe: How do I display image data? Pin
Mike Dimmick14-Apr-04 9:30
Mike Dimmick14-Apr-04 9:30 
GeneralRe: How do I display image data? Pin
Member 15847214-Apr-04 11:17
Member 15847214-Apr-04 11:17 
GeneralDocument/View question Pin
stelitsisan14-Apr-04 8:46
stelitsisan14-Apr-04 8:46 
GeneralLinker error only in release mode Pin
doctorpi14-Apr-04 8:38
doctorpi14-Apr-04 8:38 
GeneralRe: Linker error only in release mode Pin
doctorpi14-Apr-04 8:47
doctorpi14-Apr-04 8:47 
GeneralRe: Linker error only in release mode Pin
Mike Dimmick14-Apr-04 9:32
Mike Dimmick14-Apr-04 9:32 
GeneralDAO Debug and Release Pin
Rome Singh14-Apr-04 8:18
Rome Singh14-Apr-04 8:18 
GeneralDependency Walker Pin
pcdev14-Apr-04 8:04
pcdev14-Apr-04 8:04 
GeneralRe: Dependency Walker Pin
Mike Dimmick14-Apr-04 9:43
Mike Dimmick14-Apr-04 9:43 
GeneralHaving problems with this code need direction Pin
jss67200114-Apr-04 8:02
jss67200114-Apr-04 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.