|
Hi All,
I am developing an application in which I need to connect to a server and send some commands and retrieve the response. For this, I am using a third party console client application called Plink. Plink requires a console window to start and it cannot be opened by double clicking it. The entire process of login and sending commands and receiving response is automated in my application. Also plink has to be started with a initial command "plink <protocol> <server ip="">".
Code flow:
------------
m_Stdout = GetStdHandle(STD_OUTPUT_HANDLE);
m_StdIn = GetStdHandle(STD_INPUT_HANDLE);
SecureZeroMemory(&m_ProcInfo,sizeof(PROCESS_INFORMATION));
SecureZeroMemory(&m_StartInfo,sizeof(STARTUPINFO));
// Set up members of the STARTUPINFO structure.
m_StartInfo.cb = sizeof(STARTUPINFO);
m_StartInfo.hStdError = m_Stdout;
m_StartInfo.hStdOutput = m_Stdout;
m_StartInfo.hStdInput = m_StdIn;
m_StartInfo.dwFlags = STARTF_USESTDHANDLES;
// Create the child process.
wcscpy(m_Cmdline,_T("plink -telnet <server ip="">")); // server IP is not typed here for security purpose
m_RetVal = CreateProcess(0,
m_Cmdline, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&m_StartInfo, // STARTUPINFO pointer
&m_ProcInfo); // receives PROCESS_INFORMATION
memset(m_UserName,0,BUFSIZE);
wcscpy(m_UserName,_T("pdt2"));
wcscat(m_UserName,_T("\r\n"));
m_BytesToWrite = wcslen(m_UserName);
m_RetVal = WriteConsole(m_Stdout,m_UserName,m_BytesToWrite,&dwWritten,NULL);
if(m_RetVal)
{
fprintf(m_FilePtr,"Write to console succeeded\n");
ReadFromConsole();
}
else
{
m_ErrorCode = WSAGetLastError();
ErrorExit("Write To Console failed",m_ErrorCode);
}
-------------
This is where it fails. After writing the username string to the console, I should get back the password prompt in the console window which doesnt happen.The WriteConsole API succeeds and returns 1 but the application doesnt get back the password prompt as should be the case.In WriteConsole API I pass the standard output handle m_Stdout.
Can anyone say whats going wrong?
Thanks in advance for any kind of help.
Jyoti
|
|
|
|
|
Console expects "\n" as newline character rather then "\r\n".
-Saurabh
|
|
|
|
|
Hi Saurabh,
Thanks for replying.
I even tried with "\n" only but that too is not working.I suspect that WriteConsole is writing to the standard output but console is not able to send the username string to the server. Or may be we need to send the username to Plink somehow so that it sends the username to the server.
Thanks,
Jyoti
|
|
|
|
|
Member 4744683 wrote: m_RetVal = WriteConsole(m_Stdout,m_UserName,m_BytesToWrite,&dwWritten,NULL);
What is the value of dwWritten after this call?
Member 4744683 wrote: After writing the username string to the console...
Do you see it being written, or are you just assuming?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
Can anyone kindly show me some sample code how to execute Oracle stored procedure in Vc++?
|
|
|
|
|
I'm not an expert in DB related thing but still
You can use SQLExecute function[^] execute stored procedure
Please check ODBC API reference[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
|
|
My application is in system tray, how can I post a messsage to it.
I think first I have to obtained the HWND of window but I am unable to do it.
Yesterday I asked the same question but could not get any asnwer.
I have tried with FindWindow(),EnumWindow() but not succed to find the window handle that is in system tray.
Can anybody help me?
|
|
|
|
|
See yesterday also I told you FindWindow and FindWindowEx work fine for my application which minimized to system tray. So the problem you are facing must be due to the way you are minimizing to system tray. Can you share are are you doing that?
-Saurabh
|
|
|
|
|
Sure, My code is like
m_TrayIcon.MinimizeToTray(this);
m_TrayIcon.MaximizeFromTray(this);
I am using 3rd party class to minimize the application
|
|
|
|
|
Well then the question becomes, "How does the 3rd party library minimize the application?" Can you find the window before it's minimized?
Steve
|
|
|
|
|
Just from name of variable I cannot figure about how class is implemented. Can you tell more about implementation about the class?
-Saurabh
|
|
|
|
|
ok, Let me minimise the application with my own code then I will back to you.
Thanks .
|
|
|
|
|
Is the window pointed to by this an MFC window? If so why not use code this this:
pWnd->PostMessage(WM_???, ?, ?);
Steve
|
|
|
|
|
pther wrote: My application is in system tray, how can I post a messsage to it.
The same as you would for any other window. The fact that it is in the taskbar notification area is irrelevant.
pther wrote: Yesterday I asked the same question but could not get any asnwer.
You did get answers. If those answers were not helpful, why would you think asking the same question again would produce anything different?
Have you tried creating a test application that does nothing but minimize itself to the "system tray" without the help of other code or libraries?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
See is this[^] helpfuls for you?
|
|
|
|
|
hi all,
I want to create a module that play a alarm sound such as "bip" on a server whenever connection down.
Many computers, esp servers, don't have sound card. However, they have a mono-speaker inside that make it able to emit simple sound (like the "bip" you hear when you start the computer).
I'm looking for a command to play similar sound in visual C++ without the need of a sound card.
Can anyone help ?
|
|
|
|
|
|
Thanks, it works very well
Also, for anyone who could be interested: we could use a simple function to check if sound card exists and then switch between using Beep() or PlaySound()
BOOL m_bIsSoundCardExist = (waveOutGetNumDevs() > 0);
|
|
|
|
|
You are welcome. Thanks for the tip.
-Saurabh
|
|
|
|
|
|
Using C++ and MFC - is it possible to display an MDI Child window outside of it's MDI Parent - sort of like a modeless dialog?
I know it's goofy - but it is the quick solution to a requirement for a legacy application...
|
|
|
|
|
Have you tried setting the child frame's owner and/or parent to the desktop instead?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I've tried putting the following code in the MainFrame, the MDIChildWnd and the View with no luck:
CWnd* prnt = (CWnd*)::GetDesktopWindow();
if(prnt)
this->SetParent(prnt);
The actual create code is buried in the MFC DocView architecture somewhere - I don't know what method can be overriden to try to pass in the desktop window as the parent.
Maybe someone can help with that?
|
|
|
|