Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
February 10, 2014 LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Hi, one hour trying to get a string out of LPOLESTR*. What is the correct command to get rgszNames as string? HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId){} With following command I only get the first character writeln(to!string(**rgszNames)); Kind regards André |
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | On 2/11/2014 1:32 AM, Andre wrote:
> Hi,
>
> one hour trying to get a string out of LPOLESTR*.
> What is the correct command to get rgszNames as string?
>
> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
> LCID lcid, DISPID* rgDispId){}
>
> With following command I only get the first character
> writeln(to!string(**rgszNames));
>
> Kind regards
> André
I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or some such, then LPOLESTR** is char**, so **LPOLESTR would be the first character in the string, and *LPOLESTR would be the char* string.
|
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | Am 10.02.2014 17:53, schrieb Mike Parker:
> On 2/11/2014 1:32 AM, Andre wrote:
>> Hi,
>>
>> one hour trying to get a string out of LPOLESTR*.
>> What is the correct command to get rgszNames as string?
>>
>> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
>> LCID lcid, DISPID* rgDispId){}
>>
>> With following command I only get the first character
>> writeln(to!string(**rgszNames));
>>
>> Kind regards
>> André
>
> I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or some
> such, then LPOLESTR** is char**, so **LPOLESTR would be the first
> character in the string, and *LPOLESTR would be the char* string.
to!string(*rgszNames) outputs a number instead of a name.
I think I am a step further, rgszNames is an array but also with to!string(*rgszNames[0]) only the first character of my method is given back.
Kind regards
André
|
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
> Am 10.02.2014 17:53, schrieb Mike Parker:
>> On 2/11/2014 1:32 AM, Andre wrote:
>>> Hi,
>>>
>>> one hour trying to get a string out of LPOLESTR*.
>>> What is the correct command to get rgszNames as string?
>>>
>>> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
>>> LCID lcid, DISPID* rgDispId){}
>>>
>>> With following command I only get the first character
>>> writeln(to!string(**rgszNames));
>>>
>>> Kind regards
>>> André
>>
>> I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or some
>> such, then LPOLESTR** is char**, so **LPOLESTR would be the first
>> character in the string, and *LPOLESTR would be the char* string.
>
>
> to!string(*rgszNames) outputs a number instead of a name.
> I think I am a step further, rgszNames is an array but also with to!string(*rgszNames[0]) only the first character of my method is given back.
>
> Kind regards
> André
std.conv.to knows about char* c-style strings, but not wchar* c-style strings like LPOLESTR. The number you are getting is the pointer to the first wchar.
I'm not sure what is the best way to do this as it's not something I've come across before, hopefully someone else will know.
|
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote: > On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote: >> Am 10.02.2014 17:53, schrieb Mike Parker: >>> On 2/11/2014 1:32 AM, Andre wrote: >>>> Hi, >>>> >>>> one hour trying to get a string out of LPOLESTR*. >>>> What is the correct command to get rgszNames as string? >>>> >>>> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, >>>> LCID lcid, DISPID* rgDispId){} >>>> >>>> With following command I only get the first character >>>> writeln(to!string(**rgszNames)); >>>> >>>> Kind regards >>>> André >>> >>> I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or some >>> such, then LPOLESTR** is char**, so **LPOLESTR would be the first >>> character in the string, and *LPOLESTR would be the char* string. >> >> >> to!string(*rgszNames) outputs a number instead of a name. >> I think I am a step further, rgszNames is an array but also with to!string(*rgszNames[0]) only the first character of my method is given back. >> >> Kind regards >> André > > std.conv.to knows about char* c-style strings, but not wchar* c-style strings like LPOLESTR. The number you are getting is the pointer to the first wchar. > > I'm not sure what is the best way to do this as it's not something I've come across before, hopefully someone else will know. https://d.puremagic.com/issues/show_bug.cgi?id=8384 |
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote:
> On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
>> Am 10.02.2014 17:53, schrieb Mike Parker:
>>> On 2/11/2014 1:32 AM, Andre wrote:
>>>> Hi,
>>>>
>>>> one hour trying to get a string out of LPOLESTR*.
>>>> What is the correct command to get rgszNames as string?
>>>>
>>>> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
>>>> LCID lcid, DISPID* rgDispId){}
>>>>
>>>> With following command I only get the first character
>>>> writeln(to!string(**rgszNames));
>>>>
>>>> Kind regards
>>>> André
>>>
>>> I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or some
>>> such, then LPOLESTR** is char**, so **LPOLESTR would be the first
>>> character in the string, and *LPOLESTR would be the char* string.
>>
>>
>> to!string(*rgszNames) outputs a number instead of a name.
>> I think I am a step further, rgszNames is an array but also with to!string(*rgszNames[0]) only the first character of my method is given back.
>>
>> Kind regards
>> André
>
> std.conv.to knows about char* c-style strings, but not wchar* c-style strings like LPOLESTR. The number you are getting is the pointer to the first wchar.
>
> I'm not sure what is the best way to do this as it's not something I've come across before, hopefully someone else will know.
I'm pretty sure you can get a wstring like this:
import core.stdc.wchar_ : wcslen;
auto rgszNamesWStr = to!wstring(rgszNames[0][0 .. wcslen(rgszNames[0])]);
Or if you're sure you don't have any wide characters:
auto rgszNamesStr = to!string(rgszNames[0][0 .. wcslen(rgszNames[0])]);
|
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | Am 10.02.2014 18:54, schrieb John Colvin:
> On Monday, 10 February 2014 at 17:29:33 UTC, John Colvin wrote:
>> On Monday, 10 February 2014 at 17:08:27 UTC, Andre wrote:
>>> Am 10.02.2014 17:53, schrieb Mike Parker:
>>>> On 2/11/2014 1:32 AM, Andre wrote:
>>>>> Hi,
>>>>>
>>>>> one hour trying to get a string out of LPOLESTR*.
>>>>> What is the correct command to get rgszNames as string?
>>>>>
>>>>> HRESULT GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
>>>>> LCID lcid, DISPID* rgDispId){}
>>>>>
>>>>> With following command I only get the first character
>>>>> writeln(to!string(**rgszNames));
>>>>>
>>>>> Kind regards
>>>>> André
>>>>
>>>> I would assume to!string(*rgszNames). Assuming LPOLESTR is char* or
>>>> some
>>>> such, then LPOLESTR** is char**, so **LPOLESTR would be the first
>>>> character in the string, and *LPOLESTR would be the char* string.
>>>
>>>
>>> to!string(*rgszNames) outputs a number instead of a name.
>>> I think I am a step further, rgszNames is an array but also with
>>> to!string(*rgszNames[0]) only the first character of my method is
>>> given back.
>>>
>>> Kind regards
>>> André
>>
>> std.conv.to knows about char* c-style strings, but not wchar* c-style
>> strings like LPOLESTR. The number you are getting is the pointer to
>> the first wchar.
>>
>> I'm not sure what is the best way to do this as it's not something
>> I've come across before, hopefully someone else will know.
>
> I'm pretty sure you can get a wstring like this:
>
> import core.stdc.wchar_ : wcslen;
> auto rgszNamesWStr = to!wstring(rgszNames[0][0 .. wcslen(rgszNames[0])]);
>
> Or if you're sure you don't have any wide characters:
>
> auto rgszNamesStr = to!string(rgszNames[0][0 .. wcslen(rgszNames[0])]);
Yes:) now it works.
Thanks a lot.
Kind regards
André
|
February 10, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Monday, 10 February 2014 at 17:54:14 UTC, John Colvin wrote:
> Or if you're sure you don't have any wide characters:
>
> auto rgszNamesStr = to!string(rgszNames[0][0 .. wcslen(rgszNames[0])]);
to!string on a well-formed UTF-16 string is always safe. It will transcode to UTF-8.
|
February 11, 2014 Re: LPOLESTR* to string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On Monday, 10 February 2014 at 22:06:14 UTC, Jakob Ovrum wrote:
> On Monday, 10 February 2014 at 17:54:14 UTC, John Colvin wrote:
>> Or if you're sure you don't have any wide characters:
>>
>> auto rgszNamesStr = to!string(rgszNames[0][0 .. wcslen(rgszNames[0])]);
>
> to!string on a well-formed UTF-16 string is always safe. It will transcode to UTF-8.
Awesome. Sorry for the misinformation, I don't really know a lot about phobos w.r.t. unicode. There was some talk of an article on it by someone, but I don't remember seeing it happen.
|
Copyright © 1999-2021 by the D Language Foundation