If doesn't work

This is a discussion on If doesn't work within the C++ Programming forums, part of the General Programming Boards category; I have this function in dll. and if I call this DLL so that sometext = "green" then in MessageBox ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    10

    If doesn't work

    I have this function in dll. and if I call this DLL so that sometext = "green" then in MessageBox i see "green" but this if sentence doen't work.

    How should I modify my if sentence?

    Code:
    // a sample exported function
    void DLL_EXPORT SomeFunction(const LPCSTR sometext)
    {
        MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
        //remove( sometext );
    
    	HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
    	CONSOLE_SCREEN_BUFFER_INFO csbi;
    	GetConsoleScreenBufferInfo( hstdout, &csbi );
    	SetConsoleTextAttribute( hstdout, 0x07 );
      if (sometext == "green") {
     SetConsoleTextAttribute( hstdout, 0x0A );
     printf ("Iam green: ");
      }
    }
    OffTopic:Can I make that DLL create it's own cmd window?

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    You can't compare C strings with ==, you must use strcmp.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,260
    Quote Originally Posted by rags_to_riches View Post
    You can't compare C strings with ==, you must use strcmp.
    In C++ you use std::string and then == works just fine.
    But seeing as it's an exported function, I would go with rags_to_riches' suggestion in this case.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    10
    tnx, just 1 question more how to modify that function so that it uses 1st 2 chars to set text color and then print everything that is after 2nd char?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21