Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

compare two strings

I would like to compare two string and return true or false..
how do I go about making this work?

Public string daString;

extern "C" bool __declspec(dllexport) 
myCompare()
{
	if (daString == L"6YD01ZH5" | daString == L"5L0BX10HB0")
		return true;
	else
		return false;
}

Open in new window

Avatar of farzanj
farzanj
Flag of Canada image

Use || instead of | in your if condition
Avatar of XK8ER

ASKER

I get this
      IntelliSense: identifier "daString" is undefined
The compier is right, it is undeclared in that context. Plus, your function does not take any parameters. Did you mean

#include <tchar.h>

extern "C" bool __declspec(dllexport) 
myCompare(LPCTSTR daString)
{
        // '== 0' means strings are identical
	if (_tcscml(daString ,_T("6YD01ZH5") == 0  || _tcscmp(daStringL,_T("5L0BX10HB0") == 0)
		return true;
	else
		return false;
}
                                  

Open in new window

Avatar of XK8ER

ASKER

how can I declare a string outside the function as public..
something like "public daString as string"
That'd be a global variable, e.g.

#include <windows.h>
#include <tchar.h>
#include <string>
using namespace std;

string daString; // just a global variable, no 'public' needed

extern "C" bool __declspec(dllexport) 
myCompare()
{
        // '== 0' means strings are identical
	if (_tcscml(daString ,_T("6YD01ZH5") == 0  || _tcscmp(daStringL,_T("5L0BX10HB0") == 0)
		return true;
	else
		return false;
}
                                  
                                            

Open in new window

Avatar of XK8ER

ASKER

I get this

Error      1      error C2664: '_tcscmp' : cannot convert parameter 1 from 'std::string' to 'const char *'
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XK8ER

ASKER

there is an issue with this line..

if (daString  == "6YD01ZH5") == 0  || daString == "5L0BX10HB0")

is it supposed to be like this?

if (daString == "6YD01ZH5" || daString == "5L0BX10HB0")
Yes, you are right - sorry, it is getting late here...