473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

DLL with message loop

Hi
I want to re-write a C# application(exe) to C# DLL. This application
starts by

myApp.MainApplication app = new myApp.MainApplication();
Application.Idle += new
EventHandler(app.myApp.OnApplicationIdle);
Application.Run(app);

But when I move all the code into a DLL and try to call the DLL from
a test program by
myApp.MainApplication.Main(args);

I got next error
"Starting a second message loop on a single thread is not a valid
operation. Use Form.ShowDialog instead."

I tried to change
Application.Run(app);
To
app.ShowDialog();

Error was gone but I can't get mouse event. Application was not
runing correctly.

I changed my test porgram
Application.Run(new form1());
to
Form myform = new Form1();
myform.ShowDialog();

Same error message was returned.

Anyone has any idea about it, or any related infomation is helpfull.
Thanks!

Mar 27 '07 #1
4 7400
I think maybe you neednot a message loop in your dll(managed),
Only class definition (forms included) is present in you dll ,.

And Application.Run() or app.ShowDialog() should be done in the consumer
dll(exe project).

mostly likes:

//firstly,you should add refrence of YourDll.dll to the exe-project.

//in exe project
Application.Run(new YourDll.YourForm());

If the description above is not what your want, pls post your consumer code
which invoke dll.

gshzheng
20070328
<zh*****@gmail.com>
??????:11**********************@l77g2000hsb.google groups.com...
Hi
I want to re-write a C# application(exe) to C# DLL. This application
starts by

myApp.MainApplication app = new myApp.MainApplication();
Application.Idle += new
EventHandler(app.myApp.OnApplicationIdle);
Application.Run(app);

But when I move all the code into a DLL and try to call the DLL from
a test program by
myApp.MainApplication.Main(args);

I got next error
"Starting a second message loop on a single thread is not a valid
operation. Use Form.ShowDialog instead."

I tried to change
Application.Run(app);
To
app.ShowDialog();

Error was gone but I can't get mouse event. Application was not
runing correctly.

I changed my test porgram
Application.Run(new form1());
to
Form myform = new Form1();
myform.ShowDialog();

Same error message was returned.

Anyone has any idea about it, or any related infomation is helpfull.
Thanks!


Mar 28 '07 #2
Thank you for helping!
I change my consumer code as you suggested. like next
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace myApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new myApp.MainApplication());
}
}

The program started but DLL is not working correctly. Mouse event can
not be handled.

MainApplication was define as

public class MainApplication : System.Windows.Forms.Form, IGlobe

What wrong with it? I am new programmer in C#, any suggestion is very
wellcome!

Mar 29 '07 #3
>The program started but DLL is not working correctly. Mouse event can
>not be handled.
Are you sure "mouse event can not be handled"?
You just add a button on the form, try test the click event.
The form class is nothing but a class can be visible.
Also the form class in other dll is nothing but needing add reference.

Maybe firstly,for the sake of find the trouble,you should drag the form
class to exe-project,not using a separate dll.
where the form class is separate or not, nothing should be different.

<zh*****@gmail.com>
??????:11**********************@n76g2000hsh.google groups.com...
Thank you for helping!
I change my consumer code as you suggested. like next
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace myApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new myApp.MainApplication());
}
}

The program started but DLL is not working correctly. Mouse event can
not be handled.

MainApplication was define as

public class MainApplication : System.Windows.Forms.Form, IGlobe

What wrong with it? I am new programmer in C#, any suggestion is very
wellcome!


Mar 29 '07 #4
Thank you for answer!
>Are you sure "mouse event can not be handled"?
Next is the error that I got

---------------------------------------------------------------------------------------------------------------------------------------------------------
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance
of an object.
at myApp.myWindow.OnMouseMove(MouseEventArgs e) in E:\myApp
\myWindow.cs:line 1610
at System.Windows.Forms.Control.WmMouseMove(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
----------------------------------------------------------------------------------------------------------------------------------------------------------

Maybe it is a initial problem.

Now I am trying to move form part to exe project as you suggested.
Mar 29 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cantankerous Old Git | last post by:
I am trying to write a program that I hope to get working as a command-line app to start with, and then eventually use a windows service wrapper to call it as a service. Its purpose is to attach...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
8
by: Brian Keating EI9FXB | last post by:
Would I be correct in saying that the only way to get a user message into a Windows form would be to use P/Invoke with Message? Of is there some part of the .NET API that I am totally un aware...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
3
by: mccoyn | last post by:
When I have a long process to run I can create a new thread to run it and create a modal dialog on my GUI thread. The modal dialog prevents any messages (like button clicks) from working on my...
8
by: Dave | last post by:
I am trying to write an event-driven application with no main window that runs "forever". It waits on a named event and then displays a window depending on data pased in a memory-mapped file. I...
11
by: gilbert | last post by:
Hello! I am writing an application that would like to make use of a thread message queue, like the one provided in MFC. In MFC, the message poster calls the function PostThreadMessage. The...
4
by: Uday Bidkar | last post by:
I am trying to register my interface with IConnectionPoint of outlook reminders to capture some Outlook Reminder events and having some issues. Here goes the pseudo code int APIENTRY...
8
by: mtsweep | last post by:
Hi, I started a background thread to preform some time intensive tasks for a GUI frontend. This background thread uses a C++ object which requires a windows message loop so I started one in it...
9
by: =?Utf-8?B?U3RldmUgQmVobWFu?= | last post by:
Using Visual C++8.0 Express Edition I created a "Solution " using a "Form" (dialog) of my own design. Without adding any code of my own I compiled the code generated for me by Visual C++. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.