Click here to Skip to main content
15,905,071 members
Home / Discussions / C#
   

C#

 
GeneralRe: Outlook "like" Date Groupings Pin
pgraeve8-Jul-04 2:18
pgraeve8-Jul-04 2:18 
GeneralRe: Outlook "like" Date Groupings Pin
Gary Thom8-Jul-04 4:34
Gary Thom8-Jul-04 4:34 
Generalunderline Text in a Button Control Pin
isedf7-Jul-04 12:55
isedf7-Jul-04 12:55 
GeneralRe: underline Text in a Button Control Pin
Heath Stewart7-Jul-04 13:12
protectorHeath Stewart7-Jul-04 13:12 
Questionhow difficult does getting an instance by handle have to be? Pin
spazzman7-Jul-04 11:36
spazzman7-Jul-04 11:36 
AnswerRe: how difficult does getting an instance by handle have to be? Pin
Heath Stewart7-Jul-04 12:33
protectorHeath Stewart7-Jul-04 12:33 
AnswerRe: how difficult does getting an instance by handle have to be? Pin
MilesAhead11-Jul-04 16:44
MilesAhead11-Jul-04 16:44 
GeneralRe: how difficult does getting an instance by handle have to be? Pin
spazzman12-Jul-04 5:50
spazzman12-Jul-04 5:50 
The exact use is I need to send a string message from one instance to another (the string message being the file name the one instance wants the other one to open). This has to be done from the static Main() method.

The simplified code could be :

// this is the main "starting" class of my app
class MainForm()
{
public static void Main(string[] args)
{

// gets instance of this app already running
MainForm otherAppStance =
objCleverWidget.GetOtherInstance();

// sends message to other instance and quits
if (otherAppStance != null)
{
otherAppStance.TransferMessage(args[0]);
return;
}
}


public static void TransferMessage(string
strMessage)
{
MessageBox.Show(
"The other instance says" + strMessage
);
}

}


So what I really need to know is how to make
objCleverWidget.GetOtherInstance()

This will return the instance of the main Window Form from the other app instance, and all my problems will be solved.

That's the ideal solution. I haven't had any luck coding it, so I came up with a small but crude workaround - use P/Invoke's SendMessage. SendMessage is limited though - you can't send strings with it, just a message id in the form of an uint, and two pointers which I can't figure out properly. So I converted my string message into chars, converted each char to its uint equivalent, and sent those uints as message id's from one instance to another (obviously using some start- and end-message flags). It works and uses very little code, but I'm not too sure how well it will stand up to scrutiny. Oh, and it kinda destroys the recipient app's main form - you have to redraw after receiving messages. Doesn't sound too healthy ...

I've seen two other solutions online, one in VB (on codeproject infact) which I dont understand too well (VB + interop = brainmelt), and the other using Remoting, which raises questions of its own (assumes user pc will have network support). I was surprised by how much code was used in both solutions - my workaround was pretty light.

Anyway, associating an application with a file type is a pretty standard requirement, so I am a little puzzled by the lack of built-in functionality in the .Net framework for this kind of thing. If you can point out a practical solution that doesn't use networking, please let me know. I have reason to believe P/Invoke's SendMessage will do the trick, but I need to find out how to use it's two pointer parameters.

Thanks for your time!
GeneralRe: how difficult does getting an instance by handle have to be? Pin
MilesAhead12-Jul-04 6:55
MilesAhead12-Jul-04 6:55 
GeneralTreeView with ComboBoxes in TreeNodes Pin
theoutlander7-Jul-04 11:19
theoutlander7-Jul-04 11:19 
GeneralRe: TreeView with ComboBoxes in TreeNodes Pin
Heath Stewart7-Jul-04 12:38
protectorHeath Stewart7-Jul-04 12:38 
GeneralHowTo change color on statusbar Pin
QzRz7-Jul-04 9:54
QzRz7-Jul-04 9:54 
GeneralRe: HowTo change color on statusbar Pin
Heath Stewart7-Jul-04 12:50
protectorHeath Stewart7-Jul-04 12:50 
Generalproblem with SQLServer CE Pin
JulienR7-Jul-04 8:51
JulienR7-Jul-04 8:51 
GeneralRe: problem with SQLServer CE Pin
Heath Stewart7-Jul-04 12:56
protectorHeath Stewart7-Jul-04 12:56 
GeneralRe: problem with SQLServer CE Pin
Anonymous8-Jul-04 2:30
Anonymous8-Jul-04 2:30 
GeneralRe: problem with SQLServer CE Pin
Heath Stewart8-Jul-04 3:12
protectorHeath Stewart8-Jul-04 3:12 
GeneralCustom Listbox controls Pin
kam33mitch7-Jul-04 8:08
kam33mitch7-Jul-04 8:08 
GeneralRe: Custom Listbox controls Pin
Heath Stewart7-Jul-04 13:04
protectorHeath Stewart7-Jul-04 13:04 
GeneralRe: Custom Listbox controls Pin
kam33mitch7-Jul-04 14:40
kam33mitch7-Jul-04 14:40 
Questionbitmap to byte array ? Pin
kendao7-Jul-04 7:10
kendao7-Jul-04 7:10 
AnswerRe: bitmap to byte array ? Pin
Grimolfr7-Jul-04 8:05
Grimolfr7-Jul-04 8:05 
AnswerRe: bitmap to byte array ? Pin
Heath Stewart7-Jul-04 8:50
protectorHeath Stewart7-Jul-04 8:50 
GeneralProgress Bar in Status bar panel Pin
bouli7-Jul-04 4:38
bouli7-Jul-04 4:38 
GeneralRe: Progress Bar in Status bar panel Pin
Heath Stewart7-Jul-04 5:55
protectorHeath Stewart7-Jul-04 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.