`
deepfuture
  • 浏览: 4334622 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79435
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68406
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101528
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281251
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14617
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65601
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31327
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45219
社区版块
存档分类
最新评论

vb.net与matlab的混合编程

 
阅读更多

首先,使用deploytool工具或者命令行将matlab的m文件编译成类,结果产生动态链接库.dll文件和一些c#代码的类.

       第二步,将这些dll文件导入进去,并使用一些win32api函数,因为此m文件会产生figure窗口,这些api函数将此figure窗口嵌入到vb程序窗体里面.

      代码:

Imports System
Imports System.Runtime.InteropServices
Imports MathWorks.MATLAB.NET.Arrays
Imports MathWorks.MATLAB.NET.Utility
Imports SinImage.SinImage

Public Class SinForm
    Dim img As New SinImage.SinImage
    Dim FigureHwnd As IntPtr = IntPtr.Zero
    Public Declare Function SetParent Lib "user32" Alias "SetParent" _
    (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Public Declare Function GetWindowLong Lib "User32.Dll" Alias "GetWindowLongA" _
    (ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As Integer
    Public Declare Function SetWindowLong Lib "User32.Dll" Alias "SetWindowLongA" _
    (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Public Declare Function MoveWindow Lib "user32" Alias "MoveWindow" _
    (ByVal hwnd As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean

    Private Sub number_NUD_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles number_NUD.Click
        img.sx(number_NUD.Value)
        Move_Window()
    End Sub

    Private Sub SinForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        img.sx(number_NUD.Value)
        Threading.Thread.Sleep(300)
        Do While FigureHwnd = IntPtr.Zero
            FigureHwnd = FindWindow(Nothing, "Figure 1")
            Threading.Thread.Sleep(100)
        Loop
        SetWindowLong(FigureHwnd, -16, GetWindowLong(FigureHwnd, -16) And (Not &HC00000))
        SetParent(FigureHwnd, Me.image_GBX.Handle)
        Move_Window()
    End Sub

    Private Sub Move_Window() Handles Me.Resize
        MoveWindow(FigureHwnd, -3, -20, Me.image_GBX.Width + 8, Me.image_GBX.Height + 54, True)
        Me.Refresh()
    End Sub
End Class
其实可以将m文件的c#代码,直接使用csc.exe编译成.netmodule文件,然后将应用此m文件包含的函数的.vb文件也使用vbc.exe编译成exe文件,这里面要将csc.exe编译的.netmodule文件引用到vbc.exe编译中.

        若m文件不产生figure窗口,程序就更简单,直接导入.dll文件,并使用其中的函数即可.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics