Sign in to follow this  

Change to Vector/Buffer Assignments?

This topic is 1975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So in this conversion this is the only other VC++ 6==>VC++ 2005 issue i keep running into

Worked in VC++ 6
[source lang="cpp"]//////////////////////////////////////////////////////////////////////////////////////////
void Packet::GetBuffer
//////////////////////////////////////////////////////////////////////////////////////////
// Returns the packet's buffer and its size.
//
(
LPBYTE &lpNewBuffer, // The buffer to put the value to.
int &nBufferSize // The size of the buffer.
)
//////////////////////////////////////////////////////////////////////////////////////////
{
lpNewBuffer = vBuffer.begin();
nBufferSize = vBuffer.size();
}
[/source]

Now it returns the error

error C2440: '=' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'LPBYTE'
1> with
1> [
1> _Ty=BYTE,
1> _Alloc=std::allocator<BYTE>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Definition of LPBYTE
typedef BYTE far *LPBYTE;

Using the standard Vector.h from the VC includes.

I tried a few things like copy and what not.

Share this post


Link to post
Share on other sites
Hmm let me check that out.. I went more the std::copy(lpNewBuffer,lpNewBuffer+nBufferSize,vBuffer.begin()); direction easier to test once you get things to compile :)

Share this post


Link to post
Share on other sites
Yeah I am just getting ready to test the compile. I have both in there but I commented out my copy and put in the &vBuffer[0]; function

We will see how it goes ^^

Thank you

Share this post


Link to post
Share on other sites
The signature of your method and it's current implementation suggests that lpNewBuffer is not an allocated block of memory, and you want to extract a pointer to the buffer contained by vBuffer, along with the size. If that is the case, then std::copy will crash or corrupt memory unless you allocate new memory for lpNewBuffer within GetBuffer.

Share this post


Link to post
Share on other sites

This topic is 1975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this