|
The way this works is that everything that is sent on the socket is a message. The sender will send a type, a length value, and the number of data bytes specified by the length. The receiver does the corresponding. It reads the type value, then the length, and then reads the number of data bytes specified by the length. Using this approach, you always know what type of data is being sent by the other end of the connection, and how big it is.
I would suggest making two simple test programs, a client program and a server program. You can run both of them at the same time on the same machine using IP address 127.0.0.1. You can then debug both of them simultaneously.
You might try looking at the articles in the Internet & Network Programming[^] section of Code Project. There are a number of good examples of this kind of approach.
Software Zen: delete this; // <a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" rel="nofollow">Fold With Us!</a>[<a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" target="_blank" rel="nofollow" title="New Window">^</a>]
|
|
|
|
|
In the midst of trying to develop a protocol which can differentiate string/file, i found out that the routine i modified from the website for send file was actually not working!
Below are part of my receiver code which i used for my CAsyncSocket. So i isolated the send string part and juz tried to produce a working part for file transfer. It seems that i have problem receiving the file when i tested e program with messagebox inside the routines. The new file was created at the destination but its just an empty file with 0 bytes.
void CSockDlg::OnReceive()<br />
{<br />
<br />
char* pBuf=new char[1025];<br />
int iBufSize=1024;<br />
int iRcvd;<br />
<br />
CString strLocalFileName;<br />
iRcvd=m_sConnectSocket.Receive(pBuf,iBufSize);<br />
pBuf[iRcvd] =NULL; <br />
strLocalFileName=pBuf;<br />
<br />
AfxMessageBox("U get this notification?");<br />
m_strFileName=strLocalFileName;<br />
BOOL bRet = GetFileFromRemoteSender(strLocalFileName );<br />
}
Pls help me out! Being stuck for days now.
|
|
|
|
|
Dear all,
I have tried to get the drive letter of specific USB device. Below is my code. I cannot get a proper return value from DeviceIoControl. Please help and advice me how to make it work. Thanks.
TCHAR diskletter[10];
for(char le='C';le<'T';le++)
{
drive.Format ("%c:",le);
if(GetDriveType(drive)==DRIVE_FIXED||GetDriveType
(drive)==DRIVE_REMOVABLE)
{
sprintf(diskletter,"\\\\.\\%c:",le);
HANDLE handle;
handle=CreateFile(diskletter, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,OPEN_EXISTING, NULL, NULL);
if (handle = INVALID_HANDLE_VALUE)
MessageBox("Open device failed");
else
{
STORAGE_DEVICE_DESCRIPTOR pDevDesc;
STORAGE_PROPERTY_QUERY Query;
DWORD dwOutBytes;
BOOL bResult;
Query.PropertyId= StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;
bResult=DeviceIoControl(handle,
IOCTL_STORAGE_QUERY_PROPERTY,
&Query, sizeof(STORAGE_PROPERTY_QUERY),
&pDevDesc, pDevDesc.Size,
&dwOutBytes,
(LPOVERLAPPED)NULL);
if(!bResult)
MessageBox("Get bus type failed");
if(pDevDesc.BusType == BusTypeUsb)
m_Editi=m_Editi+le;
CloseHandle(handle);
}
}
|
|
|
|
|
hi all!
my objective will be implement setup application (copy fonts and usp10.dll ) on Win XP.
i need replace file usp10.dll with new version but WinXP has a file protected mode. how could i deal that problem, please give me an advice.
|
|
|
|
|
Hello,
I recently upgraded my IDE to vc++2005 from vc++6.
I used to write windows services using the ATL Com AppWizard (and choose "service" as the server type).
My problem is that now, in vc++2005, I can't find any wizard for creating a windows service using only native (not managed) c++ code.
The only wizard exist in this new IDE creates a managed code project.
Do you know any way of creating windows services in vc++2005 using only unmanaged code?
Thanks.
|
|
|
|
|
Could someone please quide me to an example where MFC will open a text file (.txt) internally within the app. itself for viewing. I am using the VC++ MFC App. win. expoler to do this.
the path of the text file will always be fixed, so i need to know how to read the text file and display it in "read only format" internally on the right pane of the app. once the user clicks display in my UI
Thank you for you help!
|
|
|
|
|
There is a CP article here on a text file reading class that can even open UNICODE files. I would look for it on CP and use it in your project.
No shirt, no shoes, no brains, no service.
|
|
|
|
|
Thank you, i am searching for it now!
|
|
|
|
|
I am trying to write an apps launcher that will also allow sequencing through the running apps User Interfaces. I want it to work something like the MS Office Launch Bar where a button selects the desired app.
I don't know how to launch an app from within an app, or how to bring an app to the foreground.
Any suggestions (or where to find further help) would be appreciated.
cgb143
|
|
|
|
|
SetForegroundWindow and CreateProcess are going to be your friends.
No shirt, no shoes, no brains, no service.
|
|
|
|
|
Doing something wrong.
I created a new MFC APP Wizard(exe) project
Added a button to the default dialog box, which generated
BEGIN_MESSAGE_MAP(CTutorDlg, CDialog)<br />
ON_WM_SYSCOMMAND()<br />
ON_WM_PAINT()<br />
ON_WM_QUERYDRAGICON()<br />
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)<br />
END_MESSAGE_MAP()
I added the CreateProcess
void CTutorDlg::OnButton1() <br />
{<br />
CreateProcess("c:\\prog1\\prog.exe",NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);<br />
<br />
}
But it all crashes when I press the button
(MFC Application has encountered a problem and needs to close.
We are sorry for the inconvenience)
What am I missing (apart from the knowledge )
|
|
|
|
|
Some of the last couple arguments to CreateProcess can not be NULL.
There are a few articles here on CP that can lead you through using CreateProcess.
Otherwise, this should work fine and looks okay.
No shirt, no shoes, no brains, no service.
|
|
|
|
|
You're doing great so far .
When I click the button the app launches. I lose focus on the launch prog and the graphics are erased.
Also (going back to the original query) how can I launch/control multiple apps.
I looked at some of the articles and they really helped but I can't find this.
|
|
|
|
|
When you start another application that way, the new application typically gets the focus. If you don't want it to get focus, use some of the start up flags so the new application's window starts minimized, or SHOW_NA which means to start it in normal window position, but it should not take focus.
What do you mean by control multiple apps? What is it you need to control?
No shirt, no shoes, no brains, no service.
|
|
|
|
|
Multiple copies of the same app , installed in different folders.
I have written an (inhouse) app that communicates with other equipments via RS232 COMMS ports.
Using a port expander I can run up to 6 copies of the app on a single PC (using a local data file to provide Comm Port assignments) thus requiring less PCs. Currently the user navigates to the folder of each installation to execute (or has links on the desktop). I was trying to create a launcher app that would manage the (up to) 6 copies, as the display gets very cluttered.
|
|
|
|
|
Save the information from CreateProcess - the thread IF and process handle of each launched program.
A thread in your launcher app can WaitForMultipleObjects on each created process' handle, to later know when it has exited.
When I am trakcing multiple programs, I usually store information into a memory mapped file, and as each of the applications starts up, it sets information into the memory mapped file. If you also store the window handle or thread ID of your launcher app in the memory mapped file, then as each hosted program starts or stops, it can post a window or thread message to the launcher programs window or thread to notify the launcher of relevant activity.
No shirt, no shoes, no brains, no service.
|
|
|
|
|
|
Help.
I would like to impliment tty in my software. I have done it in the past using 'C'. Now I am using C++, how can I use tty.c in my c++ code? I presume I need to create a class. I cannot say I am an expert on C++, I am using VC++ V6.0. Any help would be gratefully appreciated.
tty is a sample supplied by Microsoft.
McSam
|
|
|
|
|
What do u mean by " tty " ?
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
"The COMM sample (TTY) demonstrates using the Win32 communications functions while maintaining a common code base with 16-bit Windows code."
It is a red herring really,it just happens to be the code I am struggling with using c++. I would like to use the SDK sample software supplied by microsoft in my c++ code. Perhaps it cannot be done? Perhaps I can only use sections of the code if I am lucky?
|
|
|
|
|
Hello-
In VC++, I am using shellexecute to run a batch file (which is composed of several .exe files and sets the path to a generated text file in the C:\ drive to display all the information from the .exe files [i.e. when psinfo.exe is run from the batch file, it writes to the (.txt), thus displaying all the information generated from psinfo.exe] and the batch file has several other executable calls that follow the same pattern of writing the information to the .txt file).
However, I am now trying to remove the batch file out of the equation. Basically I am trying to mimic the batch file to be executed using VC++ and I am confused about the following:
In the batch file I set the path with the following line--
set INFOPTH=C:\INFO.txt
-- and then throughout the batch file I direct all the information generated through the executables as follows --
psinfo.exe -d >>%INFOPTH%
-- so that I can easily view the information in txt format. So now what I want to do is implement this using VC++ in a UI that simply has an event handler that once clicked (i.e. Execute) will run just as the batch file does, of course without the dependency of the batch file...
I know this sounds some what simple, but I am very new the VC++ and would like some guidance as to how I would mimic the bath file's functionality, using VC++, especially how I would direct all my shellexecute function calls for the executables (i.e. psinfo.exe, etc.) to a path such as C:\INFO.txt.
To sum up... I need to know how to create the file (C:\INFO.txt) and direct all the information from the executables to that path using MFC and VC++ and not a simple .bat file.
Thank you for your help!
|
|
|
|
|
Lenny P wrote: To sum up... I need to know how to create the file (C:\INFO.txt) and direct all the information from the executables to that path using MFC and VC++ and not a simple .bat file.
See here and here.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I got a DLL, in its function declare their is a function:
EXPORT int func1();
But when I display it in Dependency Walker, the actual name is something
like:
_func1@0
This DLL is compiled in visual c++ 6.0, I am wondering if
there is an option cause this problem.
Thanks
|
|
|
|
|
jinzhecheng wrote: ...I am wondering if
there is an option cause this problem.
What problem? C functions are decorated with a leading underscore. Check whether you are using __cdecl or __stdcall .
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
did you ever look a what the compiler generates ?
this is called decorated names, exactly such as your func1() ...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|