HELP....pointers, and string functions problems - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP....pointers, and string functions problems

Hi everyone,

Can someone please explain to me why


/*Global Variable*?
LPTSTR s1,s2;
int result;
int trial = 0;


LRESULT CALLBACK dialogProc(......)
{
.
.
.
.
.
if(trail == 0)
{
s1 = (LPTSTR)(some function1); //this does give a LPTSTR type
}
else if(trial == 1)
{
s2 = (LPTSTR)(some function1); //same function that is used for s1
}


trial++;
if(trial == 2)
{
result = wcscmp(s1,s2);

////inner if begins
if(result == 0)
{
/*Print out the two strings pointed by s1 and s2*/
/*Print "Match" */
}
else
{
/*Print "MisMatch" */
}
/////inner if ends

else
{
/*Do something*/
}

}

}

trial == 1 execute "Do something" s1 = x; //x is LPTSTR type

trial == 2 s2 = y; s1 = y; //y is LPTSTR type
Print "Match" and s1 and s2

Why is it when trial == 2, s1 is not x anymore? It becomes y. Is it because both s1 and s2 reference the same function (function1). What is happening here?

Can someone offer a solution? I tried to use the wcscpy function to copy s1, and then compare the copy whith s2. It only freeze the applications after s2 get recorded. Same result happens with I tried to convert both s1 and s2 to int and long using the functions _wtoi and _wtol before I do the comparison (application freeze).

I am using a barcode scanner by symbol (MC1000). The "some function1" gives the pointer to the buffer that contains the barcode scanned. My goal is to scan two barcodes and compare them.

Please help me solve this problem.

Thx in advance


Sign In or Register to comment.