• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

vb.net与matlab的混合编程

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

       首先,使用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文件,并使用其中的函数即可.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap