Mixed programming of vb.net and MATLAB

Source: Internet
Author: User

First, use the Deploytool tool or the command line to compile the matlab m file into a class, resulting in a dynamic link library. dll file and classes of some C # code.

The second step is to import the DLL files and use some of the WIN32API functions, because this m file produces a figure window, which embeds the figure window into the VB program form.

Code:

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 Bo Olean) 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
&nb sp;       img.sx (Number_nud. Value)
        Threading.Thread.Sleep (+)
         Do While figurehwnd = IntPtr.Zero
             Figurehwnd = FindWindow (Nothing, "Figure 1")
             Threading.Thread.Sleep (+)
        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 + si, True)
Me.refresh ()
End Sub
End Class
In fact, the C # code of the M file can be compiled directly into a. netmodule file using Csc.exe, and the. vb file that applies the functions contained in this m file is also compiled into an EXE file using vbc.exe. In this case, the csc.exe compiled. netmodule file is referenced to the vbc.exe compilation.

If the M file does not produce a figure window, the program is simpler, import the. dll file directly, and use the functions in it.

Mixed programming of vb.net and MATLAB

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.