?
Solved

converting LPBYTE to LPSTR (whats happening and is it efficient!?)

Posted on 2005-03-17
4
Medium Priority
?
1,338 Views
Last Modified: 2008-02-26
Hi,

I'm writing a wildcard ISAPI extension.

I want to point to the EXTEnSION_CONTROL_BLOCK data structure element lpbData.  To make it easy for me, as a C++ idiot, I am hoping to store it in a local LPSTR variable (this will mean I can use 'inbuilt' functions I am already comfortable with and local functions that I already have.

Basically this means I am using the line

pDataBody = (LPSTR) pecb->lpbData; // pecb->lpbData is a LPBYTE.

I realised as I was doing it that I don't know what this is really doing.  As pecb->lpbData  can potentially be very large I was hoping someone could and would tell me whether this is a reasonable (not necessarily perfect!) and efficient thing to do.  And if possible what is going on in the background.  i.e. As they are both pointer types is the same memory just being interpreted in a different way, or is the memory being copied to different locations for the 2 different types?

I hope this makes some sense ...

Thanks,

Ben.
0
Comment
Question by:gringogordo
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
novitiate earned 360 total points
ID: 13564281
>As they are both pointer types is the same memory just being interpreted in a different way
thats' correct.
>copied to different locations for the 2 different types
that's incorrect

Infact LPBYTE is unsigned char*
and LPSTR is char*

What you mean by I can use built-in functions, it its LPSTR,

if you they any string manipulation then it won't work, remember its still data not string, though you cast it to LPSTR.

_novi_
0
 
LVL 8

Expert Comment

by:novitiate
ID: 13564295
sorry for typos

What do you mean by, I can use built-in functions, if its LPSTR?

if your built-in functions are doing any string manipulation then it won't work, remember its still data not string, though you cast it to LPSTR.

_novi_
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 140 total points
ID: 13564315
Both types are pointers:

typedef char CHAR;
typedef CHAR* LPSTR;

typedef unsigned char *LPBYTE;

When you write:
pDataBody = (LPSTR) pecb->lpbData;

result code is copying of 32-bits pointer from one memory address to another. This is efficient and doesn't require copying of the whole memory block pointed by pDataBody.
0
 

Author Comment

by:gringogordo
ID: 13564519
Hi,

I hope the point split is acceptable!  

I felt novitiate  got there first but AlexFM was a little clearer on what was going on under the hood.


Thanks,

Ben.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question