Click here to Skip to main content
15,885,949 members
Articles / Desktop Programming / MFC
Article

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

Rate me:
Please Sign up or sign in to vote.
1.00/5 (10 votes)
8 Dec 20023 min read 57.2K   389   11   6
Implement interface between two existing DLL Library in a VBA Host MFC application.

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”.

    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


Written By
Web Developer
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCan't download Tangram SDK. The article is pointless without it ... :( Pin
oleg6318-Sep-07 10:42
professionaloleg6318-Sep-07 10:42 
GeneralAAHHH! Tangram!!!!! Pin
Daniel Turini9-Dec-02 5:25
Daniel Turini9-Dec-02 5:25 
GeneralNot advertising Pin
dean1709-Dec-02 5:18
dean1709-Dec-02 5:18 
GeneralRe: Not advertising Pin
Anonymous12-Dec-02 8:21
Anonymous12-Dec-02 8:21 
Generalnot again! Pin
SteveKing9-Dec-02 4:48
SteveKing9-Dec-02 4:48 
GeneralRe: not again! Pin
anton_suv9-Dec-02 4:59
anton_suv9-Dec-02 4:59 

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.