How to ensure string compatibility In D?

FrankLike 1150015857 at qq.com
Tue Jan 22 16:13:57 UTC 2019


On Tuesday, 22 January 2019 at 14:07:48 UTC, Olivier Pisano wrote:
> On Tuesday, 22 January 2019 at 13:55:30 UTC, FrankLike wrote:

> In D, there is only Unicode. The language doesn't manipulate 
> strings encoded in Windows local code-pages.

For example:

  std::wstring strTest(_T("d://"));
  UINT nRes = ::GetDriveType(strTest.c_str());

It can work in C++.
But:
//////////////////////////here is work 
ok///////////////////////////////////////
import std.stdio;
import std.string;
import std.conv;
import win32.winbase;

void main()
{
	string	strA_Z ="CD";
	auto type = GetDriveType((to!string(strA_Z[0])~":\\").toStringz);
	writeln(to!string(strA_Z[0])~" is ",type);
}
//////////////////////////here is work 
error//////////////////////////////////////////

import core.sys.windows.windows;
import std.stdio;
import std.string;
import std.conv;

void main()
{
	string	strA_Z ="CD";
	auto type = GetDriveType((to!string(strA_Z[0])~":\\").toStringz);
	writeln(to!string(strA_Z[0])~" is ",type);
}

////////////////////////////////////////////////////////////////////
  //---------------Error Info--------------------//
slicea2.d(9): Error: function 
core.sys.windows.winbase.GetDriveTypeW(const(wchar
)*) is not callable using argument types (immutable(char)*)
slicea2.d(9):        cannot pass argument toStringz(to(strA_Z[0]) 
~ ":\\") of ty
pe immutable(char)* to parameter const(wchar)*


Some error is "core.sys.windows.windows"?

Thank you.




More information about the Digitalmars-d-learn mailing list