代码导致崩溃(vb.net)

代码导致崩溃(vb.net),.net,vb.net,.net,Vb.net,我有一些代码,执行时崩溃了,怎么了 Imports WMEncoderLib Imports WMPREVIEWLib Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() ''//This ca

我有一些代码,执行时崩溃了,怎么了

Imports WMEncoderLib
Imports WMPREVIEWLib

Imports System.IO
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        ''//This call is required by the Windows Form Designer.
        InitializeComponent()

        ''//Add any initialization after the InitializeComponent() call

    End Sub

    ''//Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ''//Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    ''//NOTE: The following procedure is required by the Windows Form Designer
    ''//It can be modified using the Windows Form Designer.  
    ''//Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        ''//
        ''//Button1
        ''//
        Me.Button1.Location = New System.Drawing.Point(48, 80)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(216, 23)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Write To file and Close application"
        ''//
        ''//Form1
        ''//
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim Encoder As WMEncoder
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''// Create a WMEncoder object.

        Encoder = New WMEncoder
        ''// Retrieve the source group collection and add a source group. 

        Dim SrcGrp As IWMEncSourceGroup2
        Dim SrcGrpColl As IWMEncSourceGroupCollection
        SrcGrpColl = Encoder.SourceGroupCollection
        SrcGrp = SrcGrpColl.Add("SG_1")

        ''// Add a video and audio source to the source group.
        Dim SrcVid As IWMEncVideoSource2
        Dim SrcAud As IWMEncAudioSource
        SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO)
        SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)

        ''// Identify the source files to encode.
        SrcVid.SetInput("ScreenCap://ScreenCapture1")
        SrcAud.SetInput("Device://Default_Audio_Device")

        ''// Choose a profile from the collection.
        Dim ProColl As IWMEncProfileCollection
        Dim Pro As IWMEncProfile
        Dim i As Integer
        Dim lLength As Long

        ProColl = Encoder.ProfileCollection
        lLength = ProColl.Count
        ''//For i = 0 To lLength - 1
        ''//    Console.WriteLine(ProColl.Item(i).Name)
        ''//Next
        For i = 0 To lLength - 1
            Pro = ProColl.Item(i)
            If Pro.Name = "Windows Media Video 8 for Local Area Network (384 Kbps)" Then
                SrcGrp.Profile = Pro
                Exit For
            End If
        Next

        ''// Fill in the description object members.
        Dim Descr As IWMEncDisplayInfo
        Descr = Encoder.DisplayInfo
        Descr.Author = "Armoghan Asif"
        Descr.Copyright = "Copyright information"
        Descr.Description = "Text description of encoded content"
        Descr.Rating = "Rating information"
        Descr.Title = "Title of encoded content"

        ''// Add an attribute to the collection.
        Dim Attr As IWMEncAttributes
        Attr = Encoder.Attributes
        Attr.Add("URL", "www.adnare.com")

        ''// Specify a file object in which to save encoded content.
        Dim File As IWMEncFile
        File = Encoder.File
        File.LocalFileName = "C:\OutputFile.avi"

        ''// Crop 2 pixels from each edge of the video image.
        SrcVid.CroppingBottomMargin = 2
        SrcVid.CroppingTopMargin = 2
        SrcVid.CroppingLeftMargin = 2
        SrcVid.CroppingRightMargin = 2

        ''// Start the encoding process.
        Encoder.Start()

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Encoder.RunState Then
            Encoder.Stop()
            Application.Exit()
        End If
    End Sub
