Single instance applications

by Matt 7. August 2008 18:10

Scott’s Weekly Source Code just looked at handling single instance applications using Visual Basic’s built in support. Rather handy, and desperately easy.

But it’s not how the shell does it.

Windows already has a defined way to handle this. Historically, this was DDE, which involved broadcasting Windows messages to initiate a DDE conversation. Naturally not the best performing option (ever wonder why the IE options are so slow at closing? They broadcast the options change notification to all windows). Command line args are limited in length, and you've got the added cost of creating a new process for each new file to be passed through.

So, in Windows XP and later, Microsoft added support for registering your application as a COM IDropTarget for the file type. When the shell wants to send you some files, it creates an instance of the COM object and passes it an IDataObject that represents the shell items for the files. In fact, because it’s giving you shell items, you’re not limited to files, but can now accept anything that can be represented in the shell’s namespace – printers, files within zips, any other virtual item. Try that with your command line args.

Implementing it is, well, what you’d expect from COM.

You can, if you’re feeling a bit daft, implement an in-process COM object, get your dll loaded into explorer and perform your own inter process communication with your app. Kinda defeats the point, though.

Or, more appropriately, you can register your application as the out of process COM server for the object. And then you need to implement the standard COM goo of registering a class factory with CoRegisterObject, and dishing out your IDropTarget when asked for it.

The shell calls your IDropTarget and passes in the parameters. So it all happens in your first instance.

And there's the subtle difference - it's less about single instance applications, and more about passing data through to the currently running app. Almost the same thing, but not quite.

Now, this method isn't perfect - it's no good if you just double click the executable again, or call it on the command line. And it's not terribly useful if you want to pass arbitrary data through (a command line arg saying "stop").

That said, there's nothing stopping your second instance passing through a custom IDataObject data format to the existing IDropTarget...

So you can get single instance working with this method, and getting shell multi-select verb support for free can be useful, too.

As ever, MSDN has the skinny.

Now, if only there were some C# code. After all, who’d want to use a Visual Basic dll that already solved the problem?

Tags:

Comments (47) -

Jamie
Jamie
1/22/2011 6:02:55 AM #

This post topic is just great, loving it. i just couldn't stop reading this. I'm looking forward to your next posts, keep it up.

Reply

A Beautician
A Beautician
3/1/2011 6:34:49 AM #

Thanks for good information you shared, I believe these skincare tips will work for me as well.

Reply

host
host
5/11/2011 4:08:38 AM #

i hope you dont mind justin, i copied and pasted the tutorial which is great might i add. makes it so much easier for me to work from. by the way, any news or updates on gallery server pro yet?

Reply

best suv 2010
best suv 2010
7/20/2011 10:28:21 PM #

Per il tuo bambino scegli Moncler. Una scelta di capi, estivi ed invernali, eccezionali. Tuo figlio sarà sempre alla moda e potrà muoversi in totale comodità.

Reply

ipad features
ipad features
7/24/2011 6:11:15 AM #

Is it ok if I quote your article in my monthly newsletter? I would think this article suits my topic perfectly. Well ya, thanks for posting this article.

Reply

best iphone4 cases
best iphone4 cases
7/28/2011 2:28:37 AM #

Hi, just required you to know I he added your website to my Google bookmarks due to your layout. But seriously, I consider your net web-site has 1 in the freshest theme I??ve came across. It extremely helps make studying your blogging site significantly easier.

Reply

first direct loans
first direct loans
8/2/2011 8:59:06 PM #

Is it ok if I quote your article in my monthly newsletter? I would think this article suits my topic perfectly. Well ya, thanks for posting this article.

Reply

garage door automation
garage door automation
8/18/2011 6:01:26 AM #

Due to Innovative Door Solutions being an independent company we have the flexibility to offer you a range of solutions to meet your needs.

Reply

post office leeds
post office leeds
10/12/2011 8:25:42 PM #

What a perfect plot twist - Check my blog out if you want to lol. Great stuff regardless. Good show mate.

Reply

Stephane
Stephane
10/23/2011 12:02:35 PM #

Hello

nice post here may come back soon
Keep like this

Reply

Lisa
Lisa
10/23/2011 12:02:51 PM #

Hi

interresting, post here may come back soon
keep update

Reply

Stephane
Stephane
10/23/2011 9:32:05 PM #

hello there,

