我做了一个视频程序,在显示图像的同时录取AVI文件,
就是在一个do while循环里反复调用两个函数,在VB环境
下编译后执行无问题,但是做成可执行文件后每次执行
EXE文件,执行程序都自动退出,编译后执行和直接执行
EXE文件有什么不同吗???????????

解决方案 »

  1.   

    你可以F8一下。你可以看看编译执行你退出的时候内存是否还有exe的存在
      

  2.   

    也许你的程序里使用了复制内存,HOOK,子类化等操作.....如果生成后出现问题,试一下在编译选项里面选择"不优化"看看.这样有时可以解决一些内存复制上的问题
      

  3.   

    有可能是不同的函数使用相同的系统资源的问题,在适当地方加延时或用doevents
      

  4.   

    就是这部分出的问题!!
    Private Sub Command7_Click()Dim Status As HVSTATUS
        Dim i As Integer
        'Dim pOpts As Long
        
        
       'creat avi
        Dim file As cFileDlg
        Dim InitDir As String
        Dim szOutputAVIFile As String
        Dim res As Long
        Dim pfile As Long 'ptr PAVIFILE
        Dim bmp As cDIB
        Dim ps As Long 'ptr PAVISTREAM
        Dim psCompressed As Long 'ptr PAVISTREAM
        Dim strhdr As AVI_STREAM_INFO
        Dim BI As BITMAPINFOHEADER1
        Dim opts As AVI_COMPRESS_OPTIONS
        'Dim pOpts As Long
        'Dim i As Long
        Dim i1 As Long
        
        
         Dim ntemp As Long
        ntemp = Hv_Width * HV_Height - 1
        ReDim pRawBuffer(0 To ntemp)  '设置原始图像缓冲区大小
        '分配Bayer转换后图像数据缓冲
        ReDim pImageBuffer(0 To (Hv_Width * HV_Height * 3 - 1))
        
        
        'Call avi
        Status = STATUS_OK
           
        ' 启动数字摄像机采集图像到内存
            
        bStart = True
        Dim pLutR(0 To 255) As Byte
        Dim pLutG(0 To 255) As Byte
        Dim pLutB(0 To 255) As Byte    For i = 0 To 255
            pLutR(i) = i
            pLutG(i) = i
            pLutB(i) = i    Next i
            Dim ppBuf(0 To 0) As Long
        ppBuf(0) = VarPtr(pRawBuffer(0))
        
        
        '改变菜单的状态
      '  MenuStart(2).Enabled = False
      '  MenuStop(3).Enabled = True
        
        
        'Call avi
        
        
        
     ''   Set file = New cFileDlg
        'get an avi filename from user
     ''   With file
     ''       .DefaultExt = "avi"
     ''       .DlgTitle = "Choose a filename to save AVI to..."
     ''       .Filter = "AVI Files|*.avi"
     ''       .OwnerHwnd = Me.hWnd
     ''   End With
        Dim tt, tt1, tt2 As String
        
        tt = Format(Now, "ddddd ttttt")
        tt1 = Replace(tt, " ", "-", (1), (11))
        tt2 = Replace(tt1, ":", "-", 1)
        
        szOutputAVIFile = "d:\avi\AVI" + tt2 + ".avi"
       
    ''    If file.VBGetSaveFileName(szOutputAVIFile) <> True Then Exit Sub
            
    '    Open the file for writing
        res = AVIFileOpen(pfile, szOutputAVIFile, OF_WRITE Or OF_CREATE, 0&)
        'If (res <> AVIERR_OK) Then MsgBox ("error") 'GoTo error    'Get the first bmp in the list for setting format
        ''Set bmp = New cDIB
        ''lstDIBList.ListIndex = 0
        ''If bmp.CreateFromFile(lstDIBList.Text) <> True Then
        ''    MsgBox "Could not load first bitmap file in list!", vbExclamation, App.title
        ''    GoTo error
       '' End If'   Fill in the header for the video stream
        With strhdr
            .fccType = streamtypeVIDEO   'mmioStringToFOURCC("vids", 0&)    '// stream type video
            .fccHandler = 0                             '// default AVI handler
            .dwScale = 1
            .dwRate = 24 'Val(txtFPS)                        '// fps
            .dwSuggestedBufferSize = 100 * 100 * 3 'bmp.SizeImage       '// size of one frame pixels
            Call SetRect(.rcFrame, 0, 0, 100, 100)       '// rectangle for stream
        End With
        
        'validate user input
    '''    If strhdr.dwRate < 1 Then strhdr.dwRate = 1
    '''    If strhdr.dwRate > 30 Then strhdr.dwRate = 30'   And create the stream
        res = AVIFileCreateStream(pfile, ps, strhdr)
    '''    If (res <> AVIERR_OK) Then Print 11111 'GoTo error 'GoTo Error    'get the compression options from the user
        'Careful! this API requires a pointer to a pointer to a UDT
        pOpts = VarPtr(opts)
         res = AVISaveOptions(Me.hWnd, _
                            ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE, _
                           1, _
                             ps, _
                           pOpts) 'returns TRUE if User presses OK, FALSE if Cancel, or error code
    '''    If res <> 1 Then 'In C TRUE = 1
    '''        Call AVISaveOptionsFree(1, pOpts)
            ''GoTo error
    '''   End If
        
        'make compressed stream
        res = AVIMakeCompressedStream(psCompressed, ps, opts, 0&)
    '''    If res <> AVIERR_OK Then Print 111 'GoTo Error
        
        
        res = AVIStreamSetFormat(psCompressed, 0, ByVal bminfo, 80000)
    '''    If (res <> AVIERR_OK) Then Print 111 'GoTo Error
        
        
        'Delay (0.1)
        'keybd_event Chr$(38), 0, 0, 0
        
        'Delay (0.1)
        'keybd_event Chr$(38), 0, KEYEVENTF_KEYUP, 0
        
     '  addch0 = AC6610_AD(hd6610, 0, gain)'   v0 = (addch0 - 2048) * 5000# / 2048#
     
        
       
        
        Do While bStart
            Status = HVSnapShot(hhv, VarPtr(ppBuf(0)), 1)
        
            HV_VERIFY (Status)
            If (HV_SUCCESS(Status)) Then
                 ConvertBayer2Rgb VarPtr(pImageBuffer(0)), VarPtr(pRawBuffer(0)), Hv_Width, HV_Height, BAYER2RGB_NEIGHBOUR, VarPtr(pLutR(0)), VarPtr(pLutG(0)), VarPtr(pLutB(0)), True, BAYER_GR
                
                res = AVIStreamWrite(psCompressed, _
                                i1, _
                                1, _
                                VarPtr(pImageBuffer(0)), _
                                100 * 100 * 3, _
                                AVIIF_KEYFRAME, _
                                ByVal 0&, _
                                ByVal 0&)
                
                
                
                
                '在视图客户区显示图像
                StretchDIBits Form1.hdc, 0, 0, Hv_Width, HV_Height, 0, 0, Hv_Width, HV_Height, pImageBuffer(0), bminfo, DIB_RGB_COLORS, SRCCOPY
                 
            
            
            
            End If
            
            DoEvents
          i1 = i1 + 1
         
         
        '''End If
        
          
          
       Loop
             'Now close the file
       ''' Set file = Nothing
      '''  Set bmp = Nothing
        
         Call AVIStreamClose(ps)       Call AVIStreamClose(psCompressed)
         Call AVIFileClose(pfile)     Call AVIFileExitEnd Sub