CFile Assertion failure



  • community, wir haben ein problem!

    wie gesagt, macht CFile ein problem.

    erstmal zum code:

    hier wird eine inputfile und eine output file geöffnet.
    dann soll in einem extra thread zunächst einmal nur aus der
    inputfile gelesen werden.

    hier erstmal die klasse

    class CHideDlg : public CDialog
    {
    public:
    
     bool StartThread();
    	bool EndThread();
    
    	CHideDlg(CWnd* pParent = NULL);	// Standard-Konstruktor
     virtual  ~CHideDlg();
    
    // Dialogfelddaten
    	//{{AFX_DATA(CHideDlg)
    	enum { IDD = IDD_HIDE_DIALOG };
    	CProgressCtrl	m_Prg;
    	CString	m_csKey;
    	CString	m_csOutFileName;
    	CString	m_csInFileName;
    	int		m_nCode; // 0 == Code       1 == Decode
    	//}}AFX_DATA
    
    	// Vom Klassenassistenten generierte Überladungen virtueller Funktionen
    	//{{AFX_VIRTUAL(CHideDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV-Unterstützung
    	//}}AFX_VIRTUAL
    
    // Implementierung
    protected:
    	HICON m_hIcon;
    
    	// Generierte Message-Map-Funktionen
    	//{{AFX_MSG(CHideDlg)
    	virtual BOOL OnInitDialog();
    	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    	afx_msg void OnPaint();
    	afx_msg HCURSOR OnQueryDragIcon();
    	afx_msg void OnLoadIn();
    	afx_msg void OnLoadOut();
    	afx_msg void OnRun();
    	afx_msg void OnRdecode();
    	afx_msg void OnRcode();
    	afx_msg void OnTest();
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    
    private:
    	int m_nBPerLoop;
    	int m_nFileSize;
    	CFile m_fOutFile;
    	CFile m_fInFile;
    	bool m_bIsWorking;
    	int m_nStepSize;			
    	CWinThread* m_pThread;
    	int m_nCurrtPos;
    	int m_nUsableRange;
    	int m_nLowerRange;
    	int m_nUpperRange;
    	bool m_bWantExit;
    
    	UINT Decode();
    	UINT Code();
    	static UINT StartWorking( LPVOID lParam);
    };
    

    und hier die wichtigsten methoden

    struct sCall  
    {
    	int nCode;
            CHideDlg* pObj;
    };
    
    sCall* pgCall = (sCall*) malloc ( sizeof ( sCall));
    
    bool CHideDlg::StartThread()
    {
    	UpdateData ( true);
    
    	if ( ! ( m_fInFile.Open ( m_csInFileName,   CFile::modeRead) ||			   	 m_fOutFile.Open ( m_csOutFileName, CFile::modeCreate)))
    		return false;
    
    	pgCall->nCode = m_nCode; 
    	pgCall->pObj = this;
    
    	m_pThread = AfxBeginThread ( StartWorking, pgCall); 
    
    	return true;
    }
    
    UINT CHideDlg::StartWorking(  LPVOID lParam)
    {
    
    	sCall* pCall = ( sCall*) lParam;
    
    	if ( pCall->nCode == CODE)								 pCall->pObj->Code ();
    
    	else
             pCall->pObj->Decode ();			   
    
    	return S_OK;
    }
    
    UINT CHideDlg::Code()
    {
    	void* pBuf = ( void*) malloc ( 1024);
    
    	m_bIsWorking = true;
    
    	DWORD dwOnePercent = m_fInFile.GetLength() / m_n BPerLoop / 100; 
            //HIER GIBTS DIE FEHLERMELDUNG
    
    	DWORD dwLoops = 0;
    
    	//AfxMessageBox ( "UINT CHideDlg::Code()");
    
    	for ( ; ! m_bWantExit && ( m_fInFile.GetPosition () !=  
                 m_fInFile.GetLength ()); dwLoops++) 
    	{
    		if ( dwLoops >= dwOnePercent)
    		{
    												              dwLoops = 0;
    												              m_Prg.StepIt ();
    		}
    
    		m_fInFile.Read ( pBuf, 1024);
    	}
    
    	m_bIsWorking = false;
    	return S_OK;
    }
    

    nun bekomme ich bei der ersten operation an der inputdatei
    im neuen thread gleich eine fehlermeldung ( zur laufzeit)

    Microsoft Visual C++ Debug Library

    Debug Assertion Failed!

    Program: ...gramme\Microsoft Visual Studio\MyProjects\Hide\Debug\Hide.exe
    File: filecore.cpp
    Line: 258

    For information on how your program can cause an assertion
    failure, see the Visual C++ documentation on asserts.

    (Press Retry to debug the application)

    Abbrechen Wiederholen Ignorieren

    der fehler kommt genau hier

    DWORD CFile::GetLength() const
    {
    	ASSERT_VALID(this);
    
    	DWORD dwLen, dwCur;
    
    	// Seek is a non const operation
    	CFile* pFile = (CFile*)this;
    	dwCur = pFile->Seek(0L, current); //HIER GENAU
    	dwLen = pFile->SeekToEnd();
    	VERIFY(dwCur == (DWORD)pFile->Seek(dwCur, begin));
    
    	return dwLen;
    }
    

    jetzt ist die frage natürlich: warum???

    bei versuchen mit CFile ausserhalb des threads ist alles normal.
    wenn ich die zeile mit dem fehler lösche, gibts das gleiche ergebniss beim
    nächsten ( also dann dem ersten) aufruf einer memberfunktion con CFile.

    wenn ich erst in dem neuen thread ein objekt der klasse CFile erstelle,
    funktionieren die memberfunktionen.
    ALLERDINGS nur, wenn ich beim öffnen als dateipfad eine
    konstante übergebe...

    woran kann das liegen? Code () ist doch eine ganz normale methode der klasse.

    aber egal ob ich Code () in einem neuen thread ausführe, oder im hauptthread,
    der fehler passiert immer...

    weiss einer, was da zu tun ist???
    irgendwas mit dem stack???

    thx im vorraus,

    ich warte...



  • was denn???

    wo sind die profis???

    noname usw., ich verzweifle....



  • hm, alle taubstumm???

    ok, dann eben nich...

    vesuch ichs halt weiter, irgendwann wirds schon klappen


Anmelden zum Antworten