Change to Vector/Buffer Assignments?

Started by
4 comments, last by krippy2k8 11 years, 9 months ago
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.
Advertisement
lpNewBuffer = &vBuffer[0];
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 :)
That's ok as long as lpNewBuffer points to enough valid memory. But that behavior is different from what you used to have.
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
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.

This topic is closed to new replies.

Advertisement