[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Resources as a class

I created a usercontrol a while back with some 3D objects using the Tao Framework. This control uses several object files as a resource to describe the 3D objects. To test it, I placed a form in the project, placed the usercontrol on the form, then ran and everything looked good.

Now, I want to use the usercontrol in another project. I put all of the classes from the first project into the new project, but I could not place the usercontrol on a form from the toolbox. Finally, I added a reference to the first project's .exe (something I'd really rather not have to do) and it let me place the usercontrol on the new form. However, it will not compile.

In the subroutine where I want to import the objects (see code), I get an error that says each object "is not a member of 'Resources'." In the first project that compiles and runs, Resources is shown as a Class and contains the objects. In the InializeComponent sub of one of the classes is the line:
Dim resources As New System.ComponentModel.ComponentResourceManager(GetType(UserControl1))

In the second project with the errors, Resources is shown as a NameSpace and does not have the objects. The code below shows where the errors are occuring, one for each object.

I don't have enough experience with vb.net to know how this works. In old VB6 we just put all the modules in the project and everything came together.

Can someone explain to me what this means and how to overcome the errors? Also, I presume referencing the .exe is using it like an external assembly. Is there a way to use the usercontrol from within the second project without having an external assembly?

Thanks.

Private Sub ImportObject()
Dim buffer() As Byte = Nothing
            If XYZ= "1"  Then
                buffer = Resources.Object1
            ElseIf XYZ= "2" Then
                buffer = Resources.Object2
.
.
            End If
End Sub

Open in new window

0
LeeLiam
Asked:
LeeLiam
  • 10
  • 10
1 Solution
 
daveamourCommented:
Hi
.....several object files as a resource to describe the 3D objects
Tell me more about these object files, what are they exactly?
0
 
LeeLiamAuthor Commented:
These are 3D objects created with a program called Wings 3D and exported as Wavefront (.obj) files. Each file is simply a list of numbers representing faces and vertices of a 3D object. Once they are imported, the Tao framework handles the matrix manipulation to represent the object in the usercontrol.

I think all of that will work fine, if I can just get the import process to work.

BTW, I put the files into the Resources section under the second project Properties, just as I did in the first project. However, in the second project the Access Modifier is listed as either Public or Friend. In the first project, the Access Modifier in shown as (custom). I don't know if this has anything to do with it.

Thanks.
0
 