Nice, post here will came back
keep update

Reply

Btissam
Btissam
10/24/2011 12:25:21 AM #

Hi

interresting, post here
keep update

Reply

Robert
Robert
10/24/2011 12:27:11 AM #

Hi

interresting, post here may come back soon
Keep like this

Reply

proto
proto United States
10/27/2011 4:39:55 AM #

hi, this is my comment

Reply

Adirondack Boot
Adirondack Boot
10/30/2011 1:52:41 AM #

It actually took all my luck to meet you for just a moment in my lifetime.

Reply

monster dr dre
monster dr dre
10/30/2011 4:48:14 PM #

A person, be good to yourself; Two person, treat each other.

Reply

Donald
Donald
11/8/2011 6:18:29 PM #

The blog is absolutely fantastic. Lots of great information and inspiration, both of which we all need. Thanks

Reply

Corey
Corey
11/9/2011 12:45:18 AM #

Enjoyed this  this subject  article.

Reply

Philix
Philix United States
11/21/2015 12:05:47 AM #

superb website.

Reply

philix
philix United States
11/21/2015 11:28:24 AM #

Nice Website

Reply

Deena Hofer
Deena Hofer United States
1/15/2016 6:06:26 AM #

Congrats! This is such a great website, I know it will translate well into book form. Which is AWESOME!

Reply

Riley Laurino
Riley Laurino United States
1/15/2016 6:24:07 AM #

the style of keeping you connected with so many things of different types is awesome and you find it interesting everytime.

Reply

Solomon Trudics
Solomon Trudics United States
1/15/2016 6:44:22 AM #

AWESOME!Can't wait for that, will be something to want to accomplish day by day, to do something AWESOME!

Reply

Harriet Tenpas
Harriet Tenpas United States
1/15/2016 8:29:42 AM #

Congrats. And all of the items featured so far should be in the book.

Reply

Bea Sawin
Bea Sawin United States
1/15/2016 8:59:39 AM #

Congrats! So glad to see this site getting the recognition it deserves, the world can always use a little more awesome.

Reply

Olinda Difrancesco
Olinda Difrancesco United States
8/25/2016 4:12:49 AM #

Truly informative. Hopefully you can discuss more on the Smart homes design and technology using the recent obtainable equiptments

Reply

8 inch penis
8 inch penis United States
9/12/2018 5:27:47 PM #

I agree together with your conclusions and will eagerly glimpse ahead to your future updates.

Reply

Allena Aller
Allena Aller United States
9/30/2018 10:55:23 PM #

Need fake money ? only one place to go - http://456bosfo4pgtbrv3.onion - You must use TOR browser to access.Wild hacker crew

Reply

香港物業按揭. 無論您是首次置業或是換樓,工銀亞洲都能夠為您提供度身訂做的按揭貸款計劃,切合您的真正需要。 全面樓宇按揭服務. 一般按揭貸款計劃. 適合購買 ...

Reply

當蛋白線埋入皮膚後,皮下組織會將蛋白線視為異物,啟動異物反應,因此刺激膠原蛋白生長,且可促進新陳代謝,更新老化肌膚,所以客戶在術後也會發覺膚質變得較透亮白皙。膠原蛋白提拉線像一個“磁力線”一樣,將埋入處附近的肌肉和脂肪固定在原處,不會往下墜,其後會吸引皮下組織往蛋白線集中部位移動,就會逐漸產生提拉的緊實效果。也被用於填充美容的微整形,蛋白線材就好比蓋房子的鋼骨支架,先埋入皮膚當作基底結構,然後再注入好比水泥的玻尿酸或自體脂肪,因為有吸附力不易擴散,就可穩定固定住填充物,讓立體支撐力效果更好。

Reply

