Thread overview | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 20, 2011 toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Hi, I want something like: bool test(HDC dc, string str, int len, SIZE* s) { wchar[] wstr = toUTFz!(wchar*)str; GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s); ... I get the wchar[] stuff not working. I am struggling with pointer to array. Could you give some advice? Kind regards Andre |
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | > bool test(HDC dc, string str, int len, SIZE* s)
> {
> wchar[] wstr = toUTFz!(wchar*)str;
> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
toUTFz returns a wchar*, not a wchar[].
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>> bool test(HDC dc, string str, int len, SIZE* s)
>> {
>> wchar[] wstr = toUTFz!(wchar*)str;
>> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
>
> toUTFz returns a wchar*, not a wchar[].
I am not familiar with pointers. I know I have to
call toUTFz! and fill pointer value and length value
of the WinAPI from the result.
Do you have any suggestions how to achieve this API call?
Kind regards
Andre
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | On 09/20/2011 08:07 PM, Andre wrote:
> Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>
>>> bool test(HDC dc, string str, int len, SIZE* s)
>>> {
>>> wchar[] wstr = toUTFz!(wchar*)str;
>>> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
>>
>> toUTFz returns a wchar*, not a wchar[].
>
> I am not familiar with pointers. I know I have to
> call toUTFz! and fill pointer value and length value
> of the WinAPI from the result.
> Do you have any suggestions how to achieve this API call?
>
> Kind regards
> Andre
Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work:
bool test(HDC dc, string str, SIZE* s)
{
auto wstr = to!(wchar[])str;
GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
...
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | > Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work:
>
> bool test(HDC dc, string str, SIZE* s)
> {
> auto wstr = to!(wchar[])str;
> GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
> ...
It doesn't need to be null-terminated for that function.
Shouldn't you use to!wstring though?!
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On 09/20/2011 08:34 PM, Trass3r wrote:
>> Are you sure that the call requires the string to be null terminated?
>> I do not know that winapi function, but this might work:
>>
>> bool test(HDC dc, string str, SIZE* s)
>> {
>> auto wstr = to!(wchar[])str;
>> GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
>> ...
>
> It doesn't need to be null-terminated for that function.
> Shouldn't you use to!wstring though?!
It has to be copied anyway, so there is no real difference. I just did not know the signature of that function, and if it had been missing the const, wstring would not have worked. But if there is a const, wstring is indeed superior because shorter and clearer.
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On 09/20/2011 08:24 PM, Timon Gehr wrote:
> On 09/20/2011 08:07 PM, Andre wrote:
>> Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>>
>>>> bool test(HDC dc, string str, int len, SIZE* s)
>>>> {
>>>> wchar[] wstr = toUTFz!(wchar*)str;
>>>> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
>>>
>>> toUTFz returns a wchar*, not a wchar[].
>>
>> I am not familiar with pointers. I know I have to
>> call toUTFz! and fill pointer value and length value
>> of the WinAPI from the result.
>> Do you have any suggestions how to achieve this API call?
>>
>> Kind regards
>> Andre
>
> Are you sure that the call requires the string to be null terminated? I
> do not know that winapi function, but this might work:
>
> bool test(HDC dc, string str, SIZE* s)
> {
> auto wstr = to!(wchar[])str;
> GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
> ...
sry, should have read:
bool test(HDC dc, string str, SIZE* s)
{
auto wstr = to!(wchar[])(str);
GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
...
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Am Tue, 20 Sep 2011 20:44:40 +0200 schrieb Timon Gehr:
> On 09/20/2011 08:24 PM, Timon Gehr wrote:
>> On 09/20/2011 08:07 PM, Andre wrote:
>>> Am Tue, 20 Sep 2011 19:27:03 +0200 schrieb Trass3r:
>>>
>>>>> bool test(HDC dc, string str, int len, SIZE* s)
>>>>> {
>>>>> wchar[] wstr = toUTFz!(wchar*)str;
>>>>> GetTextExtentPoint32W(dc wstr.ptr, wstr.length, s);
>>>>
>>>> toUTFz returns a wchar*, not a wchar[].
>>>
>>> I am not familiar with pointers. I know I have to
>>> call toUTFz! and fill pointer value and length value
>>> of the WinAPI from the result.
>>> Do you have any suggestions how to achieve this API call?
>>>
>>> Kind regards
>>> Andre
>>
>> Are you sure that the call requires the string to be null terminated? I do not know that winapi function, but this might work:
>>
>> bool test(HDC dc, string str, SIZE* s)
>> {
>> auto wstr = to!(wchar[])str;
>> GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
>> ...
>
> sry, should have read:
>
> bool test(HDC dc, string str, SIZE* s)
> {
> auto wstr = to!(wchar[])(str);
> GetTextExtentPoint32W(dc, wstr.ptr, wstr.length, s);
> ...
thanks a lot for your help.
Kind regards
Andre
|
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre | Don't use length, use std.utf.count, ala: import std.utf; alias toUTFz!(const(wchar)*, string) toUTF16z; GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s); I like to keep that alias for my code since I was already using it beforehand. I'm pretty sure (ok maybe 80% sure) that GetTextExtentPoint32W asks for the count of characters and not code units. The WinAPI docs are a bit fuzzy when it comes to these things, some functions take the character count, others code-unit count. I've used this function in a D port of a Neatpad project a while ago. |
September 20, 2011 Re: toUTFz and WinAPI GetTextExtentPoint32W | ||||
---|---|---|---|---|
| ||||
On Tuesday, September 20, 2011 14:27 Andrej Mitrovic wrote:
> Don't use length, use std.utf.count, ala:
>
> import std.utf;
> alias toUTFz!(const(wchar)*, string) toUTF16z;
> GetTextExtentPoint32W(str.toUTF16z, std.utf.count(str), s);
Or std.range.walkLength. I don't know why we really have std.utf.count. I just calls walkLength anyway. I suspect that it's a function that predates walkLength and was made to use walkLength after walkLength was introduced. But it's kind of pointless now.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation