Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

User-Contributed Tips for tlbimpd

This page contains user-contributed tips for Juno's Type Library Importer (tlbimpd):

tlbimpd may fail when it encounters certain types

This may not be a problem with the 0.2 version of tlbimpd. So far tlbimpd seems to be much more stable. Some hand-editing may still be required, though, such as that described here: digitalmars.D:44216, item (5).

Some work-arounds are available (as mentioned in topic #1755 and ticket:1), but even with the work-arounds some types may be unidentified by tlbimpd. The project leader is aware of these problems, and he intends to fix then when he determines the solution.

Import from a GUID identifying the type library

(The processing of some or all of these type libraries might require a patched version of tlbimpd as mentioned in topic #1755.)

If Microsoft Script Control 1.0 (MSScriptControl, msscript.ocx) is installed, tlbimpd will try to create a module for it when this command is issued:

tlbimpd.exe {0E59F1D2-1FBE-11D0-8FF2-00A0D10038BC}

Microsoft Internet Controls (SHDocVw, shdocvw.dll):

tlbimpd.exe {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}

TypeLib Information (TLI, tlbinf32.dll):

tlbimpd.exe {8B217740-717D-11CE-AB5B-D41203C10000}

Example

import std.stdio : writef, writefln;

import juno.com.core : toBStr;

import scripting;
/* scripting.d was generated by running a patched version of tlbimpd on
   Microsoft Scripting Runtime (scrrun.dll) */


void main()
{
   IFileSystem3 objFSO = FileSystemObject.coCreate!(IFileSystem3);
   ITextStream objOutFile;
   int hresult;


   wchar* fileName = toBStr("test_scripting.txt");
   hresult = objFSO.CreateTextFile(
     fileName,
     VARIANT_TRUE,
     VARIANT_FALSE,
     objOutFile);
   freeBStr(fileName);
   wchar* str = toBStr("testing 1, 2, 3...");
   objOutFile.WriteLine(str);
   objOutFile.Close();
   freeBStr(str);

   writefln("Test succeeded");

   objOutFile.Release();
   objFSO.Release();
}

Word Automation Example

import juno.com.core, office, word;

void main() {
    _Application application = Application.coCreate!(_Application)(CoClassContext.LocalServer);

    Documents documents;
    application.get_Documents(documents);

    VARIANT empty; // for empty arguments
    VARIANT templateName = VARIANT("template.dot");
    Document templateDoc;
    documents.Add(&templateName, &empty, &empty, templateDoc);
    templateName.clear();

    application.set_Visible(VARIANT_TRUE);

    Selection selection;
    application.get_Selection(selection);
    Find find;
    selection.get_Find(find);

    wchar* text = toBStr("find this text");
    find.set_Text(text);
    freeBStr(text);
    short dummy;
    find.Execute(&empty, &empty, &empty, &empty, &empty, &empty, &empty, &empty, 
      &empty, &empty, &empty, &empty, &empty, &empty, &empty, dummy);

    // And so on...

    // release our COM objects.
    find.Release();
    selection.Release();
    templateDoc.Release();
    documents.Release();
    application.Release();
} 

(from digitalmars.D:44227)

IE Automation Example (juno 0.3)

Author : http://bbs.yidabu.com/

import shdocvw;
import juno.base.native;		//Sleep
import juno.com.core;
static import win32.winuser;		//IsWindow
static import win32.windef;		//HWND

alias win32.windef.HWND HWND;
alias win32.winuser.IsWindow IsWindow;

// run tlbimpd.exe {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} /propput:put    to got type library
// build command: dmd ie.d shdocvw.d -O
// by yidabu, D China, http://bbs.yidabu.com/forum-10-1.html

pragma(lib,"juno.lib");

int main() {
	try
	{
		browserThread();
	}
	catch(Exception e)
	{
		printf("catch %.*s\n",e.msg);
	}
	return 0;
}


int browserThread()
{
	IWebBrowser2 m_pInetExplorer;
	try
	{
		//ExecutionContext.InProcessServer cause run time Access Violotion
		m_pInetExplorer = InternetExplorer.coCreate!(IWebBrowser2)(ExecutionContext.LocalServer);	
		m_pInetExplorer.put_Resizable(VARIANT_FALSE);
		m_pInetExplorer.put_AddressBar(VARIANT_FALSE);
		m_pInetExplorer.put_ToolBar(VARIANT_FALSE);
        m_pInetExplorer.put_MenuBar(VARIANT_FALSE);
        m_pInetExplorer.put_StatusBar(VARIANT_FALSE);
        m_pInetExplorer.put_Width(800);
        m_pInetExplorer.put_Height(600);
		m_pInetExplorer.put_Visible(VARIANT_TRUE);
        wchar* BStrURL = toBStr("http://bbs.yidabu.com/forum-10-1.html");
		
		VARIANT vars[4];
        auto hrie = m_pInetExplorer.Navigate(BStrURL, &vars[0], &vars[1], &vars[2], &vars[3]);
        freeBStr(BStrURL);		
		if (FAILED(hrie))
		{
			debug printf("failed navigate %0x \n ", hrie);
			return 1;
		}
		
		VARIANT_BOOL bBusy = VARIANT_TRUE;
		while(bBusy == VARIANT_TRUE)
		{
			Sleep(500);
			m_pInetExplorer.get_Busy(bBusy);
		}
		int hWnd;
		m_pInetExplorer.get_HWND (hWnd);
		while(IsWindow(cast(HWND)hWnd))
		{
			Sleep(500);
			m_pInetExplorer.get_HWND (hWnd);
		}		
					
	}//try
	
	catch(Exception e)
	{
		printf("catch %.*s\n",e.msg);
		return 1;
	}
	finally
	{
		if (m_pInetExplorer) 
		{
			m_pInetExplorer.Quit();	
			m_pInetExplorer.Release();	
		}
	}
	return 0;
}

Loading HTML content from stream (juno 0.3)

Author : http://bbs.yidabu.com/

/+ 
   Loading HTML content from a Stream 
   c++ version http://msdn2.microsoft.com/en-us/library/Aa752047.aspx 
   tlbimpd {EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B} /propput:put    to get shdocvw.d 
   tlbimpd mshtml.tlb  to get mshtml.d 
   by john, yidabu ( http://bbs.yidabu.com/forum-10-1.html ) 
+/ 

import dfl.application;      //for Application.doEvents(); 
import shdocvw; 
import mshtml; 
import std.date: getUTCtime; 
import std.stream : MemoryStream; 
import juno.com.client; 
import juno.com.core; 

pragma(lib,"juno.lib"); 
pragma(lib,"dfl_debug.lib");      //for doEvents() 

interface IPersistStreamInit : IPersist { 
//from regist {7FD52380-4E07-101B-AE2D-08002B2EC713} 
   static GUID IID = {0x7FD52380,0x4E07,0x101B,0xAE,0x2D,0x08,0x00,0x2B,0x2E,0xC7,0x13};    
   int IsDirty(); 
   int Load(IStream pStm); 
   int Save(IStream pStm, int fClearDirty); 
   int GetSizeMax(out ulong); 
   int InitNew(); 
} 


int main() { 
   try 
   { 
      browser(); 
   } 
   catch(Exception e) 
   { 
      printf("catch %.*s\n",e.msg); 
   } 
   return 0; 
} 


int browser(char[] url = "about:blank") 
{ 
   try 
   { 
      IWebBrowser2 ie = InternetExplorer.coCreate!(IWebBrowser2)(ExecutionContext.LocalServer); 
      scope(exit) 
      { 
         ie.Quit();    
         tryRelease(ie);              
      } 
        
      ie.put_Width(800); 
      ie.put_Height(600); 
      ie.put_Visible(VARIANT_TRUE); 

      wchar* BStrURL = toBStr(url); 
      VARIANT vars[4]; 
      auto hrie = ie.Navigate(BStrURL, &vars[0], &vars[1], &vars[2], &vars[3]); 
      freeBStr(BStrURL);        
        
      tagREADYSTATE rs; 
      while (rs != tagREADYSTATE.READYSTATE_COMPLETE) 
      { 
         Application.doEvents();// wait!  from dfl.application 
         ie.get_ReadyState(rs); 
      } 
        
      IDispatch doc; 
      hrie = ie.get_Document(doc);       
      assert(SUCCEEDED(hrie), "failed, get_Document"); 
      scope(exit) tryRelease(doc); 
             
      IPersistStreamInit ip = com_cast!(IPersistStreamInit)(doc); 
      assert(ip, "failed, IPersistStreamInit"); 
      scope(exit) tryRelease(ip); 

      auto ms = new MemoryStream; 
      ms.writeString("Hello, world!"); 
      ms.position = 0; 

      auto s = new COMStream(ms); 
      scope(exit) tryRelease(s); 

      ip.InitNew(); 
      ip.Load(s); 
    
      //for show the result 
      long t = getUTCtime(); 
      while(getUTCtime() - t < 5000) 
      { 
         Application.doEvents(); 
      }    
          
   }//try 
    
   catch(Exception e) 
   { 
      printf("catch %.*s\n",e.msg); 
      return 1; 
   } 
   return 0; 
} 

(from http://www.dsource.org/forums/viewtopic.php?p=15846)

ImageMagick? Automation Example

Author : http://bbs.yidabu.com/

/+
  Download ImageMagick from: 
	http://www.imagemagick.org/script/binary-releases.php#windows 
	http://www.imagemagick.org/download/binaries/ImageMagick-6.3.5-4-Q16-windows-static.exe 
	install it with ole support. 
		
	run:
	tlbimpd ImageMagickObject.dll /comments  
	to get the typle library: 
	
	by yidabu, D China, http://bbs.yidabu.com/forum-10-1.html
+/

import imagemagickobject;
import juno.com.core;
pragma(lib, "juno.lib");

void main()
{
	try
	{
		IMagickImage im = MagickImage.coCreate!(IMagickImage)(ExecutionContext.InProcessServer);
		assert(im, "failed im");
		scope(exit) tryRelease(im);
		string[] args = [r"D:\old.JPG", r"D:\new.gif"];
		SAFEARRAY* pa = toSafeArray(args);
		VARIANT v;
		auto hr =im.Convert(pa, v);
		SafeArrayDestroy(pa);		
		assert(SUCCEEDED(hr));		
	}
	catch(Exception e)
	{
		printf("catch %.*s\n", e.msg);
	}
}

(from http://www.dsource.org/forums/viewtopic.php?p=15886 )