For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
I'm using Visual C++ Professional Version 2015 update 3. I have a program that automates Excel and works fine in our Windows 7 computers. However, on Windows 10, Excel doesn't even launch (CreateDispatch() returns 0).
There is a problem with a Windows Function, CLSIDFromProgID(L"Excel.Application", &clsid), which returns error 0x800401fe, which has the explanation: “Application was launched but it didn't register a class factory”. This is a curious explanation because all the function does is pick up the CLSID from the registry (it doesn’t launch Excel). And “Excel.Application” is in the registry for the Windows 10 computer just like for our Windows 7 computers. I was thinking that maybe Windows 10 doesn’t allow automation to work from clients that are from an “unknown publisher”, but then it should work with UAC off. (And when I ran it with UAC set to "never notify", the warning message did not appear when starting PI_Dats. Maybe it’s not really disabled, it just doesn’t issue the warning?)
On the Local Disk Properties Security tab, Administrators have full control and I set Users also to full control. Any ideas on how to automate Excel from Windows 10 would be greatly appreciated.
We have a MFC based Server and a Client application that communicates using TCP/IP Sockets. The Server application is a dynamic Calculation engine for Chemical Process plant and does calculations continuously and responds to dynamic inputs from the client. The plant values (structure) are sent every second using a thread with a frequency of 1 second and the values are received in the client using a thread with the same frequency of 1 second. The total size of the data sent through the sockets is around 2500bytes/second. We use socket serialization through a Class derived from CObject for sending and receiving data through sockets. This application runs fine in the LAN and initially the applications were developed to run in LAN Environment.
When I try to run the applications in internet by using a static IP address for the server, the communication is established and the values are send and received successfully. However, when the applications are run for a period of more than 2 hours one of the following result is observed repeatedly.
1. The client application hangs up and shows no response.
2. Both the server and client gets disconnected but runs independently without any data exchange.
3. The client application gets closed which may be after an application crash.
Note: The same applications run for more than 15 hours without any problems in a LAN setup.
Please help me to understand the underlying problem and provide me a solution for this problem.
This can't be answered or solved without seeing the related code and knowing about the used protocol and data flow.
However, here are some tips:
With WAN communication, packets might get lost and resend. Packets might arrive in a different order. If order matters, the sequence number of the raw packets can be used or the protocol must provide a similar field (which might be an existing time stamp with adequate resolution).
The receiving threads must be event driven (your post might indicate that they are timer driven).
Check all function return codes and check for timeouts (detect dropped connections). Doing so might solve the problem of the hanging client (possible scenario: client waits for an event or state that is never occuring).
When encountering problems by code, provide methods to gracefully drop a connection so that you can restart. This should be done on both sides which requires the client to be able to send to the server (keep alive messages and close requests).
I have copied the Server code and Client code below. As of now, both the functions send (Server side) and Receive code (client code) are timer driven with frequency of 1 second. Can you please detail me this step which you had mentioned as "Check all function return codes and check for timeouts (detect dropped connections)." as I am unable to understand that clearly.
This function call in the below code in Server "tFrm->UpdateOprs(&tData);" sends the data to all the connected clients (In my case, I have connected only one Client). This function call ("tFrm->UpdateOprs(&tData);") to send data is called 5 times in a Send cycle and correspondingly 5 calls to receive data in the client side is called.
//Server Side Code
long int Offset;
Sending data timer driven is fine. But for receiving you should use an own thread that handles the receiving and supports timeouts. Using serializing might be not the best choice.
When not detecting timeouts and the connection is dropped, the read function will wait forever. Even after establishing a new connection, the pending wait will never finish because the new connection uses a different socket handle.
The typical flow of receiving in a worker thread (not using serialization):
// Wait for events using WaitForMultipleObjects() here// Events: new data available and stop thread// Timeout: According to requirements; e.g. 10 secondsif (StopEvent)
// Try to reconnect here or break when main thread reconnects
// Receive data so that number of package bytes are contained (when not fixed size)// Receive complete package here if available// Otherwise read available date into buffer and use local variables to continue receiving
// Process it here (deserialize)// Send response here// Process data here or pass them to main thread
if (CriticalError) // in any function called above
// Report errorbreak;
// Close connection here or in main thread// Use the return value to indicate the reason why the thread has terminated// or pass the state to the main thread
Just to mention that I am a novice to socket programming.
As per your suggestion, I changed the receive at the client side by removing the thread and added the OnReceive() event function to receive data from the server. Whenever OnReceive() is called, I called the Receive() to receive the data from the server. Also I removed the Serialization from both the server and client and send the data as a normal packet.
However when I run the server and client and logged the data received time to a file by adding the code to log the current time inside the OnReceive() function of the client, it had run successfully for nearly 10 hours. After that there is no logging of time in the file seen, and I assume that the connection is disconnected between the server and the client and hence the OnReceive() event was not triggered. Please guide me how to handle this and establish a continous connection. Also How to detect if the connection is lost?
That is why all event waiting calls should have a timeout. If that occurs, the server should close the corresponding socket and go into listen state again. Similar for the client: close and try to connect again.
There is no direct and fast method to detect an interrupted connection. Interrupted in the sense off one side closing the connection without announcement or even network disconnect.
When using CAsyncSocket, you have to implement your own timer that is reset when data are received.
With non-blocking calls you usually wait for events with WaitFor(Single|Multiple)Object(s) which have a timeout parameter. I recommend this when using a worker thread for receiving because the call can also catch a terminate event to stop the thread when closing the connection by intention like when terminating the application.
Once a timeout is detected you close the related connections / sockets like when terminating the application. Afterwards enter the listen state again on the server and try to (re-)connect on the client like when starting the applications.
A complete example - even when knowing the used socket type - would be far too much for this forum. But there are a lot of tutorials in the net and here at CP about the topic.
Because of the comparison with the C# version I expected it to be about the same control, but you may be right.
In the CMFCRibbonBar, tabs are called categories and they can be set with SetActiveCategory().
Last Visit: 31-Dec-99 18:00 Last Update: 21-Jun-18 12:59