How to share a resource project among multiple projects?
I want to share a resource project among mulitple projects. I attached a sample project trying to access a shared resource project. But I got linker errors. Any guru here tells me how to fix the errors? Thanks.
Re: How to share a resource project among multiple projects?
Try to create a DLL project using VS Wizard. You should see something like that:
Code:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the DLLTEST_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// DLLTEST_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#else
#define DLLTEST_API __declspec(dllimport)
#endif
// This class is exported from the DllTest.dll
class DLLTEST_API CDllTest {
In your example, the TestSharedResourceDlg.cpp includes:
Code:
#include "..\SharedResource\SharedDlg.h"
that has:
Code:
class __declspec(dllexport) CSharedDlg : public CDialog
but SHOULD have __declspec(dllimport)
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Re: How to share a resource project among multiple projects?
Originally Posted by VladimirF
Try to create a DLL project using VS Wizard. You should see something like that:
Code:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the DLLTEST_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// DLLTEST_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#else
#define DLLTEST_API __declspec(dllimport)
#endif
// This class is exported from the DllTest.dll
class DLLTEST_API CDllTest {
In your example, the TestSharedResourceDlg.cpp includes:
Code:
#include "..\SharedResource\SharedDlg.h"
that has:
Code:
class __declspec(dllexport) CSharedDlg : public CDialog
but SHOULD have __declspec(dllimport)
Now after I fixed this issue with dllexport/dllimport, I still got two linker errors. I attached the project for you to review to see if there is anything wrong? Thank you very much!
Re: How to share a resource project among multiple projects?
Is this your first DLL project? Have you ever used other DLLs in your projects?
You have to LINK to the lib that implements these functions.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
Re: How to share a resource project among multiple projects?
Originally Posted by LarryChen
Now after I fixed this issue with dllexport/dllimport, I still got two linker errors. I attached the project for you to review to see if there is anything wrong? Thank you very much!
After I added a reference SharedResource to TestSharedResource from common properties of TestSharedResource, then linker errors are fixed. I don't know why I have to do that under VC2010?
Right now the projects compile and link fine. But when the project TestSharedResource tried to use resource Dialog from the project SharedResource, the resource dialog can't be loaded. I attached the projects for you to review. Thank you very much!
Re: How to share a resource project among multiple projects?
Originally Posted by VladimirF
Is this your first DLL project? Have you ever used other DLLs in your projects?
You have to LINK to the lib that implements these functions.
Before I always use Linker/Advanced/Import Library to link to the lib that implements these functions, but it seems not working under VC2010. I have to add a reference SharedResource to TestSharedResource from common properties of TestSharedResource, then I am able to link to the lib. I already attached an updated version of my project. At this point, I still couldn't load the resource from SharedResource in TestSharedResource. If you have a chance to review the projects, could you figure out why? Thanks.
Re: How to share a resource project among multiple projects?
Originally Posted by LarryChen
Right now the projects compile and link fine. But when the project TestSharedResource tried to use resource Dialog from the project SharedResource, the resource dialog can't be loaded.
The MFC's DoModal() looks for the dialog resource in the instance returned by AfxGetResourceHandle(), so you need to temporary replace it with your DLL's instance:
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
I have to add a reference SharedResource to TestSharedResource from common properties of TestSharedResource, then I am able to link to the lib.
I don't think you "have" to.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.