473,382 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

casting from std::vector<_ty>

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<TCHARbuf(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.

Jul 10 '07 #1
2 2595
vi*******@gmail.com 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<TCHARbuf(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
Jul 10 '07 #2

<vi*******@gmail.comwrote in message
news:11**********************@e16g2000pri.googlegr oups.com...
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<TCHARbuf(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<TCHARbuf(2);
RegQueryValueEx(................ (BYTE*)&buf[0]));

Bye
Fabio
Jul 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Vince | last post by:
Hi, I have replaced my BYTE* by a vector<BYTE> and before I used to do : void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue) { BYTE *pTmp = NULL; pTmp = new BYTE;...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.