Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to convert long int to char
    text
    copied!<pre><code>#include &lt;iostream&gt; #include &lt;Windows.h&gt; #include &lt;string&gt; using namespace std; HANDLE hPort = CreateFile("COM2", GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); DCB dcb; bool writebyte(char*data) { DWORD byteswritten; if (!GetCommState(hPort,&amp;dcb)) { printf("\nSerial port can't be open\n"); return false; } dcb.BaudRate = CBR_9600; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; if (!SetCommState(hPort,&amp;dcb)) return false; bool retVal = WriteFile(hPort,data,1,&amp;byteswritten,NULL); return retVal; } int ReadByte() { int Val; BYTE Byte; DWORD dwBytesTransferred; DWORD dwCommModemStatus; if (!GetCommState(hPort,&amp;dcb)) return 0; SetCommMask(hPort,EV_RXCHAR | EV_ERR); WaitCommEvent (hPort,&amp;dwCommModemStatus,0); if (dwCommModemStatus &amp; EV_RXCHAR) ReadFile (hPort,&amp;Byte,1,&amp;dwBytesTransferred,0); Val = Byte; return Val; } int main() { POINT p; int x; int y; int z; while(0==0){ GetCursorPos(&amp;p); x = p.x; y = p.y; HDC hDC; hDC = GetDC(NULL); cin &gt;&gt; z; cout &lt;&lt; GetPixel(hDC, x, y) &lt;&lt; endl; Sleep(z); ReleaseDC(NULL, hDC); char data = GetPixel(hDC, x, y); if (writebyte(&amp;data)) cout &lt;&lt;" DATA SENT.. " &lt;&lt; (int)data&lt;&lt; "\n"; } } </code></pre> <p>in the part of sending data through serial communication, instead of sending the data as GetPixel(hDC, x, y), it only sends the value "-1" . I was thinking it is because char is only for small integers and the output I was giving is a very very long number. I tried to change it to long int but i still get the same result. That it only sends "-1". I thought that the solution might be converting char to long int or long int to char before sending the data but I don't know how..can someone help me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload