Jump to content

  • Log In with Google      Sign In   
  • Create Account


Change to Vector/Buffer Assignments?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 edb6377   Members   -  Reputation: 118

Like
0Likes
Like

Posted 21 July 2012 - 08:44 PM

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.

Sponsor:

#2 krippy2k8   Members   -  Reputation: 642

Like
3Likes
Like

Posted 22 July 2012 - 01:53 AM

lpNewBuffer = &vBuffer[0];

#3 edb6377   Members   -  Reputation: 118

Like
0Likes
Like

Posted 22 July 2012 - 02:15 AM

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 :)

#4 patrrr   Members   -  Reputation: 937

Like
0Likes
Like

Posted 22 July 2012 - 02:29 AM

That's ok as long as lpNewBuffer points to enough valid memory. But that behavior is different from what you used to have.

#5 edb6377   Members   -  Reputation: 118

Like
0Likes
Like

Posted 22 July 2012 - 02:31 AM

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

#6 krippy2k8   Members   -  Reputation: 642

Like
0Likes
Like

Posted 22 July 2012 - 06:35 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS