I have an API call I need to pass a void* to to be filled by the API call --
since I want to return a std::string from the function I wrapped around the
API call I was hoping I could pass the std::string, one way or another, to
the API call. Well, neither operator[], nor, of course, data() are useable
for this. Perusing the documentation in Josutti's excellent book I find no
candidate function or operator -- is that correct or have I missed something?
If none exist I have to work around it by getting the length of the buffer
area needed, allocate a character array of that size, read the data,
construct a std::string from the buffer area and finally deallocate the
character array...
TIA. 4 2247
Hakan wrote: I have an API call I need to pass a void* to to be filled by the API call -- since I want to return a std::string from the function I wrapped around the API call I was hoping I could pass the std::string, one way or another, to the API call. Well, neither operator[], nor, of course, data() are useable for this. Perusing the documentation in Josutti's excellent book I find no candidate function or operator -- is that correct or have I missed something?
If none exist I have to work around it by getting the length of the buffer area needed, allocate a character array of that size, read the data, construct a std::string from the buffer area and finally deallocate the character array...
You give us little to go on.
Here is one idea.
#include <string>
#include <cassert>
void BustedApi( void *, int * length );
int const MAXIMUM_SIZE = 1024;
void MyWrapper( std::string & fill_me_in )
{
fill_me_in.resize( MAXIMUM_SIZE );
int length;
BustedApi( static_cast<void *>( &(fill_me_in[0]) ), & length );
assert( length <= MAXIMUM_SIZE );
fill_me_in.resize( length );
}
Hakan escribió: If none exist I have to work around it by getting the length of the buffer area needed, allocate a character array of that size, read the data, construct a std::string from the buffer area and finally deallocate the character array...
None exist, the standard does not guarantee that the string are stored
in a continuous block of memory.
You can use a vector of char instead of manually allocated memory.
Current implementations use a block of memory, and a revision of the
standard will make mandatory this.
Regards.
Thanks, worked great!
On 23 Nov 2003 06:54:37 GMT, Gianni Mariani wrote: Hakan wrote: I have an API call I need to pass a void* to to be filled by the API call -- since I want to return a std::string from the function I wrapped around the API call I was hoping I could pass the std::string, one way or another, to the API call. Well, neither operator[], nor, of course, data() are useable for this. Perusing the documentation in Josutti's excellent book I find no candidate function or operator -- is that correct or have I missed something?
If none exist I have to work around it by getting the length of the buffer area needed, allocate a character array of that size, read the data, construct a std::string from the buffer area and finally deallocate the character array...
You give us little to go on.
Here is one idea.
#include <string> #include <cassert>
void BustedApi( void *, int * length );
int const MAXIMUM_SIZE = 1024;
void MyWrapper( std::string & fill_me_in ) {
fill_me_in.resize( MAXIMUM_SIZE );
int length;
BustedApi( static_cast<void *>( &(fill_me_in[0]) ), & length );
assert( length <= MAXIMUM_SIZE );
fill_me_in.resize( length );
}
Hakan wrote: Thanks, worked great!
On 23 Nov 2003 06:54:37 GMT, Gianni Mariani wrote:
Hakan wrote:
I have an API call I need to pass a void* to to be filled by the API call -- since I want to return a std::string from the function I wrapped around the API call I was hoping I could pass the std::string, one way or another, to the API call. Well, neither operator[], nor, of course, data() are useable for this. Perusing the documentation in Josutti's excellent book I find no candidate function or operator -- is that correct or have I missed something?
If none exist I have to work around it by getting the length of the buffer area needed, allocate a character array of that size, read the data, construct a std::string from the buffer area and finally deallocate the character array...
You give us little to go on.
Here is one idea.
#include <string> #include <cassert>
void BustedApi( void *, int * length );
int const MAXIMUM_SIZE = 1024;
void MyWrapper( std::string & fill_me_in ) {
fill_me_in.resize( MAXIMUM_SIZE );
int length;
BustedApi( static_cast<void *>( &(fill_me_in[0]) ), & length );
assert( length <= MAXIMUM_SIZE );
fill_me_in.resize( length );
}
I believe that you need to read Julian Albo's post. I thought that the
upcoming "contiguous" requirement applied to strings as well as vectors.
In other words, this may not be portable across all compliant string
implementations - I have yet to meet one that this does not work for but
you'll find out soon enough. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Danny |
last post by:
HI again
Is there a nifty function in access that will:
1. return the amount of occurances of a small string within a larger
string?
this<br>is<br>a<br>test
would return 3 for <br>
|
by: Lauren Wilson |
last post by:
Access 2K
dim MyStr as string
What is the maximum amount of text or bytes that this variable can
store? Does anyone know?
|
by: timandsuzi36 |
last post by:
Here's the issue. Appreciate any help any Access gurus can offer.
I have a .NET WinForms application that needs to launch a Access DB
application used for generating Access Reports. That part...
|
by: Justnew |
last post by:
Hei All
Can some body help me here: I have a database name Customers, I a
trying to connect to SQL server through vb.net using asp.net webform.
I want to connect to the server programatically...
|
by: WStoreyII |
last post by:
I am making a asp page that will run on my computer by iis. But the problem
is the database in on a web server. I can not seem to get the connection to
work for it though here his the connection...
|
by: WebMatrix |
last post by:
Hello,
I have developed a web application that connects to 2 different database
servers. The connection strings with db username + password are stored in
web.config file.
After a code review,...
|
by: Orit |
last post by:
Hello .
Please find below my questions - I hope some of the ASP.NET experts of
this forum will answer to those beginner's questions :
My Web site should be able to work with either SQL Server...
|
by: Dean Slindee |
last post by:
VS2008, .NetFramework 3.5 SP1:
I have built a LINQ data access layer project. When the LINQ data context
was built over an existing SQL2005 database, the connection string for that
database was...
|
by: blunt |
last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some...
|
by: blunt |
last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |