Click here to Skip to main content
15,898,036 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String pointer questions Pin
jhwurmbach2-Mar-04 4:58
jhwurmbach2-Mar-04 4:58 
QuestionWhy cannot add new database record? Pin
siew hoon2-Mar-04 3:17
siew hoon2-Mar-04 3:17 
GeneralProblems with MFC Extensions DLLs Pin
SashaTis2-Mar-04 3:12
SashaTis2-Mar-04 3:12 
GeneralRe: Problems with MFC Extensions DLLs Pin
John M. Drescher2-Mar-04 3:39
John M. Drescher2-Mar-04 3:39 
GeneralRe: Problems with MFC Extensions DLLs Pin
SashaTis2-Mar-04 5:03
SashaTis2-Mar-04 5:03 
GeneralRe: Problems with MFC Extensions DLLs Pin
John M. Drescher2-Mar-04 6:02
John M. Drescher2-Mar-04 6:02 
GeneralRe: Problems with MFC Extensions DLLs Pin
SashaTis3-Mar-04 4:51
SashaTis3-Mar-04 4:51 
GeneralRe: Problems with MFC Extensions DLLs Pin
John M. Drescher3-Mar-04 5:43
John M. Drescher3-Mar-04 5:43 
You are welcome. This was code I got on another website. I generally do this a little bit differently but if you understand the example I gave you, you can understand what I do.

Here is what I do with all my DLLs (this was done with an vc6 appwizard that I created for that purpose):

In the file that has DLL main

// EXTDLLTESTAPI.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <afxdllx.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


static AFX_EXTENSION_MODULE ExtDllTestDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		TRACE0("EXTDLLTEST.DLL Initializing!\n");
		
		// Extension DLL one-time initialization
		if (!AfxInitExtensionModule(ExtDllTestDLL, hInstance))
			return 0;

		// Insert this DLL into the resource chain
		// NOTE: If this Extension DLL is being implicitly linked to by
		//  an MFC Regular DLL (such as an ActiveX Control)
		//  instead of an MFC application, then you will want to
		//  remove this line from DllMain and put it in a separate
		//  function exported from this Extension DLL.  The Regular DLL
		//  that uses this Extension DLL should then explicitly call that
		//  function to initialize this Extension DLL.  Otherwise,
		//  the CDynLinkLibrary object will not be attached to the
		//  Regular DLL's resource chain, and serious problems will
		//  result.

		new CDynLinkLibrary(ExtDllTestDLL);
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		TRACE0("EXTDLLTEST.DLL Terminating!\n");
		// Terminate the library before destructors are called
		AfxTermExtensionModule(ExtDllTestDLL);
	}
	return 1;   // ok
}

// Add similar code
EXTDLLTEST_DLLState::EXTDLLTEST_DLLState()
{
  m_hInstOld = AfxGetResourceHandle();
  AfxSetResourceHandle(ExtDllTestDLL.hModule);
}
 
EXTDLLTEST_DLLState::~EXTDLLTEST_DLLState()
{
  AfxSetResourceHandle(m_hInstOld);
}



Then in your dll header file:
#if defined(EXTDLLTEST_STATIC)
  #define EXTDLLTEST_CLASS_EXPORT
#elif !defined(EXTDLLTEST_DLL)
  #define EXTDLLTEST_CLASS_EXPORT AFX_CLASS_IMPORT
#else
  #define EXTDLLTEST_CLASS_EXPORT AFX_CLASS_EXPORT
#endif

/////////////////////////////////////////////////////////////////////////////
//	The following code sets up the resources for this file and is used 
//	to find them in the application's workspace.
/////////////////////////////////////////////////////////////////////////////

class EXTDLLTEST_CLASS_EXPORT EXTDLLTEST_DLLState
{
public:
  EXTDLLTEST_DLLState();
  ~EXTDLLTEST_DLLState();
protected:
  HINSTANCE m_hInstOld;
};

//////////////////////////////////////////////////////////////////////////////


Then to use it is very simple. In a function that I need resources from this dll I declare a variable of EXTDLLTEST_DLLState and all the work is done for me:
int CFileDlg::DoModal()
{
  EXTDLLTEST_DLLState state;
  return CDialog::DoModal();
}


Notes:
I export all symbols from my dlls by putting a EXTDLLTEST_CLASS_EXPORT before the symbol name like EXTDLLTEST_DLLState above. EXTDLLTEST_DLL is only defined in the project that contains the dll. If you do not want to export EXTDLLTEST_DLLState you can do it completly transparent to the end user. This is what I typically do. You can do this with dialogs by overriding DoModal and Create (if you want to support modeless dialogs).


John
QuestionHow to move CDailog child window under other it's child window? Pin
vgrigor2-Mar-04 2:44
vgrigor2-Mar-04 2:44 
AnswerRe: How to move CDailog child window under other it's child window? Pin
Prakash Nadar2-Mar-04 3:59
Prakash Nadar2-Mar-04 3:59 
GeneralRe: How to move CDailog child window under other it's child window? Pin
vgrigor2-Mar-04 4:21
vgrigor2-Mar-04 4:21 
AnswerRe: How to move CDailog child window under other it's child window? Pin
Prakash Nadar2-Mar-04 5:54
Prakash Nadar2-Mar-04 5:54 
GeneralRe: How to move CDailog child window under other it's child window? Pin
vgrigor2-Mar-04 20:32
vgrigor2-Mar-04 20:32 
GeneralUnload Shell Extension Pin
afj6662-Mar-04 2:14
afj6662-Mar-04 2:14 
GeneralRe: Unload Shell Extension Pin
Prakash Nadar2-Mar-04 2:29
Prakash Nadar2-Mar-04 2:29 
GeneralRe: Unload Shell Extension Pin
Rickard Andersson202-Mar-04 3:28
Rickard Andersson202-Mar-04 3:28 
GeneralRe: Unload Shell Extension Pin
Prakash Nadar2-Mar-04 3:53
Prakash Nadar2-Mar-04 3:53 
GeneralRe: Unload Shell Extension Pin
Rickard Andersson202-Mar-04 3:58
Rickard Andersson202-Mar-04 3:58 
GeneralRe: Unload Shell Extension Pin
Prakash Nadar2-Mar-04 4:05
Prakash Nadar2-Mar-04 4:05 
GeneralRe: Unload Shell Extension Pin
afj6662-Mar-04 12:26
afj6662-Mar-04 12:26 
GeneralDisable CListCtrl Pin
rrrado2-Mar-04 1:24
rrrado2-Mar-04 1:24 
GeneralRe: Disable CListCtrl Pin
valikac2-Mar-04 5:35
valikac2-Mar-04 5:35 
GeneralStupid include files Pin
LittleCodingFox2-Mar-04 1:23
LittleCodingFox2-Mar-04 1:23 
GeneralRe: Stupid include files Pin
Prakash Nadar2-Mar-04 1:39
Prakash Nadar2-Mar-04 1:39 
GeneralAnother cast problem Pin
Mazdak2-Mar-04 0:46
Mazdak2-Mar-04 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.