Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have 6 window applications form need to convert into dll(s) since i need to put that 6 applications into another big window application form. i tried to convert 1 of them using this instruction( How to convert a windows form to dll[^] ), but getting so much errors.

e.g:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
Event 'Load' cannot be found.
'Visible' is not a member of 'GillWind1.GillWind1'.
'TextBox1' is not a member of 'GillWind1.GillWind1'.
'End' statement cannot be used in class library projects.
'ComboBox1' is not declared. It may be inaccessible due to its protection level.

Please help.
Posted

Do something very different. Don't move any files or add anything. Do the following:

  1. If you want to preserve your existing application project(s) and solution (always a good idea), make a full copy of it to a different location not changing anything. Make sure it compiles and works.
  2. Go to project Properties, first tab, change "Output Type" from "Windows Application" to "Class Library". This already will give you a DLL. (Remember, in .NET, the difference between "EXE" and "DLL" is very minor.)
  3. You got a class library assembly. For this assembly, entry point (static method Main) is totally redundant. Remove it, and remove all code which is needed only for the purpose or executing this part of code. Don't remove your form(s) and code related to their functionality.
  4. Review your code for access modifiers. Remember that the purpose of your assembly is to be used in other assemblies, and other assemblies, to access the methods and members with need public and protected access modifiers. (I don't mention reflection here; it would access anything regardless of access modifiers. Let's talk about the access through referencing assemblies.) Don't give more access than it is really required.
  5. Now you need to test your library code with some application. Create a brand new Windows Forms application. If you want to use some form from your library as the main form of this test application, remove its main form and the code depending on it.
  6. Add the reference to the library to your test project. It's the best to have them in the same solution and use reference by project (the tab "Projects" in the "Add Reference" window). For the main form of new application, use one of the forms of your library (if possible; if this is not the purpose, create forms on some events, like button or menu item clicks on existing form). Test all you need, fix the problems.
  7. Finally refactor your library project with your test project, keeping in mind its purpose as the library. It may need more adequate names, structure, preparations for adding abstraction. This is a very informal item; you will need to use your own common sense and understanding the the project purpose.
  8. Use your library in your real application project(s), in the same solution. One of the ways to do it is to re-work your test application to be used as the working application prototype.
  9. PROFIT!


This way is much, much smoother than the one you have tried. It completely eliminates the problem you have described, because you never do any "dangerous" steps and do one step at a time.

Now, a word of the difference between "EXE" and "DLL". The real difference is just the name and the entry point in "EXE". You can really reference "EXE" in exact same was as it would be a library. It perfectly works and has some real-life uses. From the other hand, you can create a special host which will load and use either DLLs or EXEs as applications; and example of such architecture would be some plug-in architectures.

—SA
 
Share this answer
 
v9
Comments
Ron Beyer 11-Dec-13 23:48pm    
Good guide, +5
Sergey Alexandrovich Kryukov 11-Dec-13 23:49pm    
Thank you, Ron.
—SA
nca8503 16-Dec-13 1:54am    
Thanks SA. i tried to change the output type to "Class Library". However get an error:
Reference to a non-shared member requires an object reference.
on line :

GillWind1.Button_Send.Enabled = True

Fyi, my application form have a module.above line code is in module. it try call function from class in form1.

I tried google solution and found this http://msdn.microsoft.com/en-us/library/zwwhc0d0(v=vs.90).aspx. but, its not provide example.sorry, i'm new in vb.can you help me by provide an axample so i more understand.
Sergey Alexandrovich Kryukov 16-Dec-13 2:15am    
Wait a second. Did you code build correctly before you changed to "Class Library"?
You probably changed something else. What is the declaration of Button_Send? I bet it's private (non-shared). The problem is not related to conversion to the library, this is how you use it. The problem is very simple.
—SA
nca8503 16-Dec-13 2:41am    
yes, its working and successfully run before changed to Class Library. Yes, it non shared but public.i tried to declared as shared.but, another error come out in code:

Public Shared Sub Button_Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Send.Click

..
...
Me.TextBox1.Text = strtmmp
You should avoid, at all costs, naming the library the same as any type it contains. In this case, you named the library GillWind1 while it seems to contain a form called GillWind1. This causes problems trying to resolve types.
 
Share this answer
 
Comments
nca8503 11-Dec-13 22:18pm    
I have changed the library to GillWind3 but still get same error.
'Visible' is not a member of 'GillWind3.GillWind1'.
Ron Beyer 11-Dec-13 22:47pm    
Can you post the code for the line that the error is on?
Ron Beyer 11-Dec-13 22:48pm    
Also, when you created the DLL project, did you create a Custom Control library, or just a DLL project?
nca8503 11-Dec-13 22:55pm    
I create Class Library. for custom,that you mean WPF Custom Control Library?

Me.Visible = True
Application.DoEvents()
Ron Beyer 11-Dec-13 22:58pm    
No, you need to create a WinForms control library (Usercontrol or Custom Control) so that the proper references are added. Otherwise look at the original WinForms project and make sure the DLL project includes the same references.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900