Creating a view class as a resource


Is it possible to have a view class as a resource in an MFC application? (i.e. defined in .rc and with a resource ID).If yes, how can it be done?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Take a look on CFormView class, it is based on dialog resource.
sathishkumarAuthor Commented:
We have a view class(say ViewDll) in a dll inheriting from CView. In our application(exe) we have a different view class (say ViewApp) which inherits from CFormView.

As per the requirement, we are trying to have the ViewDll class inheriting from ViewApp.
When we tried to instantiate the ViewDll class, we get a compilation error saying "There is no default constructor available for ViewApp class".

The ViewApp class constructor accepts a resource id corresponding to the type of view needed. we are trying to achive this by

ViewDll :: ViewDll() : ViewApp(int ResourceID).

In this case also we get the same compilation error.

sathishkumarAuthor Commented:
The compilation error is sorted out. But there is an link error saying that "cannot open file ViewDll.lib"...  The ViewDll.lib is supposed to be created after the ViewDll is built.

The exact message in my workspace is as follows:

LINK : fatal error LNK1104: cannot open file "../lib/ViewDll.lib"
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

A view is really a block of program code, while a resource is (almost always) a block of data.  I don't think there is any *normal* way to include a View as a program resource.

If the resource ID refers to a dialog resource, then that is possible, but your question is unclear as to that regard.

Please explain your need very specifically. Describe what you want the end result to be.
sathishkumarAuthor Commented:
The end result is that I want to succeed in making the inheritance of ViewDll class from ViewApp class which are detailed below.

1) ViewDll class is in an dll application.
2)ViewDll is inheriting from CView.

1)ViewApp class is in an exe.
2)ViewApp class is inheriting from CFormView.
3)ViewApp class constructor takes a resource id as parameter corresponding to the type of dialog.

End Result: To inherit ViewDll class from ViewApp.

Problems encountered: While instantiating ViewDll class, we get a compilation error saying that There is no default constructor available for ViewApp class".
Hope this helps.
It should be perfectly possible to instantiate a CView-derived object which is defined in a DLL.

I'll have to guess that one or more of the following is true:
o You are not exporting the class object correctly
o You are not including the correct/required header file
o When you instantiate the object, you are trying to do so without using required
   parameters.  The specific error is that the object does not contain a default
   constructior... so examine the constructors that are available and use one of those.

Although this is not justified by the symptoms:
o It is also possible that the resource is not available (MCE is looking in the DLL rather
   than the EXE or vice-versa) or the wrong resource ID is being used.  In two different
   projects it is perfectly possible to have, for instance IDR_MyDlg be equal to 123 in
   one project and equal to 321 in another.

At this point you need to get past the compiler error, so you need to look at problems with the headers and your class object declarations and the code you use to instantiate the object.  Later, some of the other problems could come up and you can diagnose those with the debugger by breakpointing and single-stepping.

-- Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Surya BobbadhiTechnical ConsultantCommented:
     Notice one thing if you are not exporting any class or a function the .lib will not be created.First check the library is exporting the required class by using __declspec(dllexport) and then try with loading of the library.

Can you describe what you did to solve this problem?  All I did was "shotgun" several potential problem areas.  It would be good for the EE database if this question contained a short description of the actual solution that you used.  Thanks!

- Dan
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.