Click here to Skip to main content
15,883,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: SQL server dynamic connection Pin
LongRange.Shooter18-Apr-06 18:13
LongRange.Shooter18-Apr-06 18:13 
GeneralRe: SQL server dynamic connection Pin
namiiiii18-Apr-06 20:49
namiiiii18-Apr-06 20:49 
GeneralRe: SQL server dynamic connection Pin
LongRange.Shooter19-Apr-06 2:36
LongRange.Shooter19-Apr-06 2:36 
GeneralRe: SQL server dynamic connection Pin
namiiiii19-Apr-06 8:56
namiiiii19-Apr-06 8:56 
GeneralRe: SQL server dynamic connection Pin
LongRange.Shooter20-Apr-06 6:51
LongRange.Shooter20-Apr-06 6:51 
Questioncant add a refference to the directx libreries Pin
yossi198118-Apr-06 11:48
yossi198118-Apr-06 11:48 
AnswerRe: cant add a refference to the directx libreries Pin
LongRange.Shooter19-Apr-06 2:56
LongRange.Shooter19-Apr-06 2:56 
QuestionProcessing Registered Windows Messages Pin
Steve Harding18-Apr-06 11:24
Steve Harding18-Apr-06 11:24 
Please bear with me, this posting is long. I hope somebody has some good ideas here.

My company has a C++ application (call it MyApp) that is allowed to be spawned by a number of 2nd applications. The 2nd application runs MyApp, then registers a special message type and sends the message. I don't have the source code for MyApp (It was before my time). Some ofthe 2nd applications are developed by other companies, but I have the source code for one of them. The 2nd application actually has 2 sections of code where it spawns MyApp. One of them uses:

UINT WM_MYMESSAGE = RegisterWindowMessage("My Special Message");<br />
WinExec("MyApp", SW_SHOW);<br />
SendMessage(HWND_BROADCAST, WM_MYMESSAGE, (WPARAM)m_hWnd, 0L);


the other uses CreateProcess instead of WinExec.

MyApp, when starting up, also registers the message type, then listens for the message and processes it when it is received. MyApp also makes sure that there is only one instance of itself running. If, during startup, it sees another instance out there, it brings the other instance to foreground, restores it if minimized, and then quietly kills itself. Therefore, MyApp receives and processes the message sucessfully if it was already running when the 2nd application sent the message, or if it was not yet running.

Cut to the present. We have recoded MyApp into C#/.NET environment, and we need this behavior to still work the same, without any change to the 2nd applications. MyApp is a Windows.Forms application, and one of the first things it does in Main() is call

static UInt32 WM_MYMESSAGE = RegisterWindowMessage("My Special Message");

next, it creates an instance of the main form:

Form myApp = new MyApp();

then, after performing other startup tasks, it runs it:

Application.Run(myApp);

The main form has an override of WndProc() which does pretty much this:

protected override void WndProc(ref Message m)<br />
{<br />
	if(m.Msg == WM_MYMESSAGE )<br />
	{<br />
		ProcessMyMessage( m.WParam,m.LParam);	<br />
	}<br />
	base.WndProc(ref m);<br />
}


This version of MyApp also prevents multiple instances of itself from running in the same way the C++ version did.

The problem I have is that the C# version correctly receives and processes the special message only when it is already running. When it is not running, it starts up, but the main form never receives the message. I am not sure at this point whether the delay in starting the app means that the message is already gone before MyApp is ready to receive it, or if there is something else going on. It is a fairly large application and takes about 5 to 7 seconds to start up on an average machine. Most of the applications that spawn MyApp are sending the message either immediately after spawning, or waiting at most 5 seconds before sending it. The C++ version works beautifully on fast or slow machines, but the C# version only works when it is already running (even on fast machines).

I have wrestled with this problem for awhile without success. If anybody can shed some light on this I would be most grateful.

Thanks for any help.

Steve
QuestionCasting Problem Pin
danchester18-Apr-06 9:47
danchester18-Apr-06 9:47 
AnswerRe: Casting Problem Pin
Guffa18-Apr-06 9:57
Guffa18-Apr-06 9:57 
Question"Value does not fall within the expected range" Pin
ahchoo18-Apr-06 7:10
ahchoo18-Apr-06 7:10 
AnswerRe: "Value does not fall within the expected range" Pin
LongRange.Shooter18-Apr-06 11:17
LongRange.Shooter18-Apr-06 11:17 
QuestionMessage="Value does not fall within the expected range." Pin
ahchoo18-Apr-06 7:07
ahchoo18-Apr-06 7:07 
AnswerRe: Message="Value does not fall within the expected range." Pin
Judah Gabriel Himango18-Apr-06 8:01
sponsorJudah Gabriel Himango18-Apr-06 8:01 
AnswerRe: Message="Value does not fall within the expected range." Pin
ahchoo18-Apr-06 8:26
ahchoo18-Apr-06 8:26 
QuestionI have Dundas Gauge for .NET Version 1.6 [for Visual Studio 2005 ] can I use it with .NET 2003 Pin
t4ure4n18-Apr-06 7:02
t4ure4n18-Apr-06 7:02 
AnswerRe: I have Dundas Gauge for .NET Version 1.6 [for Visual Studio 2005 ] can I use it with .NET 2003 Pin
Judah Gabriel Himango18-Apr-06 7:14
sponsorJudah Gabriel Himango18-Apr-06 7:14 
AnswerRe: I have Dundas Gauge for .NET Version 1.6 [for Visual Studio 2005 ] can I use it with .NET 2003 Pin
Troy Marchand19-Apr-06 4:00
sitebuilderTroy Marchand19-Apr-06 4:00 
QuestionWin32 dll conversion Pin
t4ure4n18-Apr-06 6:50
t4ure4n18-Apr-06 6:50 
AnswerRe: Win32 dll conversion Pin
Judah Gabriel Himango18-Apr-06 7:16
sponsorJudah Gabriel Himango18-Apr-06 7:16 
QuestionInheritance problem Pin
sharpone18-Apr-06 6:33
sharpone18-Apr-06 6:33 
AnswerRe: Inheritance problem Pin
Le centriste18-Apr-06 6:41
Le centriste18-Apr-06 6:41 
AnswerRe: Inheritance problem Pin
Ricardo Mendes18-Apr-06 6:42
Ricardo Mendes18-Apr-06 6:42 
QuestionWeb service request does not reach IIS Pin
Ricardo Mendes18-Apr-06 6:22
Ricardo Mendes18-Apr-06 6:22 
QuestionDynamically loadning Menu Items Pin
sjpjs18-Apr-06 5:52
sjpjs18-Apr-06 5:52 

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.