0

I am trying to debug a DLL that I have built with MSVS 2008 in VC++. I selected to use the CLR (Common Language Runtime?) so I can take advantage of the System::Net::Socket API. That API seems to be working fine but, one of my functions in the DLL needs to compare the Bytes coming off the socket against a literal string "ON:"

I arranged to send some matching Bytes thru the socket but the comparison always fails. I eventually was able to walk thru the code with the MSVS debugger and I can see the socket Bytes get converted to a String which matches the literal String I am using ("ON:"), yet, for some reason, the equality comparison is always failing (see code below.) The only real clue I have been able to glean from the debugger is that when I attempt to watch the comparison expression (str == "ON:") I get the following error text in the 'value' field of the quickwatch window:

"relational operator failure"

I have no clue what this means, (beyond the obvious that == is NOT working right) and have NOT been able to track the error message down anywhere online or otherwise so far. Below I will list some additional facts about my MSVS solution configuration and the code fragment I am experiencing this with in case any of that allows for some wise MSVS C++ person to see the error of my ways... :)

Thanks in advance:

MSVS Solution contains two projects, one an executable that calls the DLL and one the DLL itself.

The executable project is native code and the DLL project is CLR (managed code?).

Both projects use MultiByte Character Sets (ie..not Unicode)

Here is the code fragment that I am examining in the debugger when this error is encountered:

DWORD Get_Status( ) {       
    array<Byte>^ RecvBytes = gcnew array<Byte>(256);        
    array<Byte>^ SendBytes = Encoding::ASCII->GetBytes("CHECK_STATUS");
    GO::lsock->Send(SendBytes);
    if (GO::lsock->Receive(RecvBytes, GO::lsock->Available, SocketFlags::None)) {           
        System::String^ str = Encoding::ASCII->GetString(RecvBytes);            
        return ( str == "ON:") ? 0x1008 : 0; //this always returns 0 at runtime and returns the aforementioned error in the debugger watch window, error: relational operator failure
    }
    return 0;               
}
Travis
  • 552
  • 1
  • 8
  • 14
  • Visual Studio 2008? Get a new version! There have been VS 2010, 2012, 2013, 2015, and 2017, so you're six (!) versions behind. – Sjoerd Aug 25 '17 at 18:55
  • :) True, could use a new version but this stuff is on a standalone machine that requires too many hoops to update....I do plan to pursue a new version at some point but still, it is hard to believe that String equality detection is a new feature added after 2008? :) – Travis Aug 25 '17 at 20:17
  • Could this be a duplicate of https://stackoverflow.com/questions/1788702/visual-studio-fails-to-display-some-watched-expressions ? If so, see there for the answer. – Sjoerd Aug 25 '17 at 23:46

1 Answers1

0

Insert whitespace after the ON: and it may work.

Personally I prefer to use a raw socket and send()/recv() along with the C standard library (libc) when dealing with data streams for portability reasons.

#include <winsock.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Anthony Bachler
  • 224
  • 2
  • 4