Case study of Mixed Programming of vc6.0 and Matlab (II)

Source: Internet
Author: User

Case study of Mixed Programming of vc6.0 and Matlab (II)
Iv. function call and parameter transfer analysis: function [R] = showsin (B, n); two input parameters are B, n, only one output parameter is R. 1. Define the real parameter: mxarray * B = NULL, * n = NULL, * r = NULL. 2. shows the design interface: 3. parameter input method example: A. Create a matrix and assign the value to the mxarray variable: B = mxcreatedoublematrix (, mxreal). B. Copy the name through the memory, copy the parameters to the defined matrix address: memcpy (mxgetpr (B), & B1, sizeof (double )); // pass the B1 value into the mxgetpr function to obtain the address function of the mxarray variable; 4. Parameter outgoing instance: A. Define a double variable to receive the parameter result: double R1 = 0;
B. Use the memory copy command again to copy the analysis results: memcpy (& R1, mxgetpr (R), sizeof (double); 5. Call the function, note the meaning of the first parameter. The first parameter is an integer and defines the number of returned parameters. In this example, the return parameter is set to 1, if it is set to 0, no response parameters are received, but execution is not affected. The response parameters must be received by the address, that is, the pointer to the mxarray variable. For example: mlfshowsin (1, & R, B, n); // execute the drawing function 6. The main event code is as follows;

// Edit by: favory. Peng # include "stdafx. H"
# Include "mat7vc. H"
# Include "mat7vcdlg. H"
# Include "mylib. H"

// Define parameters
Mxarray * B = NULL, * n = NULL, * r = NULL;

Cmat7vcdlg: cmat7vcdlg (cwnd * pparent/** // * = NULL */)
: Cdialog (cmat7vcdlg: IDD, pparent)
...{
// {Afx_data_init (cmat7vcdlg)
M_ B =-5.0;
M_n = 5.0;
M_r = _ T ("");
//} Afx_data_init
// Note that loadicon does not require a subsequent destroyicon in Win32
M_hicon = afxgetapp ()-> loadicon (idr_mainframe );
Mylibinitialize (); // initialize the library
}

Void cmat7vcdlg: onbtnrun ()
...{
Int out = 1; // defines the number of returned parameters.
Double b1 = 0, n1 = 0, R1 = 0;
Updatedata (true );
B1 = m_ B;
N1 = M_n;
B = mxcreatedoublematrix (1, 1, mxreal );
N = mxcreatedoublematrix (1, 1, mxreal );
Memcpy (mxgetpr (B), & B1, sizeof (double ));
Memcpy (mxgetpr (N), & N1, sizeof (double ));
Mlfshowsin (Out, & R, B, n); // executes the drawing function.
// Obtain the returned parameter value
Memcpy (& R1, mxgetpr (R), sizeof (double ));
M_r.format ("% F", R1 );
Updatedata (false );
}


Void cmat7vcdlg: ondestroy ()
...{
Mylibterminate (); // releases library resources
Cdialog: ondestroy ();
}

7. Compile and run. Link errors may occur during compilation. Check whether the above settings are correct and check whether mylib is changed. h. mylib. lib, mylib. DLL is added to the current project. effect 5: Program release and running environment configuration: 1. Copy the <MATLAB 71_root>/toolbox/Compiler/deploy/Win32/mcrinstaller.exe file to the target machine, click "Install" and follow the prompts to install MCR. 2. After MCR is installed, add <mcr_root>/v73/runtime/Win32 to the system environment variable path, add <mcr_root>/v73/bin/Win32 to the path of the system's environment variable. 3. executable programs of project files, user shared libraries used (DLL files, the LIB file is not required. CTF file. <This article ends, by: favory 2007-5-19> [I hope to discuss some questions together]

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.