Was ist da falsch



  • Hallo Bekomme immer diese fehler Meldung:

    ThreadFind.obj : error LNK2020: Nicht aufgelöstes Token (06000013) ThreadFind::ThreadProc.

    hier die der header, cpp, und Main:

    Header

    #pragma once
    #include "stdafx.h"
    
    // [C++]
    // Compile using /clr option.
    using namespace System;
    using namespace System::Threading;
    
    ref class ThreadFind
    {
    public:
    	static void ThreadProc();
    
    	//ThreadFind(void);
    };
    

    CPP

    #include "StdAfx.h"
    #include "ThreadFind.h"
    
    using namespace System;
    using namespace System::Threading;
    
       // The ThreadProc method is called when the thread starts.
       // It loops ten times, writing to the console and yielding 
       // the rest of its time slice each time, and then ends.
    static void ThreadProc()
       {
          for ( int i = 0; i < 10; i++ )
          {
             Console::Write(  "ThreadProc: " );
             Console::WriteLine( i );
    
             // Yield the rest of the time slice.
             Thread::Sleep( 0 );
    
          }
       }
    

    Und Main

    // LISAv1.cpp: Hauptprojektdatei.
    
    #include "stdafx.h"
    #include "Form1.h"
    #include "ThreadFind.h"
    
    using namespace LISAv1;
    using namespace System;
    using namespace System::Threading;
    
    [STAThreadAttribute]
    int main(array<System::String ^> ^args)
    {
    	// Aktivieren visueller Effekte von Windows XP, bevor Steuerelemente erstellt werden
    	Application::EnableVisualStyles();
    	Application::SetCompatibleTextRenderingDefault(false); 
    
    	 Console::WriteLine( "Main thread: Start a second thread." );
    
       // Create the thread, passing a ThreadStart delegate that
       // represents the ThreadExample::ThreadProc method.  For a 
       // delegate representing a static method, no object is
       // required.
       Thread^ oThread = gcnew Thread( gcnew ThreadStart( &ThreadFind::ThreadProc ) );
    
       // Start the thread.  On a uniprocessor, the thread does not get 
       // any processor time until the main thread yields.  Uncomment
       // the Thread.Sleep that follows t.Start() to see the difference.
       oThread->Start();
    
       //Thread::Sleep(0);
       for ( int i = 0; i < 4; i++ )
       {
          Console::WriteLine(  "Main thread: Do some work." );
          Thread::Sleep( 0 );
    
       }
       Console::WriteLine(  "Main thread: Call Join(), to wait until ThreadProc ends." );
       oThread->Join();
       Console::WriteLine(  "Main thread: ThreadProc.Join has returned.  Press Enter to end program." );
       Console::ReadLine();
    
    	// Hauptfenster erstellen und ausführen
    	Application::Run(gcnew Form1());
    	return 0;
    }
    

    ich versuche gerade einen Thread einzubauen und aus einem Konsolencode für Form umzugestallten, klappt aber nicht, wie die obrige fehlermeldung beweist.

    weiss jemand was da falsch ist.

    Danke



  • es muss in "ThreadFind.cpp" ThreadFind::ThreadProc heißen



  • oh nein. das passiert wenns spät ist.

    aber ich sehe zur überprüfung die consolen fenster nicht.

    Danke schon mal der fehler ist weg.



  • Danke hab ich mit MessageBoxen gemacht.

    Cooles Forum 🕶


Anmelden zum Antworten