FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Some char-based types must be ubyte-based types

 
Post new topic   Reply to topic     Forum Index -> Bindings
View previous topic :: View next topic  
Author Message
haru-s



Joined: 28 Mar 2009
Posts: 8
Location: Japan

PostPosted: Fri Oct 29, 2010 9:37 am    Post subject: Some char-based types must be ubyte-based types Reply with quote

Hi! Very Happy

The LPSTR is defined by "alias char* LPSTR".
But D's char is a utf-8 string, so LPSTR must be defined by "alias ubyte* LPSTR".
This problem is broadly applicable to other points of the Bindings.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sat Oct 30, 2010 2:22 am    Post subject: Reply with quote

That would cause a lot of casting between char* and ubyte* which would be very annoying and since all valid ASCII is valid UTF-8 I don't think it's any problem. "The first 128 characters of the Unicode character set (which correspond directly to the ASCII) use a single octet with the same binary value as in ASCII." - http://en.wikipedia.org/wiki/UTF-8
Back to top
View user's profile Send private message
haru-s



Joined: 28 Mar 2009
Posts: 8
Location: Japan

PostPosted: Mon Nov 01, 2010 8:53 am    Post subject: Reply with quote

Your ideas are right at a point of binary semantics.
But some types, such as LPSTR of WAVEHDR.lpData, don't have character semantics.

For example;

import win32.mmsystem;
char* buffer = new char[BUFFER_LENGTH];
WAVEHDR header;
header.lpData = buffer;

You will have a error message "invalid UTF-8 sequence", because any strings are validated.

import win32.mmsystem;
ubyte[] buffer = new ubyte[BUFFER_LENGTH];
WAVEHDR header;
header.lpData = cast(LPSTR)buffer;

If a type of WAVEHDR.lpData is ubyte*, you will not use cast(LPSTR).

However, the cause of this problem is that Win32 API use char* to binary sequence, probably...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Bindings All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group