ok, now I need to get an actual pointer to the data in a vector, I have to pass this to a function that only accepts raw pointers.
Printable View
ok, now I need to get an actual pointer to the data in a vector, I have to pass this to a function that only accepts raw pointers.
so if I have -
I can just passCode:string Foo;
and that will point to the characters int eh string themselves?Code:MyFunction((LPVOID)&Foo);
Not even remotely...
Example:
Code:MyFunction((LPCVOID)Foo.c_str());
It seems that string (currently) doesn't really allow non-constant access to the internal buffer (it is not required to be contiguous). You can use a vector<char> instead of string.
Pointers needn't be cast to void* in either C or C++ either.
Also there's no such thing as LPCVOID ;)
The only reason I put the cast was to assure that the OP was aware of the fact that std::string::c_str() is constant. Hence the LPCVOID.
There is no such thing as LPCVOID. I think it's just better to write const void*.
All those LP* defines/typedefs are evil anyway. They obfuscate code, makes it harder to read and more prone to errors.
Whether you like them or not, to say that they don't exist is absurd, and totally irrelevant to the thread, too.
I said "LPCVOID" didn't exist. Unless you typedef that one yourself, it doesn't exist in any common windows header.
OK, you're right. Sorry.
News to me. Never seen it before that I can remember.
But... I stand corrected.
Although, const void* is much easier to read and interpret rather than LPCVOID. I still stand fast to that.
And I grepped the wrong directory in my search.
i am hearing such comments from someone who uses cryptic (to me, at least :() #defines to make it even more difficult to understand template ridden code :(
but anyways such typedefs have advantages:
like:
Code:char* p, q r; // not all are pointers :(
LPSTR p, q, r; // all are pointers :)