End Class
导入WMEncoderLib
导入WMPREVIEWLib
导入System.IO
公开课表格1
继承System.Windows.Forms.Form
#区域“Windows窗体设计器生成的代码”
公共分新()
MyBase.New()
“”//此调用是Windows窗体设计器所必需的。
初始化组件()
''//在InitializeComponent()调用之后添加任何初始化
端接头
''//表单重写dispose以清理组件列表。
受保护的重载重写子处置(ByVal作为布尔值处置)
如果是这样的话
如果不是(组件什么都不是),那么
components.Dispose()
如果结束
如果结束
MyBase.Dispose(Dispose)
端接头
“”//Windows窗体设计器所需
作为System.ComponentModel.IContainer的专用组件
''//注意:Windows窗体设计器需要以下过程
“”//可以使用Windows窗体设计器对其进行修改。
“”//不要使用代码编辑器修改它。
Friend WithEvents按钮1作为System.Windows.Forms.Button
私有子初始化组件()
Me.Button1=新建System.Windows.Forms.Button
Me.SuspendLayout()
''//
''//按钮1
''//
Me.Button1.Location=新系统图纸点(48,80)
Me.Button1.Name=“Button1”
Me.Button1.Size=新系统图纸尺寸(216,23)
Me.Button1.TabIndex=1
Me.Button1.Text=“写入文件并关闭应用程序”
''//
''//表格1
''//
Me.AutoScaleBaseSize=新系统.图纸.尺寸(5,13)
Me.ClientSize=新系统.Drawing.Size(292266)
Me.Controls.Add(Me.Button1)
Me.Name=“Form1”
Me.Text=“Form1”
Me.ResumeLayout(错误)
端接头
#末端区域
作为WM编码器的Dim编码器
私有子表单1_Load(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
''//创建WMEncoder对象。
编码器=新的WMEncoder
“”//检索源组集合并添加源组。
将SrcGrp作为iwmenchsourcegroup2进行调整
Dim SrcGrpColl作为IWMEncSourceGroupCollection
SrcGrpColl=Encoder.SourceGroupCollection
SrcGrp=SrcGrpColl.Add(“SG_1”)
''//将视频和音频源添加到源组。
Dim SrcVid作为IWMENC视频源2
作为音频源的Dim SrcAud
SrcVid=SrcGrp.AddSource(WMENC\u SOURCE\u TYPE.WMENC\u VIDEO)
SrcAud=SrcGrp.AddSource(WMENC\u SOURCE\u TYPE.WMENC\u AUDIO)
''//标识要编码的源文件。
SrcVid.SetInput(“ScreenCap://ScreenCapture1”)
SrcAud.SetInput(“Device://Default_Audio_Device")
''//从集合中选择一个配置文件。
Dim ProColl作为IWMENT PROFILE集合
Dim Pro作为个人资料
作为整数的Dim i
暗长
ProColl=Encoder.ProfileCollection
lLength=ProColl.Count
''//对于i=0到L长度-1
''//Console.WriteLine(ProColl.Item(i).Name)
''/下一个
对于i=0到L长度-1
Pro=ProColl.项目(i)
如果Pro.Name=“适用于局域网的Windows Media Video 8(384 Kbps)”,则
SrcGrp.Profile=Pro
退出
如果结束
下一个
''//填写描述对象成员。
Dim Descr作为iWMENCSDISPLAYINFO
Descr=Encoder.DisplayInfo
描述作者=“Armoghan Asif”
Descr.Copyright=“版权信息”
Descr.Description=“编码内容的文本描述”
Descr.Rating=“评级信息”
Descr.Title=“编码内容的标题”
''//向集合添加属性。
作为属性的Dim Attr
Attr=Encoder.Attributes
Attr.Add(“URL”,“www.adnare.com”)
''//指定要在其中保存编码内容的文件对象。
Dim文件作为iwmenfile
File=Encoder.File
File.LocalFileName=“C:\OutputFile.avi”
''//从视频图像的每个边缘裁剪2个像素。
SrcVid.cropingbottommargin=2
SrcVid.cropingTopMargin=2
SrcVid.cropingleftmargin=2
SrcVid.cropingRightMargin=2
''//开始编码过程。
Encoder.Start()
端接头
私有子按钮1\u单击(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理按钮1。单击
如果编码器为.RunState,则
编码器。停止()
Application.Exit()
如果结束
端接头
末级
它一开始就崩溃了,我不明白


谢谢

这段代码崩溃的原因可能有上百个

首先,考虑从窗体上的按钮或窗体上的某个按钮执行FrimeLoad事件,以使应用程序的启动与Windows Media编码器工作启动隔离。 然后在整个代码中设置断点,并找出它能走多远。还有,当你说它“崩溃”时,那是什么意思?如果Windows Media Converter或任何其他通用DirectX组件引发错误,通常会有一个与之相关的错误号/代码。你有错误吗


最后,您的代码是否真的到达了Encoder.Start()?

通常这是因为您的引用很旧或者不适合您的操作系统。所以,也许您在64位Vista上,而您引用的DLL是16位的?这类事情。

至少将它隔离到引起问题的几行代码中,以帮助我们帮助您。它在哪里崩溃?逐步检查代码,找出哪一行和错误消息我们在这里看不到错误消息。也许你可以告诉我们,这次坠机是怎么发生的?有转储文件吗?当我打开“开始调试”时,它会使vshost崩溃,因此我无法真正提供行