Calling a cpp function from d
Daniel Kozák via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 16 06:13:26 PDT 2015
On Tue, 16 Jun 2015 12:26:45 +0000
C2D via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:
> Hi,
> I encountered the following error:
>
> Error: function files.SHGetFolderPath (void* hwndOwner, int
> nFolder, void* hToken, uint dwFlags, char* pszPath) is not
> callable using argument types (typeof(null), int, typeof(null),
> int, immutable(char)*)
>
> When I'm try to run this code:
> ...
> {
> import std.utf : toUTF8;
> static string cache;
>
> wchar[MAX_PATH + 2] buf;
>
> BOOL result = SHGetFolderPath(null, 0x23, null, 0, cache.ptr);
>
> return cache;
> }
> ...
> extern(Windows) HRESULT SHGetFolderPath(HWND hwndOwner, int
> nFolder, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
>
> I tried everything I know about D and CPP. What can be the
> solution?
Something like this should work
import std.string : fromStringz;
import std.traits : PointerTarget;
auto buf = new PointerTarget!LPTSTR[MAX_PATH + 2];
auto result = SHGetFolderPath(null, 0x23, null, 0, buf.ptr);
return fromStringz(buf);
More information about the Digitalmars-d-learn
mailing list