# Dynamic framework

This topic is 5394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I've created a 'framework' which creates tabs dynamically on the standard MFC CTabCtrl. It does this by loading DLL's, each of these DLLs is a dialog application. Each DLL application has relevant entities within an XML file, for example :
<DAFrameWork>
<Applications>
<Application name="Log" dll="Logger.dll" icon="log.bmp"/>
<Application name="Ping" dll="Ping.dll" icon="Ping.bmp"/>
</Applications>
</DAFrameWork>


Now to load the DLL's I do the following :
typedef CWnd*  (*MYFUNC)(CWnd*);
MYFUNC pfunc;
HMODULE hMod = LoadLibrary( szDLLApp );
pfunc = (MYFUNC)GetProcAddress( hMod, _T("CallDlg") );
CWnd* pWnd = (pfunc)( GetParentFrame() );


Now, all of these DLL Applications have the CallDlg function which displays there dialog. I attach these DLL applications to tabs in the following way :
TCITEM TabItem;
TabItem.cchTextMax = 10;
TabItem.pszText = szDLLAppName
TabItem.iImage = 0;
pTab->InsertItem( 0, &TabItem );


Now when I change tabs in the main application I just show the relevant dialog from the relevant DLL, this is called from the TCN_SELCHANGE event :
void CDAPlatformManagerView::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
TCHAR szText[10];
TCITEM TabItem;
TabItem.cchTextMax = 10;
TabItem.pszText = szText;

CTabCtrl* pTab = ( CTabCtrl* )GetDlgItem( IDC_APPTAB );
pTab->GetItem( pTab->GetCurSel(), &TabItem );

// Get the active view and hide it
CDAPlatformManagerDoc* pDoc = ( CDAPlatformManagerDoc* )GetDocument();
CString strViewname = pDoc->GetActiveView();
pDoc->CloseActiveView( strViewname );

// Show the new view
CString strActive = szText;
pDoc->ActivateView( strActive );
*pResult = 0;
}


Anyway, enough of the waffle, lets get to my question. I was wondering how these DLL applications which are stored on each tab could communicate to each other, say one of the DLL Apps needs information such as what is in an edit box in another of the DLL Apps. My problem is that these DLLs know nothing about each other, only the main application knows about them all. Any help/advice is much appreciated. Steve

##### Share on other sites
You could export a standard, defined API from your EXE. I think exporting stuff from EXEs is a bit tricky (I had a look once but it seemed like more trouble than doing it from a DLL, but I didn't really try very hard) so instead you could have a central/common DLL that exports the API. Then your DLLs would call the API and say "tell me what's in edit box blah". The problem is how does the DLL know that the edit box even exists? I suppose the API could return an empty string if it doesn't exist.

I think if you're starting to need more and more stuff from another DLL, you should probably merge the code into one DLL as it will just get very messy otherwise. It seems to me that there'd be dependencies anyway so they would always need to coexist, so you might as well move them into the one.

The other option is to use some sort of message passing mechanism but that amounts to the same thing really.

cheers
sam

##### Share on other sites
Thanks Sam,

I was thinking of using message passing with the usual SendMessage, wait for response mechanism.

As for merging the code into one DLL, well I can't really as these DLLs sit on seperate tabs, it is hard to explain in words!

I need a protocol defining I think, if one DLL needs to get information from one of the others, there needs to be some standard protocol defined between them, otherwise, the DLL wouldn't know what the other DLL was and what information it contains.

Is it possible to have one DLL which could hold information about the DLL applications registered with the main app that could share data with other DLLs ? Does this make sense ?! Basically, it would work the same way as static members do in a class. This way I could link this DLL into the other DLLs and they could make requests to this DLL instead of sending messages up to the main app, seems cleaner somehow.

Best regards,
Steve

##### Share on other sites
Yeah a well-defined protocol/set of data structures seems appropriate. It sounds like you're going to need the various DLLs to know whats in the other DLLs, or at least have a way to find out if some specific data exists. For example, maybe you could give the controls on the tabs names using your XML (and even do the layout in the XML, that would be neat). Then one DLL should be able to query another DLL with something like "give me the text from a textbox called username".

Also do you mean a sort of "manager" DLL, and all other DLLs register some function/data with that manager? That also sounds like a good idea.

cheers
sam

##### Share on other sites
Hi Sam,

Yep, the name of the DLL's are on the tabs, and I was thinking of doing it like you say.

As for central DLL manager, I was hoping this could hold shared data that the other DLL's could use. Looks like this is only possible when running two or more of the same application that loads the DLL :-(

Maybe COM sink events could help ?

Regards,
Steve

• 18
• 20
• 12
• 21
• 16