[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Using a linked in .lib file that contains a dialog

I have a library that I am compiling as a static library (.lib).  It contains a simple login dialog.  I want to reuse it from my application that is linking in the library, however, when I try this, I get a compilation error as follows:

...\Include\SecurityDlg.h(21) : error C2065: 'IDD_SECURITY_DLG' : undeclared identifier

How do I address this?

Thanks,

Joe

0
jribble
Asked:
jribble
  • 5
  • 3
1 Solution
 
AlexFMCommented:
You need to include resource.h file before including SecurityDlg.h.
0
 
AlexFMCommented:
If you need to call login dialog using DoModal, don't export CSecurityDlg class directly. Instead of this, write other exported class which has function like ShowLoginDialog:

void CExportedClass::ShowLoginGialog(...)
{
    CSecurityDialog dlg();
    dlg.DoModal();
    ...
}

You need to solve also resource handle problem, this depends on Dll type.
0
 
jribbleAuthor Commented:
My project already includes a resource.h file.  I guess I need to hard code the path to where the other resource file is and include that?

For example:

#include "C:\source\gpmqnt\Common\MesMsgLib\Versions\v2.1.0\resource.h"

It does compile, but is that the best way to do it?


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AlexFMCommented:
Actually, I never export dialog classes directly from Dll because of this problem. You can include Dll resource.h file to client code, but this can create conflicts with client's own resource.h file.
So, my way to use dialog from Dll is described in the second post.
0
 
AlexFMCommented:
However, if this complies and runs, you can do this. About hard-coded path to resource.h - you have some solution for SecurityDlg.h, use it for resource.h.
0
 
jribbleAuthor Commented:
AlexFM,

I created an exported class in my library to show the dialog as you suggested.  I was able to compile without having to include the resource file from the library.  However, the dialog does not display when I run my new code, it doesn't throw an exception or anything else to indicate there was a problem.  Have you ever tried this approach where the library was a staticly linked .lib rather than a DLL? Below is my code, seems straightforward enough.


Calling code...
            
  CShowSecurityDialog *showSecurityDialogObject = new CShowSecurityDialog();
  showSecurityDialogObject->showSecurityDialog();



New exported class in library...

void CShowSecurityDialog::showSecurityDialog()
{
      CSecurityDlg dlg;
      dlg.DoModal();
}
0
 
AlexFMCommented:
Static library with it's own resource? Sorry, I don't have experience in such project type. Static library without Dll is part of executable. What happens with library resource in this case, it is added to executable resource or lost when project is built?
Open executable file in Visual Studio as resource file (use Open As)  and see whether it's resource contains this dialog. If not, I think that you must do Dll instead of static library for this.
0
 
jribbleAuthor Commented:
When I open the executable as a resource, I do not see the dialog from the statically linked library.  I will compile the library as a DLL.  Thanks for your help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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