Newbie: can't manage some types...

Cleverson Casarin Uliana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 31 04:44:25 PDT 2016


Hello all, I'm trying to do two tasks which involves some type
conversion, and I'm having dificulties, probably because I haven't yet
understood well how such types works.

First, I wanted to convert UTF-8 strings to ansi, so it displays
correctly at the Windows command prompt. One function to do that is
"toMBSz" from std.windows.charset, which is declared as follows:
    const(char)* toMBSz(in char[] s, uint codePage = 0);

So, after some struggling, I managed to write the following code:

import std.stdio;
import std.windows.charset;
void main() {
string s = "Testando acentuação";
auto r = toMBSz (s, 1);
writeln (r[0..19]);
}

Although the above code works, I have an impression that it could be
more elegant and concise, but don't know how to improve it...

I'd also like to play a sound file, so tried to use the function
"PlaySound" from core.sys.windows.mmsystem, declared as follows:
BOOL PlaySoundW(LPCWSTR, HMODULE, DWORD);

According to some error messages I receive, the first parameter is of
type const(char)*, which corresponds to the sound file name, but I
just can't figure out how to convert the string (or a char array) to
that type... Could you please give some snippet example? The closest I
have come, which doesn't compile at all, is as follows:
import core.sys.windows.mmsystem;

void main() {
char[] f = "C:/base/portavox/som/_fon102.wav".dup;
const(wchar)* arq = cast(const(wchar)*)&f;
void* nulo;
uint SND_FILENAME;
PlaySound (arq, nulo, SND_FILENAME);
}

Thank you,
Cleverson



More information about the Digitalmars-d-learn mailing list