Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Create windows .lnk

Moderators: larsivi kris

Posted: 02/12/08 22:18:35

Trying to create a windows .lnk file, the typical way is to use IShellLink... but can;t find it under sys.win32 heres some c++ code i've used in the past...

void CreateShortcut(LPWSTR root, LPWSTR link)
{
	HRESULT hres;
	IShellLink *psl = NULL;
	IPersistFile *pPf = NULL;

	if (fileExists(link))
		return;

	try{
		hres = CoInitialize(NULL);
		hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);

		SetErrorMode(SEM_FAILCRITICALERRORS);
		try{
			hres = psl->SetPath(root);
		}catch(int e){}
		
		hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
		hres = pPf->Save(link, TRUE);
	}catch(int e) {}
	refreshDesktop();
}

-wyverex

Author Message

Posted: 02/13/08 06:30:48

I know nothing about COM but I thought it would be educational to dig into it a bit.

It looks like Phobos has some COM bindings in std/c/windows/com.d.

Prototypes for CoCreateInstance? and the like are found there.

I don't see any equivalent in Tango at the moment, but of course Tangobos includes it, so you can use it from there.

I can't seem to find many COM usage examples, but maybe the COM client-server example in dmd/samples/d (of compiler installation dir) may be of help. In particular dclient.d is calling a simple COM interface that is set up in chello.d.

Posted: 02/13/08 07:37:17

Tango does indeed have fairly weak support for COM programming, but the DWin project at dsource should have most relevant bindings presented in a Tango compatible manner.

Posted: 02/14/08 01:28:25 -- Modified: 02/14/08 05:27:26 by
baxissimo

Bjoern on the NG recommended looking at this for D + COM info:

http://www.dsource.org/projects/juno/wiki/ComProgramming

And John Reimer recommended the tango friendly:

http://www.dsource.org/projects/dwin