Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I need to store an IntPtr to windows registry. But when I try to read the value it is uint and I cannot convert it to IntPtr. So how can I convert uint --> IntPtr??
Posted
I need to store an IntPtr to windows registry.

I really don't think you do. You're not supposed to move pointers between processes let alone serialize them to the registry or a file. Why on earth would you want to do this?

 

Casting, its in the documentation, have a read.

Posted

I'm making an mp3 player for myself. And in order to get file association work I need to send the commandline arguments from every new instance of the program to the main instance. So that the main instance will play the opened file.

 

And this is how I accomplished it (in VB6 but now I making it again with C# 2005):

1) When the program is started for the first time (no other instances present) it will store the handle of the Communicator TextBox to a known place in registry.

 

2) When a new instance is started (another instance detected) it will read the handle of main instances Communicator from registry and then change Communicators text. This will raise the TextChange event in the main instance were I have the code that will play the right file.

 

PS: You might think this is cockeyed but at least it works. If you have a better solution for my problem please tell me.

Posted
PS: You might think this is cockeyed but at least it works. If you have a better solution for my problem please tell me.

 

The .net way of interprocess communication is Remoting, its a bit complicated at first but it can quite easily solve this probme, there are plenty of single-instance remoting examples out there if you look.

 

Handles are opaque handles, they involve pointers and as such are memory bound, you don't write memory locations to disk/registry because they change. What happens if your system crashes and the old handle value remains? You're not tryign to use an invalid handle, bad move. What happens if the handle is reallocated or moved, its now invalid. Handles are for in memory operations only.

 

In my single intance MP3player application i used an IMessageFilter registered a window message and used that to prevent multiple instances opening. I chose this method before i could do it in remoting but it still works its entirely safe and doesn't do silly things.

 

All sorts of things and all of them less silly than writing control handles to the registry.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...