|
You can check new resolution with GetSystemMetrics.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi,
I created an C++ application an run Excel within that application by using the COM-Interface. For the development I use Visual Studio 2005. At the moment I'm be able to create an Excel application, create a worksheet and put Data on selected cells. Just see my code example.
Excel::_ApplicationPtr ExcelApp;
ExcelApp.CreateInstance(L"Excel.Application.9");
ExcelApp->put_Visible(10, true);
Excel::_WorksheetPtr pSheet;
pSheet = ExcelApp->ActiveSheet;
pSheet->Range["C1"]->Value = "Hallo World";
ExcelApp->Quit();
Now I'm trying to create a Excel ListBox throughout my C++ application. The problem is, that I'm not a experienced programmer. By searching the internet, I couldn't found any examples which would explain how to do that. In the excel9.tlh include, I found a ListBox decleration. The problem is that I don't know how to instantiate such a struct and conect it to a defined cell.
Thanks for your help.
|
|
|
|
|
After following the great tutorial on here: <a href="http://tldp.org/LDP/LG/issue74/tougher.html">http://tldp.org/LDP/LG/issue74/tougher.html</a>[<a href="http://tldp.org/LDP/LG/issue74/tougher.html" target="_blank" title="New Window">^</a>]
sources in folder here: <a href="http://www.sharedigest.com/SocketClientServer.zip">http://www.sharedigest.com/SocketClientServer.zip</a>[<a href="http://www.sharedigest.com/SocketClientServer.zip" target="_blank" title="New Window">^</a>]
I've managed to get the client and server talking to each other.
This is for an setup whereby data will be transmitted to my client via telnet from a remote server, and, according to them, I need to configure the client in such a way that it checks if the server dies and automatically attempts to reconnect after some (pre-specified) time period.
Currently, when I kill the server, I get ALOT of '' received by the client, continuously ... (output shown below, main routine shown below output)
I was wondering if there's a way to detect that the connection from the server's been lost, and consequently attempt to reconnect and keep listening for incoming messages?
Help much appreciated!
gvanto
socket newbie
<code>
Server:
pacific@mainbox /workspace/SocketClientServer/Debug$ ./SocketClientServer 0
starting server ...
Hello server from client.
Please enter string to send: hello back to client
Please enter string to send: another message
Please enter string to send: one more
Please enter string to send: //here i kill the server using ctrl+c
Client:
pacific@mainbox /workspace/SocketClientServer/Debug$ ./SocketClientServer 1
starting client ...
Sending hello server msg ...
Listening ...
We received this response from the server:
"hello back to client"
Listening ...
We received this response from the server:
"another message"
Listening ...
We received this response from the server:
"one more"
Listening ...
We received this response from the server: //AFter server killed, FLOOD of incoming BLANK messages received by client
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
""
Listening ...
We received this response from the server:
</code>
MAIN ROUTINE:
<code>
/*
* main.cpp
*
* Created on: 15/02/2009
* Author: pacific
*
* http://tldp.org/LDP/LG/issue74/tougher.html
*/
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include "ServerSocket.h"
#include "ClientSocket.h"
#include "SocketException.h"
#define DO_MAIN 1
using namespace std;
#ifdef DO_MAIN
int main(int argc, char *argv[]) {
if(argc > 1) {
/*****************************************************
* *********** SERVER *******************************/
if(atoi( argv[1] ) == 0) { //server mode
cout << "starting server ... " << endl;
try {
//Create the server socket
ServerSocket *server = new ServerSocket(30000); //set up socket and listen on local port
while(true) { //wait for incoming connections
/**
* Contains all of our socket information, used to exchange data with the client.
*/
ServerSocket new_sock;
server->accept(new_sock); //accept new incoming socket connection
try {
while(true) {
string data;
new_sock >> data; //read data from new_sock into 'data'
cout << data << endl;
//new_sock << data; //sends data in 'data' back throught the socket to the client (echo server)
string sendstr;
while(1) {
cout << "Please enter string to send: ";
getline (cin, sendstr);
new_sock << sendstr; //send it!
}
}
}
catch(SocketException&) {}
}
}
catch(SocketException &e) {
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
}
/*****************************************************
* *********** CLIENT *******************************/
if(atoi(argv[1]) == 1 ) { //client mode
cout << "starting client ... " << endl;
try {
//Create the server socket
ClientSocket client("localhost", 30000); //set up socket and listen on local port
string reply;
try {
cout << "Sending hello server msg ... " << endl;
client << "Hello server from client. "; //send
}
catch(SocketException &) {}
while(true) { //keep listening
try {
cout << "Listening ... " << endl;
//client << "Test message. "; //send
client >> reply; //receive
}
catch(SocketException &) {}
std::cout << "We received this response from the server:\n\"" << reply << "\"\n";;
}
}
catch(SocketException &e) {
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
}
}
else {
cout << "usage: ./SocketClientServer 0|1 (0 == server, 1 == client)" << endl;
}
return 0;
}
#endif
</code>
Find Your Dream IT-Job in Australia, Free!
http://www.WebCV.com.au
|
|
|
|
|
Go back to Beej's networking guid that you were looking at a few days ago - that says this in the section about recv
Wait! recv() can return 0. This can mean only one thing: the remote side has closed the
connection on you! A return value of 0 is recv()'s way of letting you know this has occurred.
[edit]I'd modify the ClientSocket class to do something like throw an exception on getting a return value of zero from recv .[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks alot, think the recv() == 0 should do the trick.
I've set it up to be reconnecting every somany seconds, when it does it keeps listening.
Many thanks again guys,
onto threads now!
(multiple clientsockets within class)
|
|
|
|
|
It simply sucks to go through the junk. Please remove it.
Also, to answer your question, based on my guess, I think you are not talking about a natural disconnect between server & client. TCP is connection oriented, when one breaks it , you should get an exception. But there's one exception, when there's a slight network disruption, the server actually loses it's connection with client, but it acts to be there alive. The client gets notified but the server don't. even the send function wouldn't convey us anything.That's a problem. There we need to set up a ping mechanism. The server asks "Are you all alive".. the clients say "Yes we are". If few client's don't say, they are actually out. We need to remove them from association with server.
I don't remember the scenario so clearly. I did these long before. I'm not sure If I'm right :P. A couple of years before I replied to the same question with a more vivid answer. lol memory's fading.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Please tell me what will the cause for this.
i have checked the path for MIDL compiler also. Please help
|
|
|
|
|
This error can occur in many cases:
- The type library could not be generated. One possible cause of this error is specifying a path to the IDL file that is longer than 126 characters. Oleaut32.dll does not support path names longer than 126 characters.
- Another way to get this message is to have the .tlb file write-protected, as you do when you use a code management tool...
I think that you first have to check your .tlb files if you use some code management tool
|
|
|
|
|
I am getting an error as said in the subject line . I know this is because i am porting my code from VC 6.0 to .NET 2005. But dont know how to troubleshoot this problem. Can you please tell me is there any setting required for this ...because my other adddins are building properly except for one i am getting such an error.
|
|
|
|
|
Sounds to me like the add-in is verifying that it's being built for VC++ 6. If you're porting the add-in to VC2005, then you need to remove that line as part of the porting process...
But if it's really that tied to VC++6, you're going to have real problems porting it to VC2005, as the add-in model's changed big time between the two versions, I think.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
yes that adding was built for VC++6.0.. that code is of CPPUnit for making the Unit Test script for new feature development.
Now i have "Batch Builded" my framwork of CPPUnit. The error in subject line doesnt occurs instead a new one is generated like this
"Error 44 error PRJ0019: A tool returned an error code from "duplicating DLL to lib directory" DSPlugIn"
Error 43 Could not delete file 'd:\CPPUnit\cppunit-1.12.1\src\msvc6\DSPlugIn\TestRunnerDSPlugin.tlb'.
Make sure that the file is not open by another process and is not write-protected. DSPlugIn
kindly provide the comments so that i can resolve the issue..
Thanks
|
|
|
|
|
Sounds like you have the addin open somewhere - are you using VC6 with the CppUnit at the same time?
Also - things I've read (including the source-code - src\msvc6\testrunner\MsDevCallerListCtrl.cpp in the latest source tarball) imply that no add-in is required for Visual Studio later than VC6. The add-in is used to support jumping to source code when double-clicking on an error in the MFC test runner, something that can be accomplished without the plug-in for later Visual Studio editions.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I created an MFC application for SDI. And after everything, I changed the inheritance of my CMyCview class to CEdit View. Compiled, but when I try to execute the application I get an assertion in
void CEditView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
What are the other things I should do to make my SDI work like a notepad?
|
|
|
|
|
Ok.. I found and replaced all CViews with CEditView. And it's not asserting now. Is it a right way? If it's possible for you to say the sequence of steps I need to do to create a notepad app?
I will have a separate class to read/write to a given file path.
On Opening a document, I read the text and keep it in a variable.
In the OnDraw() function in the view, I keep "SetWindowText()" that read content.
Are these enough for a read operation?
|
|
|
|
|
grassrootkit wrote: Ok.. I found and replaced all CViews with CEditView. And it's not asserting now. Is it a right way?
Yeah, that should now be correctly deriving from CEditView .
grassrootkit wrote: I will have a separate class to read/write to a given file path.
grassrootkit wrote: On Opening a document, I read the text and keep it in a variable
You should have read/write operations as methods of your document class, and store the text in a member variable of an instance of your document class (presuming you're using the document/view bits of MFC).
grassrootkit wrote: In the OnDraw() function in the view, I keep "SetWindowText()" that read content
You should probably do that in the OnUpdate handler - that should get called when the document is updated, by the document calling its UpdateAllViews method (that's part of CView ).
The idea of the doc/view stuff is for you to put operations affecting the document in your document class, operations affecting the view in your view class, to get separation of concerns.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your replies again. I've done those changes you suggested. Now the reading part moved to document. but I'm still calling the document's reading functions from the view. Is that ok? Please find below ,In the CmyCView::OnOpen function,
<br />
CmyCView::OnOpen()<br />
{<br />
CFileDialog dlg(TRUE,NULL,NULL,NULL,szFilter);<br />
CSDITestDoc* pDoc = GetDocument();<br />
if (dlg.DoModal() == IDOK)<br />
{<br />
pDoc->readFile((LPCTSTR)dlg.GetPathName());<br />
}<br />
CString str = pDoc->getText().c_str();<br />
CEdit& ced = GetEditCtrl();<br />
ced.SetWindowTextA(str);<br />
}<br />
So far so good, some queries regarding the below comment:
Stuart Dootson wrote: You should probably do that in the OnUpdate handler - that should get called when the document is updated, by the document calling its UpdateAllViews method (that's part of CView).
The only interface between the user & the document object(here a text content) is the CEditview, where the user modifies the text and when he saves, it's going be View->to->Doc. And it's going to be one way. Where does your comment fit in? I can't get the picture.. How does the document get modified by itself so that it updates the view from there? May be you are talking about multiple view?
Question No 2:
I guessed about a scenario where , as you said the document gets modified from an external window, may be another dialog. So added a dialog. Now I dont have any clue how do I get the document pointer into my Dialog? looks like I'm on the other end of the river..
|
|
|
|
|
I've just created a tiny MFC SDI app (using VS2008) to test this out.
To hold the text you're editting, I added a member to my document class, plus an accessor function.
public:
CString const& GetText() const { return text_; }
protected:
CString text_;
To read/write a file, I added functionality to the document's Serialize method:
void CdddDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar.Write(text_, text_.GetLength());
}
else
{
const UINT fileSize = (UINT)ar.GetFile()->GetLength();
CStringT<char, StrTraitMFC_DLL<char> > byteString;
ar.Read(byteString.GetBufferSetLength(fileSize), fileSize);
text_ = byteString;
UpdateAllViews(0);
}
}
The byteString stuff is because I had a file with ASCII text, while my app is Unicode, so I need to read the file into a 'byte per char' string and then convert to the standard CString .
Then I added an OnUpdate handler to my view, to set the view's text:
void CdddView::OnUpdate(CView* , LPARAM , CObject* )
{
SetWindowText(GetDocument()->GetText());
}
To update the document in line with the edit view, I'd add a method to the document class that would allow me to update the text somehow.
So, as you can see, by complying with the standard MFC doc/view framework, I've got plenty of functionality for very little effort!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a lot for the sample.. I'll try the same in my application.
|
|
|
|
|
Hi Stuart, I've put the logic in ::Serialize function. But how will I connect this function in "Open New file". The control flow is a bit unclear.
When I open a document, the first function that gets called is the below one.
The void CMyTestView::OnFileOpen()
{
..
}
Also in the document class, I've got,
BOOL CMyTestDoc::OnOpenDocument()
{
return TRUE;
}
Where should we call the ::Serialize() function?.
When I open a new file, what the functions happens/I should call. Can you please..just type down the function names. I'll figure out and end the conversation.
Like,
Open A new document:
1.
void CMyTestView::OnFileOpen()
{
}
2.
BOOL CSDITestDoc::OnOpenDocument()
{
return true;
}
3.
void CSDITestDoc::Serialize(CArchive& ar)
{
}
|
|
|
|
|
As I've said in my other reply - I think you should probably leave handling OnFileOpen to CWinApp , a) because it fits better with the model of responsibilities and collaborations the MFC doc/view framework was designed around, and b) it fits with MFC, so you don't need to write as much code!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
grassrootkit wrote: But shouldn't that be view's OnFileOpen
Not necessarily - thanks to the wonders of command routing, OnFileOpen can be handled by many different things.
The best way to look at whether your view should be handling OnFileOpen is to think about what your view's responsibilities are - display a view of the document and feed back user interactions with that view. Document management (which is what opening a file counts as) isn't really the responsibility of the view.
It becomes clearer when you move to MDI, or if you have multiple views on a single document:
- An application has zero to many documents
- Each document is related to precisely one application, but can have one to many views
- Each view is related to precisely one document
HTH!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Why this doesn't write anything on the Edit window?
CEditViews handle things differently from CView?
void CSDITestView::OnDraw(CDC* /*pDC*/)
{
CSDITestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CString str = "Hello CEditWorld!";
CEdit& ced = GetEditCtrl();
ced.SetWindowTextA(str);
// TODO: add draw code for native data here
}
|
|
|
|
|
Damit OnDraw never gets called for CEditViews. .. Where I can I find a tutorial that clearly talks about a CEditView ? possibly with a notepad example.
|
|
|
|
|
Google[^] is your friend[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|