digitalmars.D.learn - How to use Com object (it comes from other dll) in D? Thanks.
- FrankLike (38/38) Feb 22 2018 Hi,everyone,
- rikki cattermole (2/45) Feb 22 2018 Reminder classes in D are already references, no need for pointers to th...
Hi,everyone,
I want use the Com object (it comes from other dll) in D,but the
core.sys.windows.objidl:QueryInterface Fuction not work.
For example:
import core.sys.windows.windef;
import core.sys.windows.basetyps;
import core.sys.windows.uuid;
import core.sys.windows.com;
import
core.sys.windows.objbase:CoInitialize,CoUninitialize,CoCreateInstance;
import core.sys.windows.objidl;//:QueryInterface
import core.sys.windows.shlobj;//:IShellLink
import core.sys.windows.unknwn;
if(lpszLnkFileDir is null) return;
HRESULT hr;
IShellLink* pLink;
IPersistFile* ppf;
hr = CoCreateInstance(&CLSID_ShellLink,NULL,
CLSCTX_INPROC_SERVER,&IID_IShellLinkA,cast(PVOID*)&pLink);//cast(PVOID*)
writeln("CoCreateInstance ");
if(FAILED(hr))
{
writeln("FAILED(hr) ");
return ;
}
writeln(" pLink is "~pLink.to!string);
writeln("will QueryInterface hr is "~hr.to!string);
writeln(IID_IPersistFile.to!string);
hr = pLink.QueryInterface(&IID_IPersistFile,
cast(PVOID*)&ppf);// err <-
writeln("pLink.QueryInterface ");
-----------------------------------------------------
It stops in 'hr = pLink.QueryInterface(&IID_IPersistFile,
cast(PVOID*)&ppf);'
But the same c++ code is ok.
Who can help me?
Thanks.
Feb 22 2018
On 23/02/2018 2:12 AM, FrankLike wrote:
Hi,everyone,
I want use the Com object (it comes from other dll) in D,but the
core.sys.windows.objidl:QueryInterface Fuction not work.
For example:
import core.sys.windows.windef;
import core.sys.windows.basetyps;
import core.sys.windows.uuid;
import core.sys.windows.com;
import
core.sys.windows.objbase:CoInitialize,CoUninitialize,CoCreateInstance;
import core.sys.windows.objidl;//:QueryInterface
import core.sys.windows.shlobj;//:IShellLink
import core.sys.windows.unknwn;
if(lpszLnkFileDir is null) return;
HRESULT hr;
IShellLink* pLink;
IPersistFile* ppf;
hr = CoCreateInstance(&CLSID_ShellLink,NULL,
CLSCTX_INPROC_SERVER,&IID_IShellLinkA,cast(PVOID*)&pLink);//cast(PVOID*)
writeln("CoCreateInstance ");
if(FAILED(hr))
{
writeln("FAILED(hr) ");
return ;
}
writeln(" pLink is "~pLink.to!string);
writeln("will QueryInterface hr is "~hr.to!string);
writeln(IID_IPersistFile.to!string);
hr = pLink.QueryInterface(&IID_IPersistFile, cast(PVOID*)&ppf);//
err <-
writeln("pLink.QueryInterface ");
-----------------------------------------------------
It stops in 'hr = pLink.QueryInterface(&IID_IPersistFile,
cast(PVOID*)&ppf);'
But the same c++ code is ok.
Who can help me?
Thanks.
Reminder classes in D are already references, no need for pointers to them.
Feb 22 2018
On Thursday, 22 February 2018 at 13:15:11 UTC, rikki cattermole wrote:Reminder classes in D are already references, no need for pointers to them.Thank you,but get the same error. [D CODE] if(lpszLnkFileDir is null) return; HRESULT hr; IShellLink pLink; IPersistFile ppf; hr = CoCreateInstance(CLSID_ShellLink,NULL, CLSCTX_INPROC_SERVER,IID_IShellLinkA,pLink);//cast(PVOID*) DisplayInfoWork("CoCreateInstance "); if(FAILED(hr)) { DisplayInfoWork("FAILED(hr) "); return ; } DisplayInfoWork(" pLink is "~pLink.to!string); DisplayInfoWork("will QueryInterface hr is "~hr.to!string); DisplayInfoWork(IID_IPersistFile.to!string); hr = pLink.QueryInterface(IID_IPersistFile, ppf);// err <- DisplayInfoWork("pLink.QueryInterface "); -------------------log info-------------- CoCreateInstance pLink is 5E9954 will QueryInterface hr is 0 const(GUID)(267, 0, 0, [192, 0, 0, 0, 0, 0, 0, 70]) Access Violation -----------------------end---------------------------- Thanks.
Feb 22 2018
On Thursday, 22 February 2018 at 13:15:11 UTC, rikki cattermole wrote:On 23/02/2018 2:12 AM, FrankLike wrote:IShellLink* pLink; IPersistFile* ppf;Reminder classes in D are already references, no need for pointers to them.Ok,I delete the pointers ,It's ok! Thank you very much!
Feb 22 2018









FrankLike <1150015857 qq.com> 