|
|
if only you were :
1) expressing yourself clearly
2) asking the correct forum (this is Managed C++ or C++/CLI)
3) explaining what you had tried first before expecting too much of us
4) giving full error messages and a related and relevant code
|
|
|
|
|
This is my code which is probably causing the error:
void AsyncServer::InitSocks()
{
String* server = "CATUXPSD01";
int port = 4901;
printf("in InitSocks");
String* request = String::Concat(S"Our test data asdf");
Byte bytesSent[] = Encoding::ASCII->GetBytes(request);
Byte bytesReceived[] = new Byte[256];
Socket* s = 0;
IPHostEntry* hostEntry = 0;
// Get host related information.
hostEntry = Dns::Resolve(server);
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
IEnumerator* myEnum = hostEntry->AddressList->GetEnumerator();
while (myEnum->MoveNext())
{
IPAddress* address = __try_cast<ipaddress*>(myEnum->Current);
IPEndPoint* endPoint = new IPEndPoint(address, port);
Socket* tmpS = new Socket(endPoint->AddressFamily, SocketType::Stream, ProtocolType::Tcp);
tmpS->Connect(endPoint);
if (tmpS->Connected)
{
s = tmpS;
break;
}
}
// Create a socket connection with the specified server and port.
if (s == 0) {
printf("Connection failed");
} else {
// Send request to the server.
s->Send(bytesSent, bytesSent->Length, static_cast<socketflags>(0));
}
}
So a socket is being created so I can send data. My problem is that when there is nothing listening on the port I don't want the program to generate the error, I want to trap the error and do something with it.
|
|
|
|
|
but still you're asking a C++/CLI question in the wrong forum...
|
|
|
|
|
|
What are Visual Studio 2003 Keyboard Shortcuts for Find Results pane?
I have several items in my 'find results pane' at bottom of screen. When I click on one item, the source file opens up and cursor is put to line. What is shortcut key to advance to next item int he find results list? For example, in Visual Studio 6.0, you could press F4 to automatically advance to next item. When I press F4 in VS 2003, I just get some 'properties' pane opening up on right of screen.
Thanks in advance for any help on this - the MS help was worthless...
|
|
|
|
|
Hi everybody!!!
I want to change value of static text in Dialog, but I can't do it.
I try to do another way, example:
SetDialogText(hDlg,ID_STATIC,"example")
Notice: I use WIN32 API not MFC
Please show me how to do it
Thanks so much...
|
|
|
|
|
Use SetDlgItemText(hDlg, ID_STATIC, "Example");
|
|
|
|
|
You can use of WM_SETTEXT message.
|
|
|
|
|
Need help with Midistation...I want to write a FUNCTION in Visual C++ that will SET A FLAG to turn note on when note turns off...
DIRECTX DIRECT MUSIC
IF NOTE = OFF
THEN NOTE = On
What MIDISTATION source do I use from the MIDISTATION FOLDER????
I'm using MIDISTATIONDIG.CPP FILE..Is This correct???
//////////////////////////////////////////////////////////
Function called when the keyboard sends a note to the port
IF NOTE = OFF THEN NOTE = ON
/////////////////////////////////////////////////////////
Rance_Wilson
|
|
|
|
|
Need help with Midistation...I want to write a FUNCTION in Visual C++ that will SET A FLAG to turn note on when note turns off...
IF NOTE = OFF
THEN NOTE = On
What MIDISTATION source do I use from the MIDISTATION FOLDER????
I'm using MIDISTATIONDIG.CPP FILE..Is This correct???
//////////////////////////////////////////////////////////
Function called when the keyboard sends a note to the port
IF NOTE = OFF THEN NOTE = ON
/////////////////////////////////////////////////////////
Rance_Wilson
|
|
|
|
|
hi
would like to know if the following is possible:
a windows program written in c++ that allows you to submit a form and store the contents of the form in a database and retrieve/edit/delete information in the database. i can do this in asp, but would like to create an c++ application that does the same thing
if not is there another way to achieve a windows standalone application
regards
very new to c++ programming
|
|
|
|
|
Yes, it's possible.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It is possible, but if you are very new to C++ and experienced with ASP, better use something like VB (I can't believe I wrote that )
|
|
|
|
|
Nemanja Trifunovic wrote: I can't believe I wrote that
I don't think any of us can believe you said that!
|
|
|
|
|
I'm expecting sincere apologies
codito ergo sum
|
|
|
|
|
|
I am writing a short piece of code to broadcast a UDP packet over a network. It initialises the socket system, created a DGRAM socket, broadcasts the packet and then closes the socket. My problem is that when the Close() function is called it crashes with the message
HEAP[Test.exe]: Invalid Address specified to RtlFreeHeap( 01470000, 0147425C )
Here is the snippit of code :
#define BROADCAST_PORT 9122<br />
<br />
CAsyncSocket m_Broadcast_Socket;<br />
char Data[] = "1234567890";<br />
int Bytes_Sent;<br />
BOOL Value;<br />
<br />
<br />
AfxSocketInit();<br />
<br />
VERIFY(m_Broadcast_Socket.Create(BROADCAST_PORT, SOCK_DGRAM));<br />
Value = TRUE;<br />
VERIFY(m_Broadcast_Socket.SetSockOpt(SO_BROADCAST, &Value, sizeof(BOOL)));<br />
Bytes_Sent = m_Broadcast_Socket.SendTo((LPCTSTR)Data, 3, BROADCAST_PORT);<br />
DWORD Error = GetLastError();<br />
m_Broadcast_Socket.Close();
I can see the packet on my network monitor.
If I take out the SendTo call I have no crash.
If I take out the Close call the destructor crashes (again in the Close call).
What am I doing wrong ?
|
|
|
|
|
Anorexic Tribble wrote: What am I doing wrong ?
One guess is that you did not call Shutdown(..) and the other thing I would note is that you are using an Asynchronous Socket in serial fashion.
Are you following a book, article or tutorial? If so please reference it.
|
|
|
|
|
I put in the Shutdown call, but that made no difference. It be honest at the moment my small routine is the only thing sending and nothing receiving (at the moment). But good idea to put Shutdown call in.
I used an async socket because eventually I will be sending and receiving in a non linear fashion.
I'm using bits and pieces from various articles. To be honest I haven't found a really good one that deals specifically with DGRAM sockets. MSDN for example mixes its description of DGRAM and STREAM sockets to provide a very confusing piece if spaghetti writing. Do you know of any good articles?
|
|
|
|
|
This place[^] has been around since the 90's and is always a good source to check out.
|
|
|
|
|
Hi All,
I have unsigned char * buffer in which some data are stored , now I want to move these all data to my CString variable for some operations.
I tried to copy but problem is that in my unsigned char * some data are padded as zero, So I hope that in CString it gets the null value so it can not copy whole data.
I tried to copy from unsigned char * to the CString using...
CString tmpMsg = CString(msg); // Here msg is the unsigned char *
Ashish Bhatt
|
|
|
|
|
|
Thanks ...
I used memcpy() as u told me, But I used like ........
memcpy(&tempMsg,(unsigned char*)msg,noOfBytes);
Then it gives me the run time Access violation error as below...
TestRTMP.exe: 0xC0000005: Access violation reading location 0x49468964.
So,plz help me , is there any other way to copying.
Ashish Bhatt
|
|
|
|
|
Does not surprise me that it gives you an access violation when doing that.
The first and foremost rule to remember is: DO NOT USE MEMCPY ON CLASSES.
Classes work independently, managing their own memory and so on. Therefore, you should use the exposed interfaces in the classes to do stuff.
In this case, you're overwriting important data in the class, not to mention that the class's internal buffer is nowhere large enough to hold your data.
As mentioned, use CString.GetBuffer(LengthOfBuffer). It returns a pointer to a buffer. Copy data using memcpy/CopyMemory. Then call CString.ReleaseBuffer(LengthOfData).
That should do the trick.
|
|
|
|