daveamourCommented:
When you created the first project, what kind of project was it?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
LeeLiamAuthor Commented:
It was intended to be a basic usercontrol (or custom control, I'm not sure I understand the difference). To test it, I added a Form1, placed the control on the form and everything eventually worked fine.

While testing, it created a .exe in the bin/debug folder. To get the control in the toolbox, I had to set a reference to its own .exe. Then the control appeared in the toolbox.

Now in the second project, to use the control from the Toolbox, I had to set a refernce to the first .exe. But, it will not compile due to the errors in the ImportObject sub. It seems like it is not compiling the source code in the same order in the second project as it is in the first.

I guess I just don't understand the concepts here. I am putting all of the source code for the usercontrol in the second project. It is in that source code that the errors are occuring. Perhaps, if I am referencing an external .exe, I don't need the source code in my second project.

However, I'd like to keep everything internal to one project. Is it possible that I need to remove the reference to the first .exe and remove the usercontrol from the Toolbox, then set a reference to the second .exe. Would this allow me to add the usercontrl back into the toolbox? Also, would this force the compiler to work differently and avoid the errors?

Thanks.
0
 
daveamourCommented:
I created a user control as a test and when I created my project I created a Windows Forms Control Library.
This will compile into a DLL which can be resued across many projects or even installed in the GAC.  It can also contain many controls, not just the one.
Do you understand the difference between an exe and a DLL?
0
 
LeeLiamAuthor Commented:
Not really.

Can you explain?

Thanks.
0
 
daveamourCommented:
Ok well when you create something like say a Console application then this will be compiled into an exe.  That is a file with a .exe extension.  Double clicking on this will run that program.
When you have libraries of code which can be resued many times across different programs then you would write this as a DLL.  These will be files with a DLL extension.
When you are writing a program you can reference existing DLLs (Dynamic link library) and use them in your code.
So if you were writing a program which drew lots of shapes on the screen you wouldn't write all your code and classes from scratch - you would us existing code which someone else has written and deployed as a DLL so it can be used again and again.
Your user control is like this and should be a DLL.  You could actually have a DLL consisting of a whole suite of user controls which you could use again and again.
To build a DLL rather than an exe, when you create a new project you shoudl choose Windows Control Library as your project type.  When you then compile this it will build a DLL which you can then use in other programs.
Make sense?
0
 
LeeLiamAuthor Commented:
Thanks, that is helpful.

However, I was hoping to avoid external DLL's. I read somewhere that obfuscating the final prduct will be complicated with DLL's.

So, I really wanted to put the source code into the project to keep everything together. When I just placed all the classes in the source, the errors occurred. However, I found another way to go about it. Coming from VB6, I forgot that we can have more than one project in a solution. When I opened the usercontrol project in the solutiion, everything seems to be working as I would like.

There's just one remaining issue. Before I brought in the uc project, when I closed the app's MDI window, the IDE ended debugging. Now, it does not. When I close the MDI window, something is still running and I have to force the IDE to stop debugging. Do you have any idea what I need look for to prevent this?

Thanks.
0
 
daveamourCommented:
Don't take this the wrong way but I suspect you have got this working without really knowing why it is working.
What files do you see in your bin directory?
0
 
LeeLiamAuthor Commented:
You're absolutely correct. I'm really at a loss in trying to understand .NET.

In the bin directory, as far as executables, I have myapp.exe and myapp.vshost.exe. Also, there is a usercontrol.exe. That is if the usercontrol prject settings are set to Windows Forms Application. If I change it to Class Library, then I get a usercontrol.dll. Either way, the program seems to function the same.

So, I guess I'm stuck with an external file no matter what.

In any event, I cannot figure out why the app won't stop running when I close the MDI form. It is set as the Startup Form in the MyApp property settings. Closing it always terminated the app before I added the second project. Can you tell me what I need to do to fix that?

Thanks.
0
 
daveamourCommented:
Does it do this even if the second app is set to DLL.
Also tell me which version of Visual Studio you are using, what project type your user control project is and how you are changing it from exe to DLL.
Thanks
0
 
LeeLiamAuthor Commented:
I'm using VS2008 Pro.

Both projects are in the same solution now. If I set the "Application Type" in the uc properties to "Windows Forms Application", a .exe is automatically created. If I change that to "Class Library", a DLL is automatically created.

And yes, the program keeps running whether it is a .DLL or a .exe.

The "Startup object" in the MyApp properties is set to the MDI form. Prior to adding the uc project, when we closed the MDI, the program stopped. Now, when we close the MDI, it keeps running. You can see MyApp.exe in the taskmanager. We now have to click the "Stop Debugging" button to get it to stop.

My understanding in .NET was that whenever the startup object closed, the whole program stopped. It's not doing that now. Any ideas?

Thanks.
0
 
daveamourCommented:
Nope can't think of anything I'm afraid.
When you set the uc project to dll though you are actually doing pretty much what I first suggested anyway!
You can create the uc straight in your main project and keep it all in the same exe that way.
0
 
LeeLiamAuthor Commented:
That's what I originally tried to do. But, when I just include the classes from the uc into the project, it will not compile due to the errors in my first post.

I was adding the classes by clicking on "Add Existing Item" under the Project menu. Is there another way to bring the classes into the project? Or, is there something I need to do to group them to avoid the errors?

Thanks.
0
 
daveamourCommented:
I would just create a new class in your project and copy and paste the code in!
Make sure the namespace is right though.
0
 
LeeLiamAuthor Commented:
I have tried what you suggested. Actually it is seven classes. I created each one and copied and pasted the code. Two of the classes also have a Designer.vb and a .resx file. I also copied and pasted into those.

When I open the form that had the uc, it has now disappeared and I get errors saying the control cannot be found. If I click Ignore and Continue, the form opens with the uc missing.

Also, I'm getting the original errors that say each object "is not a member of 'Resources'."

The only way I can figure to get the uc back into the Toolbox to place it on the form is to refernce the uc.dll. Is there no other way to place the uc on a form without having an external dll?

Thanks.
0
 
LeeLiamAuthor Commented:
I think I've made some progress.

In the uc project in the Resources.Designer.vb, I found Friend Class Resources. I copied and pasted this into my project and all of the errors went away. I compiled the app. Then, I created a reference to the app, and the uc showed up in the ToolBox. So far so good.

Then, When I try drag the uc to the form, I get an error:
'System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the spcified culture or neutral culture. Make sure "Resources.resources" was correctly embedded or linked into assembly "MyApp" at compile time, or that all satelite assemblies required are loadable and fully signed.

If I can just resolve this, I think I've got what I need. Any ideas?

Thanks.
0
 
daveamourCommented:
Hi
This is getting very difficult to help out by messaging alone.  Would be much easier for someone to be there.
Do you have any colleagues nearby who may be able to help?
0
 
LeeLiamAuthor Commented:
I fixed it.

In the Resources.resx Property Box, it had automatically generated a Custom Tool Namespace of My.Resources. I noticed this was not present in the project for the uc, so I deleted it and everything now runs.

Thanks for your help.
0
 
daveamourCommented:
Ok glad to help.  Thanks for the points.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now