Cenron's Profile User Rating: -----

Reputation: 6 Worker
Group:
New Members
Active Posts:
11 (0.02 per day)
Joined:
23-May 12
Profile Views:
1,813
Last Active:
User is offline Nov 12 2013 01:46 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
XBox
Your Car:
Honda
Dream Kudos:
0
Icon   Cenron has not set their status

Posts I've Made

  1. In Topic: Embarrassing hangman code

    Posted 18 Jun 2013

    Oh man the patience required to write something like this. I don't think I could do it with all that repetition.
  2. In Topic: How to trigger Main function through a Thread?

    Posted 29 Jul 2012

    View PostSkydiver, on 06 June 2012 - 01:56 AM, said:

    The typical approach is to use a mutex, event, or semaphore. The thread that is to be "triggered" will wait on the WaitHandle object, and the thread that is doing the work that says it is done will signal the WaitHandle.

    In your case, though, since all you are doing is waiting for the other thread to be done, you could simply use Join(). See the sample code: http://msdn.microsof...y/95hbf2ta#Y500



    Not to knock your approach man but why use a thread to maintain a timer? Seems like a waste of resources. You can make a simple timer using 2 variables.

    // NOT CLI
    
    int main()
    {
      const u_long interval = 10; // 10 seconds for example.
      u_long startTimer = GetTickCount(); // This is in mili secs.
    
      // The thread that checks for the timer.
      while( true )
      {
         // DO whatever you want here and when 10 seconds goes by the loop exists.
         if( (startTimer + (interval * 1000)) >= GetTickCount() )
           break;
      }
    }
    
    
    
  3. In Topic: set variables from inside a thread

    Posted 29 Jul 2012

    View PostJohnBoyMan, on 29 March 2012 - 02:30 AM, said:

    Hello all. I am working with threads at the moment in my program. The thread is simple and looks like this.
    
    void ThreadProc(void){
    
    				 
    };
    
    
    Thread^ oThread = gcnew Thread( gcnew ThreadStart( this,&qualifiedlist::ThreadProc ) );
    oThread->Start();
    
    


    I have another simplar thread like this but its more complex. I try to set variables in it like this, for example.


    int y;
    void ThreadProc(void){
    y=9;
    				 
    };
    
    
    Thread^ oThread = gcnew Thread( gcnew ThreadStart( this,&qualifiedlist::ThreadProc ) );
    oThread->Start();
    cout<<y;
    
    
    


    y will be 0!

    This is veryyy simple stuff, but if i cout<<y; from outside of the ThreadProc it will be 0 always. I have tried a few other things, i dont ever remeber having this problem, i have been coding for 5 years,so am i nuts? Or should i use a delegate or something? thanks



    Use the static keyword to declare the int as a global variable,
     static int y = 0;
    
    


    The other way you can do it is declare it as a pointer.
    so it can survive the scope of the function, I like this method better because then your not polluting the global namespace.

    unsigned int __stdcall ThreadProc( void *param )
    {
      int *y = reinterpret_cast<int *>( param );
      if( y != NULL )
        (*y) = 9;
    }
    
    
    int main()
    {
      int y = 0; // Or int *y = new int;
    
      // Pass the address of the variable as a reference. 
      CreateThread( &ThreadProc, reinterpret_cast<void *>(&y) );
      std::cout << y << std::endl; // Should be 9.
    }
    
    
    
  4. In Topic: Questions about DLLs in C/C++

    Posted 1 Jul 2012

    View Postmachoolah, on 20 May 2012 - 03:18 PM, said:

    I have a few questions about DLLs I hope somebody could help me with:


    1. What are DLLs good for?
    2. Can you make DLLs using classic C++ (as opposed to C++/CLI)?
    3. Can you make DLLs using C?
    4. Is there any tutorial out there suitable for someone who has made command-line applications to learn creating DLLs?



    DLL's can be used to extend the functionality of a program by allowing an external library of functions that can be called.

    You can create an interface into the DLL and as long as you maintain that interface, you can update the functionality of DLL without recompiling the main code.

    So lets say for example your writing a game, you create a DLL that handles all the drawing of stuff to the screen ( for example take the following functions. )

    DrawEngine.DLL
    InitDrawEngine()
    DrawSprite()
    MoveSprite()
    DestroyDrawEngine()
    
    


    So then in your main program you import the DLL then create access to the functions

    MyGame.exe
    // This is pseudo code
    import DrawEngine.DLL
    
    // Dynamically Link the functions
    FUNC_TEMPLATE InitDrawEngine = (FUNC_TEMPLATE)(DrawEngine.GetProcAddr(InitDrawEngine));
    FUNC_TEMPLATE DrawSprite = (FUNC_TEMPLATE)(DrawEngine.GetProcAddr(DrawSprite));
    FUNC_TEMPLATE MoveSprit) = (FUNC_TEMPLATE)(DrawEngine.GetProcAddr(MoveSprite));
    FUNC_TEMPLATE DestroyDrawEngine = (FUNC_TEMPLATE)(DrawEngine.GetProcAddr(DestroyDrawEngine));
    
    // Now call our functions since we linked them.
    mainDisplay = InitDrawEngine();
    DrawSprite( mainDisplay, drawCopper );
    MoveSprite( mainDisplay, drawCopper, 20px, 100px );
    DestroyDrawEngine( mainDisplay );
    
    


    Now you can go back into your DLL project and modify the functionality of these function as much as you want, but as long as you dont change the function prototype then you wont have to modify and recompile your main program.


    The other feature is you can create a DLL as if it was an EXE and when that DLL is loaded it will execute the code from start to finish. This option is usually used for code injection.

    Here is a little guide with more detail.
    http://www.flipcode....sing_DLLs.shtml

    DLL's are very usful for big project like a game, because you can break up your code and only update the parts you want instead of having to recompile your entire project.
  5. In Topic: Developing a custom network protocol

    Posted 10 Jun 2012

    View PosttlhIn`toq, on 09 June 2012 - 06:27 AM, said:

    I do something similar but with two more fields
    • packetNumber
    • totalPackets


    saying this would be packet 14 of 250 for example.
    Some of my data are quite large and have to be broken down and reassembled.

    This way if one packet is lost in transmission the receiver then requests the missing packet specifically.



    Thats def a good idea and so simple. Great for large amounts of data or UDP packets. I am gonna have to remember that next time.

My Information

Member Title:
New D.I.C Head
Age:
28 years old
Birthday:
October 20, 1985
Gender:
Location:
127.0.0.1
Years Programming:
10
Programming Languages:
C/C++, PHP, Python, Java, ASM, MySQL, HTML, CSS, Java Script

Contact Information

E-mail:
Private

Friends

Cenron hasn't added any friends yet.

Comments

Cenron has no profile comments yet. Why not say hello?