?
Solved

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

Posted on 2005-03-17
4
Medium Priority
?
1,270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

770 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