Click here to Skip to main content
Click here to Skip to main content

How to use Dynamic External MFC CView Class Objects (which exists in a DLL library) in a VBA Host MFC Application

, 8 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Implement interface between two existing DLL Library in a VBA Host MFC application.
<!-- Download Links --> <!-- Add the rest of your HTML here -->

Introduction

In a MFC Application, it is very difficult to use dynamic view which exists in a mfc dll library at runtime, because such a view object may be has nothing to do with this application or this view is created after this application be created. If some application can create view dynamic, it certainly can be extended infinitely. If you use Tangram SDK (you can get it free from http://www.tangramdev.com/english/downloads.asp), you can create such kind of application easily.

Steps:

  1. First, You must install Tangram SDK
  2. Create a Tangram Application use wizard”Tangram Application”. (Please reference:http://www.codeproject.com/useritems/Tangram_class_library.asp).
  3. Create a Tangram Component Dll use Wizard “Tangram component Dll”. <!-- Article image -->

    Sample Image - TangramAppMFC.jpg

  4. I will give you a simple example. Add a new class for this component Dll. Use wizard “Tangram component” to add a new class.

    Sample Image - TangramAppMFC.jpg

  5. For get value I add an edit control and a button for the new component. Then map a variable for the edit control.
  6. Add an event for this component to transfer values. Open class “TangramDllLeftLib”, right click “_IAtlLeftEvents”, select option “Add”, the click “Add Method”, and select type “BSTR” in the parameter type, fill “str” into parameter name, then click button “add”.

    Sample Image - TangramAppMFC.jpg

  7. Next, compile idl file “TangramDllLeft.idl”, and add connection point on class “CAtlLeft” (Right Click class “CAtlLeft”, select option “Add”, then select sub option “Add connection point”. Then dbClick “_IAtlLeftEvents” make it to the right side.)
  8. After adding an event, the next step is active this event. DbClick “Button1” in the recourse view. And add the codes below:
    		
    UpdateData(TRUE);	
    m_pComObj->Fire_ShowText(m_strEdit.AllocSysString());
    

    Remark: “m_pComObj” is a pointer variable point to class “CAtlLeft”.

    Then when you click “button1”, this event will be active and the value from edit control will send our.
  9. Use step 3~4 to create an new Tangram component Dll. Only add an edit control, and map a variable for this edit control.
  10. Add a method for this component to get the value. Right click class “IAtlRight”, select option “Add”, then select sub option “Add method”.

    Sample Image - TangramAppMFC.jpg

  11. Open class “CAtlRight”, DbClick method “AddText”. Delete the code “AFX_MANAGE_STATE(AfxGetStaticModuleState());” and add the following codes:
    m_pMfcWnd->m_strEditR=strText;
    m_pMfcWnd->UpdateData(FALSE);
    

    Remark: m_pMfcWnd is a pointer variable point to class “CRightView”.

  12. Add the two components to Tangram. Build and Run “Tangram Application”.
  13. Open a new document, click “Design”. Input “1” row and “2” columns in the splitter Tab pane, and click “CreateSplitter” button. Then you will see this document divided into two part.

    Sample Image - TangramAppMFC.jpg

  14. Click “Design” which is in the left side, fill the tangram component Dll project name and class name “TangramDllLeft.CLeftView” into the ComWnd tab pane. In the same way, fill another tangram Component Dll “TangramDllRight.CRightView” int the com wnd which is in the right side window. And then click button “Create COM Window”.

    Sample Image - TangramAppMFC.jpg

  15. After that, you will see the figure like below.

    Sample Image - TangramAppMFC.jpg

  16. Interface each other. Open “Tool” in the menu bar, and click option “Visual Basic” to the VBA Code interface. Add the following codes in the CleftView object.
    CRightView.AddText(str)
    

    Sample Image - TangramAppMFC.jpg

  17. Save the change, and close VBA interface. Switch to the document, fill some words in the edit control which is on the left side. And Click “button1”. You will see the words you input appear in the edit control which is on the right side.

    Sample Image - TangramAppMFC.jpg

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

dean170
Web Developer
China China
No Biography provided

Comments and Discussions

 
GeneralCan't download Tangram SDK. The article is pointless without it ... :( Pinmemberoleg6318-Sep-07 10:42 
GeneralAAHHH! Tangram!!!!! PinmemberDaniel Turini9-Dec-02 5:25 
No, please, stop!!!!

 
I see dumb people
GeneralNot advertising Pinmemberdean1709-Dec-02 5:18 
GeneralRe: Not advertising PinsussAnonymous12-Dec-02 8:21 
Generalnot again! PinmemberSteveKing9-Dec-02 4:48 
GeneralRe: not again! PinsussAntonS9-Dec-02 4:59 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 9 Dec 2002
Article Copyright 2002 by dean170
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid