casting from std::vector<_ty>

V

vikasetrx

any idea how we can cast from std::vector types.

e.g.. i am using the win32 API RegQueryValueEx().

the out buffer it takes should be LPBYTE.

i used the code as shown,

TCHAR * buf = new TCHAR[2];

RegQueryValueEx(................ (BYTE*)buf));

now i want to use a vector instead of TCHAR*.. so what i did is,

std::vector<TCHAR> buf(2);

now i want to use this in the RegQueryValueEx() API, how do i cast it
to LPBYTE... i tried using const_iterator.... the cast doesn't produce
warning or error, but the results are not as desired.
 
M

Michael DOUBEZ

(e-mail address removed) a écrit :
any idea how we can cast from std::vector types.

e.g.. i am using the win32 API RegQueryValueEx().

the out buffer it takes should be LPBYTE.

i used the code as shown,

TCHAR * buf = new TCHAR[2];

RegQueryValueEx(................ (BYTE*)buf));

now i want to use a vector instead of TCHAR*.. so what i did is,

std::vector<TCHAR> buf(2);

now i want to use this in the RegQueryValueEx() API, how do i cast it
to LPBYTE... i tried using const_iterator.... the cast doesn't produce
warning or error, but the results are not as desired.

I don't known about LPBYTE but perhaps it is what you want :

RegQueryValueEx(................ static_cast<LPBYTE*>(&buf.front()) );

Michael
 
F

FabioAng

any idea how we can cast from std::vector types.

e.g.. i am using the win32 API RegQueryValueEx().

the out buffer it takes should be LPBYTE.

i used the code as shown,

TCHAR * buf = new TCHAR[2];

RegQueryValueEx(................ (BYTE*)buf));

now i want to use a vector instead of TCHAR*.. so what i did is,

std::vector<TCHAR> buf(2);

now i want to use this in the RegQueryValueEx() API, how do i cast it
to LPBYTE... i tried using const_iterator.... the cast doesn't produce
warning or error, but the results are not as desired.
See Effective STL book.
Item 16: Know how to pass vector and string data to legacy APIs

std::vector<TCHAR> buf(2);
RegQueryValueEx(................ (BYTE*)&buf[0]));

Bye
Fabio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top