# Ruby and CoCreateInstance

**URL:** <https://www.ruby-forum.com/t/ruby-and-cocreateinstance/195955>\
**Category:** Ruby\
**Created:** [October 3, 2010, 10:15pm UTC](https://www.ruby-forum.com/t/ruby-and-cocreateinstance/195955 "2010-10-03T22:15:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomthom](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/thomthom/32/341_2.png) [@thomthom](https://www.ruby-forum.com/u/thomthom)\
**Post date:** [October 3, 2010, 10:15pm UTC](https://www.ruby-forum.com/t/ruby-and-cocreateinstance/195955/1 "2010-10-03T22:15:33Z")

</div>

I am writing plugins for Google SketchUp using their Ruby API. One of  
the common problems we (SketchUp scripters) have is that when a script  
is performing intensive operations it locks up the SketchUp UI and there  
is no way to see the progress of the current process.

What I would like to do is call the new Taskbar API in Windows7 in a  
hope that it will allow for a reactive progress indication.

I found this MSDN article:

> **[Windows 7 Taskbar APIs](https://learn.microsoft.com/en-us/archive/msdn-magazine/2009/brownfield/windows-7-taskbar-apis)**

The simplest example appear to be:

ITaskbarList3\* ptl;  
VERIFY(CoCreateInstance(  
CLSID\_TaskbarList, NULL, CLSCTX\_ALL,  
IID\_ITaskbarList3, (void\*\*)&ptl));

…

HWND hmainwnd;//Application main window  
ITaskbarList3\* ptl;//Created earlier

DWORD WINAPI DoWork(LPVOID) {  
ptl-\>SetProgressState(hmainwnd, TBPF\_NORMAL);  
for (int i = 0; i \< WorkToDo; ++i) {  
DoSomePartOfTheWork(i);  
ptl-\>SetProgressValue(hmainwnd, i, WorkToDo);  
}  
ptl-\>SetProgressState(hmainwnd, TBPF\_PAUSED);  
return 0;  
}

I have briefly toyed with some simple Win32API calls from Ruby - but  
this one I am unable to translate.

I am able to get the window handle of the SketchUp window, but how do I  
initiate these taskbar progressbar calls?

(SketchUp uses Ruby 1.8)

---

<div class="post-metadata">

**Author:** ![thomthom](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/thomthom/32/341_2.png) [@thomthom](https://www.ruby-forum.com/u/thomthom)\
**Post date:** [October 4, 2010, 3:24am UTC](https://www.ruby-forum.com/t/ruby-and-cocreateinstance/195955/2 "2010-10-04T03:24:49Z")

</div>

On Oct 3, 2010, at 13:15 , Thomas T. wrote:

> What I would like to do is call the new Taskbar API in Windows7 in a  
> hope that it will allow for a reactive progress indication.

Bad idea unless your plugin is supposed to run on only windoze (which  
would make us sad)… What you _should_ do is see if google sketchup API  
has their own progress API. If not, you should petition them for it.

---

<div class="post-metadata">

**Author:** ![thomthom](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/thomthom/32/341_2.png) [@thomthom](https://www.ruby-forum.com/u/thomthom)\
**Post date:** [October 4, 2010, 8:29am UTC](https://www.ruby-forum.com/t/ruby-and-cocreateinstance/195955/3 "2010-10-04T08:29:33Z")

</div>

Ryan D. wrote:

> On Oct 3, 2010, at 13:15 , Thomas T. wrote:
> 
> > What I would like to do is call the new Taskbar API in Windows7 in a  
> > hope that it will allow for a reactive progress indication.
> 
> Bad idea unless your plugin is supposed to run on only windoze (which  
> would make us sad)… What you _should_ do is see if google sketchup API  
> has their own progress API. If not, you should petition them for it.

It hasn’t. And we have petitioned this for years - literally.  
I know it’ll only be available for limited amount of users, but I’d like  
to try it out anyway. I don’t have the know-how to create a Win+OSX  
compatible custom progressbar implementation.  
At least I could offer an enhancement for some users.

From what I understand the CoCreateInstance is connecting to a COM  
object - which one in Ruby can do with Win32OLE.

WIN32OLE.new(CLSID\_TaskbarList3)

However, I get error message that the No such interface supported.  
When I look at the examples for a progressbar it appear that they are  
creating a Taskbar object with an ITaskbarList3 interface - but when I  
look at the Ruby source code the object it creates is hardcoded to  
IDispatch.
