Class and interface communication problem.. menu

Shout-Out

User Tag List

Results 1 to 10 of 10
  1. #1
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class and interface communication problem..

    Hello again :-)
    Here I am with another stupid question.

    I'm trying to make a class for a Log system. And I only just tried something with classes, and my first succesfull attempt was the following:
    Code:
    static void Click( int x, int y ) {
     
    SetCursorPos( x, y );
     
    mouse_event( MOUSEEVENTF_LEFTDOWN, 0,0,0,0 );
    mouse_event( MOUSEEVENTF_LEFTUP, 0,0,0,0);
     
    }
    which could be called with:

    Click( 100,100 );

    That code worked, so I wanted to move on. So I wanted to do the following:

    Code:
    static void Log( String^ Message ) {
     
    this->listBox1->Items->Add( Message );
     
    }
    But surprisingly that didn't work. ( Actually, after "this->" nothing appeared or anything..

    When I compile that, I get the following errors:
    (49) : error C2671: 'Klassetest::Form1::Log' : static member functions do not have 'this' pointers
    (49) : error C2227: left of '->listBox1' must point to class/struct/union/generic type
    (49) : error C2227: left of '->Items' must point to class/struct/union/generic type
    (49) : error C2227: left of '->Add' must point to class/struct/union/generic type
    So, how do I make that work in Visual C++ ? :-)
    Last edited by Krillere; 12-27-2009 at 07:24 PM.

    Class and interface communication problem..
  2. #2
    WargRider's Avatar Member
    Reputation
    20
    Join Date
    Oct 2007
    Posts
    115
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    Hello again :-)
    Here I am with another stupid question.

    I'm trying to make a class for a Log system. And I only just tried something with classes, and my first succesfull attempt was the following:
    Code:
    static void Click( int x, int y ) {
     
    SetCursorPos( x, y );
     
    mouse_event( MOUSEEVENTF_LEFTDOWN, 0,0,0,0 );
    mouse_event( MOUSEEVENTF_LEFTUP, 0,0,0,0);
     
    }
    which could be called with:

    Click( 100,100 );

    That code worked, so I wanted to move on. So I wanted to do the following:

    Code:
    static void Log( String^ Message ) {
     
    this->listBox1->Items->Add( Message );
     
    }
    But surprisingly that didn't work. ( Actually, after "this->" nothing appeared or anything..

    When I compile that, I get the following errors:


    So, how do I make that work in Visual C++ ? :-)
    Because you either dont have any struct or union in the first place or you did not declare a variable of that struct or union type named "this". The "." and "->" are only used to access the inner variables of a struct or union. Especially the "->".

  3. #3
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Arghhh. Why are you using Managed C++?

    Seriously. If you want to write managed code then use C#, if you want to write native code then use C++ (normal - i.e. ISO - C++, not 'Visual C++' or 'Managed C++').

    Managed C++ is only good for some mixed-mode stuff and transitional stuff, it's such a bastardized language.

  4. #4
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Arghhh. Why are you using Managed C++?

    Seriously. If you want to write managed code then use C#, if you want to write native code then use C++ (normal - i.e. ISO - C++, not 'Visual C++' or 'Managed C++').

    Managed C++ is only good for some mixed-mode stuff and transitional stuff, it's such a bastardized language.
    TBH, I did consider switching over to C#, but does it have the same functions as Managed C++ ? And can thoose functions just be imported? For instance, how do I #include <windows.h> ? Or will I have to DLLImport all the functions when I need them?
    And thanks for the polite answer :-)
    Last edited by Krillere; 12-29-2009 at 12:59 PM.

  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    TBH, I did consider switching over to C#, but does it have the same functions as Managed C++ ? And can thoose functions just be imported? For instance, how do I #include <windows.h> ? Or will I have to DLLImport all the functions when I need them?
    And thanks for the polite answer :-)
    You shouldn't need to use P/Invoke most of the time, as the .NET framework provides wrappers for the most common API uses.

    What do you mean "does it have the same functions as managed c++"? I think you're confused about how .NET works...
    Last edited by Cypher; 01-17-2010 at 04:51 AM.

  6. #6
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    You shouldn't need to use P/Invoke most of the time, as the .NET framework provides wrappers for the most common API uses.

    What do you mean "does it have the same functions as managed c++"? I think you're confused about how .NET works...
    Sorry, I didn't think when I wrote it.
    I just tested my C# Skills. And I figured out how to get a Window Handle:
    Code:
    [ System.Runtime.InteropServices.DLLImport( "user32.dll" ) ] 
    static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
     
    IntPtr hWnd = FindWindow( null, "Some Window" );
    But I couldn't check if the window existed like I could in ( Managed ) C++.

    if( hWnd ) {

    }
    else {

    }

    it just errored.. How would I fix that? :-)

  7. #7
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this:

    if (hWnd != 0)
    {
    }
    else
    {
    }

    C# doesn't have implicit void* to bool or int to bool conversions.

  8. #8
    Krillere's Avatar Contributor
    Reputation
    112
    Join Date
    Nov 2007
    Posts
    668
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. That makes sense. Thanks! :-)

  9. #9
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Krillere View Post
    Ok. That makes sense. Thanks! :-)
    Yar. C# is stricter than C++ when it comes to type safety.

  10. #10
    Pragma's Avatar Contributor
    Reputation
    261
    Join Date
    Feb 2007
    Posts
    630
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As well as not using managed C++, you need to take out the static keyword of your function declaration, static member functions cannot access non-static class variables.


Similar Threads

  1. [How to] Choosing your class and Race!
    By galathius in forum World of Warcraft Guides
    Replies: 17
    Last Post: 10-30-2007, 11:59 AM
  2. dyndns and going public problem
    By godofwar in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 10-14-2007, 06:18 PM
  3. Which class and race?
    By kangaxx4 in forum World of Warcraft General
    Replies: 15
    Last Post: 10-02-2007, 05:42 AM
  4. Class and Instance Guides
    By Robin1986 in forum World of Warcraft Guides
    Replies: 0
    Last Post: 04-11-2007, 02:18 PM
  5. Favourite Class and Race
    By Simy in forum World of Warcraft General
    Replies: 13
    Last Post: 07-12-2006, 08:55 PM
All times are GMT -5. The time now is 05:48 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search