Jump to page: 1 2 3
Thread overview
toUTFz and WinAPI GetTextExtentPoint32W
Sep 20, 2011
Andre
Sep 20, 2011
Trass3r
Sep 20, 2011
Andre
Sep 20, 2011
Timon Gehr
Sep 20, 2011
Trass3r
Sep 20, 2011
Timon Gehr
Sep 20, 2011
Timon Gehr
Sep 20, 2011
Andre
Sep 20, 2011
Andrej Mitrovic
Sep 20, 2011
Jonathan M Davis
Sep 20, 2011
Andrej Mitrovic
Sep 20, 2011
Andrej Mitrovic
Sep 20, 2011
Jonathan M Davis
Sep 20, 2011
Christophe
Sep 21, 2011
Timon Gehr
Sep 21, 2011
Christophe
Sep 21, 2011
Timon Gehr
Sep 21, 2011
Dmitry Olshansky
Sep 21, 2011
Timon Gehr
Sep 21, 2011
Christophe
Sep 21, 2011
Dmitry Olshansky
Sep 21, 2011
zeljkog
Sep 21, 2011
Christophe Travert
Sep 21, 2011
zeljkog
Sep 20, 2011
Andrej Mitrovic
Sep 20, 2011
Jonathan M Davis
September 20, 2011
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
> 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
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
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
> 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
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
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
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
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
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
« First   ‹ Prev
1 2 3