How to use MFC to create a VB can reference DLL method

zhaozj2021-02-16  29

After using the MFC to write the DLL file, we cannot find and reference it in the REFERENCES of the VB Engine (Project), you cannot use the DIM S AS NEW CLASS or DIM S AS CLASS, SET S = New Class mode.

The following explains how to create a DLL method that VB can be cited using MFC, which steps:

(1) Select the MFC AppWizard (DLL) to create a new project; (such as: dlgtest.dll)

(2) Select Regular DLL with MFC STATILARLARLINKED and select Automation;

(3) Creating an MFC Class It Class is ccmdtarget and selects Automation; (assuming that the name is DLG)

(4) Modify the DLGTEST.DEF file: library "dlgtest.dll" (Modify) DllunregisterServer Private;

(5) Add a DLL file to the DLGTest.odl file to browse the displayed content in the VB reference (optional)

[uuid (........), Version (1.0), Helpstring ("My Test Contents ..."]]

(6) Add the following code to the construction and destructive function:

CDLG :: DLG () CDLG :: ~ DLG ()

{{

AfxoLockApp (); AfxoleunlockApp ();

}

(7) Note CCMDTARGET: ONFinalRelease () in the onfinalrelease function (), add DELETE THIS;

(8) Add the following code (underline, purple code) in a dlg.cpp file

Begin_MESSAGE_MAP (CDLG, CCMDTARGET)

..........

END_MESSAGE_MAP ()

Implement_olecreate (CDLG, "Dlgtest.dlg", ClassGuid Value)

ClassGuid value is the UUID value at CoClass in the .odl file.

(9) In the dlg.h file, add the following underscores, purple code

Declare_message_map ()

Declare_olecreate (CDLG)

转载请注明原文地址:https://www.9cbs.com/read-26472.html

New Post(0)