The. M file compiled by MATLAB is converted into a DLL file using the vc6.0 (MFC (DLL) project, and the DLL file is called using the vc6.0 (MFC dialog box project ).

Source: Internet
Author: User

Before creating an MFC (DLL) project, we need to download MATCOM.ProgramInstall, open vc6.0, open tool-custom-additional items, and select visual MATCOM add-in. After the installation is successful, it will be displayed on the vc6.0 toolbar.

Start our project:

(1) Open vc6.0 and create an MFC (DLL) project. Then click the M ++ button on the toolbar to add the edited. M file.

(2) Click the FileView view and you will see several more files. Then, add the XX. h file to the project. Note that XX indicates the file name of the. M file.

(3) Open stdafx. h and add the header file # include "XX. h"

(4) define the DLL file entry. You can define the entry function in the "Project name. H" file in the following format:

Extern "C" Void run (int x, int y) (note that the entry function run can be defined at will, depending on what function you use as the entry)

(5) implement this entry function in the "Project name. H" file, that is, call the function in the. M file in the run Function

(6) Add the run @ 1 statement at the end of the "Project name. Def" file. This statement must be added; otherwise, the generated DLL file is useless.

Note that a g_xx.cpp file is generated after the. M file is added, and a main () function is provided to delete the file.

(7) compile and generate DLL files.

For example, we have the change. M file as follows:

Function [] = change (x, y)

T = X;

X = y;

Y = T;

While

The run function is as follows:

Initm (matcom_version)

Mm a, B;

A = X;

B = y;

Change (A, B)

Exitm ();

Next we will call the DLL file

Create a project MFC (exe) dialog box document;

In the void cmyfederatedlg: onok () function, add

Hinstance hinst = NULL;

Hinst = loadlibrary (mycomname );
If (hinst! = NULL)
{
Afxmessagebox ("loaded successfully ");
}

Lpfn = getprocaddress (hinst, "run"); note that run is the entry function used to generate the DLL file project.
If (lpfn = NULL)
{
Afxmessagebox ("cannot load ");
Return;
}
Else {getdt = (getdt) lpfn ;}

(* Getdt) (comin1, comin2); here is the two parameters of the run function, so as to call the function run.

Appendix:

MATCOM tool Installation

First install MATCOM

Open VC ++ 6.0

Open tools-> customization-> additional items and macro files-> select visual MATCOM add-in

In this way, MATCOM is embedded into vc6.0.

If you open vc6.0 after successful embedding, it will be displayed in the toolbar window.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.