The Combined Programming of VS2008 and Matlab

简介: Today, let’s do one thing: take a combined programming with VS2008 and matlab2009a.   Configuration of Matlab First, launch matlab and do the following to configure the initial environment :(th

Today, let’s do one thing: take a combined programming with VS2008 and matlab2009a.

 

Configuration of Matlab

First, launch matlab and do the following to configure the initial environment :(the red part is my input)

mbuild-setup

Please choose yourcompiler for building standalone MATLAB applications:

Would you like mbuild to locate installed compilers [y]/n?y

Select a compiler:

[1] Lcc-win32 C2.4.1 in C:\PROGRA~1\MATLAB\R2009a\sys\lcc

[0] None

Compiler: 0

  mbuild: No compiler selected. No actiontaken.

 

mbuild -setup

Please choose your compiler forbuilding standalone MATLAB applications:

Would you like mbuild to locateinstalled compilers [y]/n?n

Select a compiler:

[1] Lcc-win32 C 2.4.1

[2] Microsoft Visual C++ 6.0

[3] Microsoft Visual C++ .NET 2003

[4] Microsoft Visual C++ 2005 SP1

[5] Microsoft Visual C++ 2008Express

[6] Microsoft Visual C++ 2008 SP1

[0] None

 

Compiler: 6(make sure your vs2008 is the official version, not the express)

 

The default location for Microsoft Visual C++ 2008 compilers is C:\Program Files\Microsoft Visual Studio9.0,

but that directory does not existon this machine. 

Use C:\Program Files\MicrosoftVisual Studio 9.0 anyway [y]/n? y

Please verify your choices:

Compiler: Microsoft Visual C++ 2008

Location: C:\ProgramFiles\Microsoft Visual Studio 9.0

 

Are these correct [y]/n?y

 

****************************************************************************

 Warning: Applications/components generated using Microsoft VisualC++     

           2008 require that the MicrosoftVisual Studio 2008 run-time      

           libraries be available on thecomputer used for deployment.      

           To redistribute yourapplications/components, be sure that the   

           deployment machine has theserun-time libraries.                 

****************************************************************************

 

Trying to update options file:C:\Documents and Settings\Administrator\ApplicationData\MathWorks\MATLAB\R2009a\compopts.bat

From template:             C:\PROGRA~1\MATLAB\R2009a\bin\win32\mbuildopts\msvc90freecompp.bat

 

Done . . .

 

second, create a m file, naming it “add.m”. Here are in add.m:

 

function y = add(a,b)

y = a + b;

end

 

third, type this in matlab command prompt:

mcc –W cpplib:myadd–T link:lib add.m –C(concrete parameters in HELP document)

One or two minutes later, there are several new files in your current directory, just like:

 

Please notice: the four files myadd.ctf, myadd.h, myadd.lib, myadd.dll should be used by vs2008 project.So you must copy them to your current vs project directory.

 

You may feel strange to file myadd.ctf. However, if you do not copy it, you’ll get this in executing stage if other operations are OK:

 


By the way, By typing the following command at VS2008 command prompt, we can get the exports and imports of myadd.dll.Please notice the red part, because we're gonna use it in our own code.

>> dumpbin myadd.dll /exports > exports.txt

here is the exports.txt:

Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.
Dump of file myadd.dll

File Type: DLL

  Section contains the following exports for myadd.dll

    00000000 characteristics
    50F6AA97 time date stamp Wed Jan 16 21:26:47 2013
        0.00 version
           1 ordinal base
           7 number of functions
           7 number of names

    ordinal hint RVA      name

          1    0 000018D0 ?add@@YAXHAAVmwArray@@ABV1@1@Z
          2    1 00001560 mlxAdd
          3    2 000014E0 myaddGetMcrID
          4    3 000014A0
myaddInitialize
          5    4 00001440 myaddInitializeWithHandlers
          6    5 000014F0 myaddPrintStackTrace
          7    6 000014C0 myaddTerminate
  Summary
        2000 .data
        4000 .rdata
        2000 .reloc
        9000 .text

>> dumpbin myadd.dll /imports > imports.txt

here is the imports.txt:

Microsoft (R) COFF/PE Dumper Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file myadd.dll
File Type: DLL
  Section contains the following imports:
   
KERNEL32.dll
              1000A000 Import Address Table
              1000C8D8 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference


                  1F4 GetModuleFileNameA
                  1F6 GetModuleHandleA
                  2A6 HeapSize
                  2E3 LCMapStringW
                  2E1 LCMapStringA
                  240 GetStringTypeW
                  31A MultiByteToWideChar
                  23D GetStringTypeA
                  1E8 GetLocaleInfoA
                  2B5 InitializeCriticalSectionAndSpinCount
                  …… many functions!

    mclmcrrt710.dll
              1000A0F4 Import Address Table
              1000C9CC Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference


                  12C mclcppGetArrayBuffer_proxy
                    A array_buffer_set_proxy
                    6 array_buffer_add_proxy
                  12A mclcppFeval_proxy
                    8 array_buffer_get_proxy
                    C array_buffer_to_cell_proxy
                   A9 mclFeval_proxy
                   DF mclGetStackTrace_proxy
                   AC mclFreeStackTrace_proxy
                   BC mclGetID_proxy
                  11F mclTerminateInstance_proxy
                  131 mclmcrInitialize_proxy
                   EC mclInitializeComponentInstance_proxy
                  126 mclWrite_proxy
                   4C array_ref_getV_int_proxy
                   66 array_ref_number_of_elements_proxy
                   44 array_ref_classID_proxy
                  12D mclcppGetLastError_proxy
                   81 error_info_get_message_proxy
                  1C3 ref_count_obj_release_proxy
                  1C2 ref_count_obj_addref_proxy
                  128 mclcppCreateError_proxy
  Summary
        2000 .data
        4000 .rdata
        2000 .reloc
        9000 .text


Configuration of VS2008

 

create a MFC project based on dialog named myadd, then do the following to contain “include and lib”:

 choose tool-option and add the matlab’s include directory. see below:

 

choose tool-option and add the matlab’s lib directory.see below:

 

Then you’re expected to enter menu project-myadd property-linker-input, do these:

 

so myadd.lib was generated just now, and the mclmcrrt.lib is necessary for myadd.dll.

The configuration of vs is completed. let’s enter the code process.

 

Implementation of basic function

 

open your myadd project and add some controller such as the static text, the edit control and button. Just like this:

 

double click the calculate button and automatically enter the message-handling function void CMyAddTestDlg::OnBnClickedOk().

 

edit it like this:

void CMyAddTestDlg::OnBnClickedOk()
{
  // TODO: 在此添加控件通知处理程序代码
  CString str;
  inta,b,c;
 
//get what’s in the edit control and save to a,b
  a=GetDlgItemInt(IDC_EDIT1);
  b=GetDlgItemInt(IDC_EDIT2);
 
//initializing function to avoid failure
  if(!myaddInitialize())
  {
     str.Format(_T("lib myadd2 Initialize failed!\n"));
     MessageBox(str);
     return;
  }
  try
  {
//declare a mwArray variable and store a to it
     mwArray mwa(1,1,mxUINT32_CLASS);
     mwa.SetData(&a,1);
 
//declare a mwArray variable and store b to it
     mwArray mwb(1,1,mxUINT32_CLASS);
     mwb.SetData(&b,1);
 
//declare a mwArray variable and store the result
     mwArray mwy(1,1,mxUINT32_CLASS);
 
//call the add function and store mwy to c
     add(1,mwy,mwa,mwb);
     mwy.GetData(&c,1);
 
     SetDlgItemInt(IDC_EDIT3,c);
  }
  catch(mwException&e)
  {
     str.Format(_T("%s"),e.what());
     MessageBox(str);
  }
 
//the ending function
  myaddTerminate();
 
  //OnOK();youshould add an annotation of it
}

And do not forget add the include file “myadd.h” to MyAddDlg.cpp !

 

So you are seeming to be allowed to link and run the program. If you do that, you may become a little disappointed. Because you’re likely to get the following error:

 

the way to it is simple.open targetver.h and modify two lines:

 

that’s to say,change the two “0600” to “0501”.

 

Then you try to run the application. To your disappointment again, you’ll get this:

 

For this problem,you may refer to this:

http://www.mathworks.ch/matlabcentral/newsreader/view_thread/249680

 

Here is my way:

find the file \MATLAB\R2009a\toolbox\compiler\deploy\win32\MCRInstaller.exe and install it. when it’s done, the installing directory will have that .dll file.In order to find it in executing stage, you should set your PATH environment variable.See below:

 

And this time,believe me ,you will get a satisfying answer if your quality is not so bad…Just see below


Congratulations !!!

目录
相关文章
|
9月前
|
缓存
计算机网络:可靠数据传输(rdt)、流水协议、窗口滑动协议
计算机网络:可靠数据传输(rdt)、流水协议、窗口滑动协议
460 2
|
数据可视化 测试技术 uml
UML概述及UML图详解
UML概述及UML图详解
383 0
UML概述及UML图详解
|
机器学习/深度学习
22 机器学习 - 深入SVM(下)
22 机器学习 - 深入SVM(下)
69 0
|
自然语言处理 Java 计算机视觉
ACL2023 - AMPERE: AMR-Aware Prefix for Generation-Based Event Argument Extraction Model
事件论元抽取(EAE)识别给定事件的事件论元及其特定角色。最近在基于生成的EAE模型方面取得的进展显示出了与基于分类的模型相比的良好性能和可推广性
220 0
|
小程序
微信小程序:页面调用组件内方法
微信小程序:页面调用组件内方法
1345 0
|
开发框架 .NET PHP
如何搭建自己的个人网站小白教程
今天写这篇文章是为了给一些新人写一个简单的教程,简单的写一写建设个人网站的步骤个方法。
764 0
|
缓存 Linux
pdflush机制
在做进程安全监控的时候,拍脑袋决定的,如果发现一个进程在D状态时,即TASK_UNINTERRUPTIBLE(不可中断的睡眠状态),时间超过了8min,就将系统panic掉。恰好DB组做日志时,将整个log缓存到内存中,最后刷磁盘,结果系统就D状态了很长时间,自然panic了,中间涉及到Linux的缓存写回刷磁盘的一些机制和调优方法,写一下总结。
940 0
|
3天前
|
人工智能 自然语言处理 Shell
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
仅用3分钟,百炼调用满血版Deepseek-r1 API,享受百万免费Token。阿里云提供零门槛、快速部署的解决方案,支持云控制台和Cloud Shell两种方式,操作简便。Deepseek-r1满血版在推理能力上表现出色,尤其擅长数学、代码和自然语言处理任务,使用过程中无卡顿,体验丝滑。结合Chatbox工具,用户可轻松掌控模型,提升工作效率。阿里云大模型服务平台百炼不仅速度快,还确保数据安全,值得信赖。
157353 24
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
|
5天前
|
人工智能 API 网络安全
用DeepSeek,就在阿里云!四种方式助您快速使用 DeepSeek-R1 满血版!更有内部实战指导!
DeepSeek自发布以来,凭借卓越的技术性能和开源策略迅速吸引了全球关注。DeepSeek-R1作为系列中的佼佼者,在多个基准测试中超越现有顶尖模型,展现了强大的推理能力。然而,由于其爆火及受到黑客攻击,官网使用受限,影响用户体验。为解决这一问题,阿里云提供了多种解决方案。
17009 37

热门文章

最新文章