toUTFz and WinAPI GetTextExtentPoint32W

Andre andre at s-e-a-p.de
Tue Sep 20 11:55:35 PDT 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


More information about the Digitalmars-d-learn mailing list