• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Creating a view class as a resource

Hi,

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?

Thanks,
Sathish.
0
sathishkumar
Asked:
sathishkumar
1 Solution
 
AlexFMCommented:
Take a look on CFormView class, it is based on dialog resource.
0
 
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.


0
 
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.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DanRollinsCommented:
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.
0
 
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.

Details:
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.
0
 
DanRollinsCommented:
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
0
 
suryaxchangeCommented:
Hi,
     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.

-Surya.
0
 
DanRollinsCommented:
sathishkumar,
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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