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.
Printable View
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.
Try to create a DLL project using VS Wizard. You should see something like that:
In your example, the TestSharedResourceDlg.cpp includes: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 {
that has:Code:#include "..\SharedResource\SharedDlg.h"
but SHOULD have __declspec(dllimport)Code:class __declspec(dllexport) CSharedDlg : public CDialog
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.
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!
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.
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:
Code:HMODULE hDll = ::LoadLibrary(L"SharedResource.dll");
HINSTANCE hInst = AfxGetResourceHandle();
AfxSetResourceHandle(hDll);
CSharedDlg dlg(this);
dlg.DoModal();
AfxSetResourceHandle(hInst);
This "Linker/Advanced/Import Library" produces /IMPLIB command, NOT the input library:
http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
You need to specify Linker/Input/Additional Dependency
I don't think you "have" to.