【保養】顏值大提升。洗出韓妞的國民水嫩肌♥韓國CREMORLAB水麗妍。絲絨雪花奶油泡泡洗顏慕斯 @ B2B崔咪TRAMY :: 痞客邦 ::  終於等到你啦~~學長~~~就是韓劇啦!!(我完全就是個韓劇迷....) 上星期因為過年,原本想說可以在家和''學長''談戀愛的, 結果, 因為過年竟然沒有更新阿~~ (好啦,我知道我唸過很多次了,但我      

Reply

Nova Hively
Nova Hively United States
10/15/2018 10:27:09 AM #

Cant thank these guys enough http://weightlostthatworks.com

Reply

解構
解構 United States
10/17/2018 1:26:25 PM #

替一般至乾性肌膚全天保濕。

Reply

#RBF 天生八婆相? - STYLE-TIPS.COM  近日網上番傳Resting Bitch Face,簡寫#RBF的用語,用來形容即...      

Reply

夢想成真!哈利波特世界現大阪 - STYLE-TIPS.COM  相信每位喜歡《哈利波特》的Fans,都曾幻想過如果現實中真的有一所魔法學校多好,...      

Reply

Johnie Chiesa
Johnie Chiesa United States
10/21/2018 6:53:39 AM #

test

Reply

大部份曾經生育或經歷更年期的女性都會面臨私密深處及外觀鬆弛問題,不單會影響自信心和伴侶的親密體驗,更有機會造成容易積菌及尿滲等健康問題。全港首部 Venus Fiore閨密儀 RF射頻 私密緊緻療程 專門針對私密各處包括陰道、陰唇及陰阜的專用治療頭,全面改善鬆弛問題;每個治療頭均採用一次性即棄治療蓋,確保衛生。還有ATC自動控溫綜合系統,讓療程的治療溫度被有效監控,療程自然更安全、更有效達至預期效果。全港首部 Venus Fiore閨密儀 RF射頻 私密緊緻療程Venus Fiore集中為女性私密之處提供最到位的呵護,專注重整陰道健康、收緊鬆弛陰唇和改善陰阜肥大問題。關鍵在於Venus Concept的王牌─糅合多極射頻與磁力脈衝的(MP)2磁頻專利技術,發揮提升細胞活躍度、重塑同時增加膠原蛋白、刺激毛細血管新生等作用,達至調整陰道濕潤度、pH值的效果,更重要的是顯著改善陰道彈性,使其回復年輕狀態。

Reply

Ashley Cole has warned Arsenal's Kieran Gibbs he has no intention of stepping aside and allowing the youngster to take his England spot. Cole will win his 87thcap against Denmark. Cole sticking around for England as Chelsea defender tells Gibbs to wait in line

Reply

Karri Hillsman
Karri Hillsman United States
12/11/2018 9:30:35 AM #

That bitch was cheating and thanks to wild hacker crew I found out http://oufkrhddoiik3xoy.onion - You must use TOR browser to access.Wild hacker crew

Reply

Eugenio Delaune
Eugenio Delaune United States
12/12/2018 1:52:09 AM #

Need to make fast cash ? - http://oufkrhddoiik3xoy.onion - You must use TOR browser to access.

Reply

Otto Nicholl
Otto Nicholl United States
1/20/2019 11:32:51 AM #

We are a group of volunteers and starting a new scheme in our community. Your site provided us with valuable information to work on. You have done a formidable job and our entire community will be thankful to you.|

Reply

Oswaldo Heinle
Oswaldo Heinle United States
1/20/2019 2:13:36 PM #

If you desire to get a great deal from this paragraph then you have to apply these strategies to your won webpage.|

Reply

Today, while I was at work, my cousin stole my iphone and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is now destroyed and she has 83 views. I know this is completely off topic but I had to share it with someone!

Reply

Dong
Dong United States
2/25/2019 8:22:46 AM #

The key to conquering the inconvenience and agony of this condition is to learn as much as possible about its causes and treatments seat cushions for chairs. This will help loosen up your muscles, and you will be ready for the day.

Reply

echovox system 3 hack download
echovox system 3 hack download United States
3/14/2019 6:27:49 PM #

I do accept as true with all the ideas you have presented for your post. They are really convincing and can definitely work. Still, the posts are too short for beginners. May you please lengthen them a little from next time? Thanks for the post.

Reply

fortnite download for windows 10
fortnite download for windows 10 United States
3/15/2019 12:15:16 AM #

There are certainly a number of particulars like that to take into consideration. That could be a nice point to convey up. I supply the thoughts above as basic inspiration however clearly there are questions like the one you convey up the place the most important thing will be working in honest good faith. I don?t know if finest practices have emerged around issues like that, but I'm sure that your job is clearly recognized as a fair game. Both boys and girls feel the influence of just a second’s pleasure, for the rest of their lives.

Reply

Add comment

biuquote
  • Comment
  • Preview
Loading

Rel=Me

Month List

RecentComments

Comment RSS