Converting literal strings to pointers

John Kiro johnkirollos at yahoo.com
Sun Jan 7 07:32:04 PST 2007


Hello

Consider the win32 case of inserting a string in a listbox, I need to
convert a literal string to a pointer, and then to an int. I tried
the following 2 solutions:

SendMessage(hListBox,LB_ADDSTRING,0,cast(int)cast(void*)cast(char[])"My
String");


SendMessage(hListBox,LB_ADDSTRING,0,cast(int)std.string.toStringz("My
String"));

They both seem to work fine, but I expect that the 1st method is
better in terms of performance; All that is needed, is the compiler
to store the string somewhere, and simply pass its pointer to
SendMessage(). No realtime processing is needed. So does the triple-
cast in the first method really do it this way?
Obviously, for the 2nd method, there is some processing, in calling
toStringz at least.

On the other hand, casting directly to void* does not work:
SendMessage(hwndLBPrecision,LB_ADDSTRING,0,cast(int)cast(void*)"8 bit
PCM");

Error: "cannot convert string literal to void*"

(isn't there any method easier than doing 3 casts?)

Another question is, where can I post a request of generating
assembly code listing file? It would help in exploring the D language.

Thanks
John


More information about the Digitalmars-d-learn mailing list