Calling a cpp function from d
John Chapman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 17 01:47:08 PDT 2015
On Tuesday, 16 June 2015 at 12:42:16 UTC, C2D wrote:
> On Tuesday, 16 June 2015 at 12:31:23 UTC, John Chapman wrote:
>> On Tuesday, 16 June 2015 at 12:26:45 UTC, C2D wrote:
>>> BOOL result = SHGetFolderPath(null, 0x23, null, 0, cache.ptr);
>>
>> That should be:
>>
>> BOOL result = SHGetFolderPath(null, 0x23, null, 0, buf.ptr);
>
> Thanks, but I'm still getting the same error -
Here's a working version:
import core.sys.windows.windows;
extern(Windows)
HRESULT SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE
hToken, DWORD dwFlags, LPWSTR pszPath);
string getFolderPath(int folder) {
import core.stdc.wchar_ : wcslen;
import std.utf : toUTF8;
wchar[MAX_PATH] buffer;
if (SHGetFolderPathW(null, folder, null, 0, buffer.ptr) >= 0)
return buffer[0 .. wcslen(buffer.ptr)].toUTF8();
return null;
}
void main() {
writeln(getFolderPath(0x23));
}
More information about the Digitalmars-d-learn
mailing list