|
OK, you need to think in bytes, not shorts. You are sending 28 bytes - it doesn't matter if an odd number are sent or received. You just restart from whichever byte you were up to. I assume here that iLength is the number of shorts, not the number of bytes.
Sending
You don't need to cache the data locally. Just send it straight from the input array. Try this:
int SendHeader(SOCKET ClientSock, const short *piHeader, int iLength)
{
int iSentTotal = 0;
int iSentPass = 0;
const int iLengthBytes = iLength*sizeof(short);
const unsigned char *ptr = (const unsigned char*)piHeader;
while(iSentTotal < iLengthBytes)
{
iSentPass = send(ClientSock, ptr, iLengthBytes-iSentTotal, 0);
if(iSentPass != SOCKET_ERROR)
{
iSentTotal += iSentPass;
ptr += iSentPass;
}
else
{
if(WSAGetLastError() != WSAEWOULDBLOCK)
return -1;
}
}
return iSentTotal;
} Receiving
Again, there's no need to make a local copy of the data before transferring it to the array. If you're worried about the contents in case of an error, don't be. If a function returns an error, all output data from it should be considered undefined, unless stated otherwise. I don't think that your code will even compile. Try this:
int ReceiveHeader(SOCKET ClientSock, short *piHeader, int iLength)
{
int iRecvTotal = 0;
int iRecvPass = 0;
const int iLengthBytes = iLength*sizeof(short);
unsigned char *ptr = (const unsigned short*)piHeader;
while(iRecvTotal < iLengthBytes)
{
iRecvPass = recv(ClientSock, ptr, iLengthBytes-iRecvTotal, 0);
if(iRecvPass != SOCKET_ERROR)
{
iRecvTotal += iRecvPass;
ptr += iRecvPass;
}
else
{
if(WSAGetLastError() != WSAEWOULDBLOCK)
return -1;
}
}
return iRecvTotal;
} Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
If you are sending as raw values, then a value of 0 would be seen as a terminator for the string.
Elaine
The tigress is here
|
|
|
|
|
Does anyone know if there is a way to programmitically burn a CD from a Visual C++ application running under Windows XP?
I have checked with Roxio and they don't expose their burning engine to programs.
Martin
|
|
|
|
|
|
There sure is, it's called IMAPI and is fully documented in MSDN.
--Mike--
"I'm working really, really fast at the moment, so a 3 minute outage becomes, due to time dilation, a 5 minute outage."
-- Chris Maunder, relativistic system administrator
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
I have successfully used IMAPI to burn CDs on Windows XP, however, I can't seem to get around the 31 character filename limit. Any suggestions?
|
|
|
|
|
Yep, check out IMAPI in MSDN.
[edit] Darn it! Should have checked Michael's message first! [/edit]
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi!
I need to know how many lines there are in a text file.
I open the file with fstream... Is there any function or anything that will help me to count the lines?
Thank you very much for your future answers!
Well... I am a beginner ...
|
|
|
|
|
One way is to read through the file and count all occurrences or \r\n.
|
|
|
|
|
If you can use the C routines then you can use standard I/O (stdio.h).
fopen() [open file]
fgets() [reads a single line from file]
fclose() [close file]
Just put fgets() in a loop and as long as there is no error keep reading one line at a time, while incrementing the counter.
INTP
|
|
|
|
|
You could do something like this if you have to:
#include <fstream.h>
void main()
{
fstream infile;
char c;
int i = 0;
infile.open("data.txt", ios::in);
while(!infile.eof())
{
infile.get(c);
if(c == '\n')
i++;
}
i++;
cout << "data.txt has " << i << " lines.\n";
}
-Nick Parker
|
|
|
|
|
Or alternatively:
ifstream File;
File.open("data.txt");
int i = 0;
while ( !File.eof() )
{
File.getline(szBuffer, sizeof(szBuffer), '\n');
i++;
}
cout << "data.txt has" << i << " lines." << endl;
|
|
|
|
|
I've added a CGridCtrl to my dialog in the SDI project just like in the tutorial. I provided the name MFCGridCtrl, just like in the tutorial. However, when I go to create a member variable so I can use it, the Class Wizard won't allow me to add a member variable. Did I miss a step??
|
|
|
|
|
I think you have to do that manually...
[EDIT]
Add this to your class definition:
CGridCtrl m_Grid;
Add this after CDialog::DoDataExchange(pDX); in your DoDataExchange(CDataExchange* pDX) member function
DDX_GridControl(pDX, IDC_GRID, m_Grid);
[/EDIT]
John
|
|
|
|
|
Thanks, I tried that. I copied it from the demo project. I didn't think you could do that.
|
|
|
|
|
If I am in my CWinApp class, how do I get access to ALL documents. Reason is, I want to update all my documents when the Word Wrap option changes. Thanks!
|
|
|
|
|
You'll first need to call GetMainWnd(), then call GetActiveDocument().
|
|
|
|
|
This should do what you want:
POSITION pos = m_pDocManager->GetFirstDocTemplatePosition();
while( pos )
{
CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos);
POSITION pos2 = pTemplate->GetFirstDocPosition();
while( pos2 )
{
CDocument * pDoc = pTemplate->GetNextDoc(pos2);
if( pDoc )
pDoc->UpdateAllViews();
}
}
<pre\>
INTP
|
|
|
|
|
I have an application, and basically I just want to make it able to dock at the bottom of the screen... Its not a dialog, its simple a Win32 API CreateWindow() WS_OVERLAPPEDWINDOW window... Is there an easy way to do this?
|
|
|
|
|
|
I know this is a studid question, but I am only able to create an instance of a struct.
I actually need an instance of the struct container
I have created a struct in class RFMAccess and I'm trying to get the elements from it in another class.
<br />
struct TSimHeader<br />
{<br />
char Name[45];<br />
char Unit[45];<br />
double Min[45];<br />
double Max[45];<br />
int SignalCount;<br />
int SimStatus;<br />
<br />
}static TSimHeader_arr[10];
I can get them if I access them with the class name.
RFMAccess::TSimHeader_arr[j].Name[i];
I really don't want to have to type all of this so is there a way that I can create and instance of the container?
so I coule type s[j].Name[i]
I know, I know you guys feel like I have had the same kind of question for a week now.
Sorry, but I keep changing things around.
thanks for the help,
steven
|
|
|
|
|
No, not unless the other class was derived from RFMAccess. The statement s[j].Name[i] tries to resolve 's' to the calling class or any class it is derived from.
Even if this other class were made a friend class of RFMAccess, it still wouldn't help. This designation simply allows access to private and protected members, but you'd still have to qualify them.
|
|
|
|
|
So, your saying that I can't make and instance of the struct container?
steven
|
|
|
|
|
Saying "struct container" is redundant as a struct is a container of (different) data types.
That aside, I'm not sure what you are asking. Your RFMAccess class has a TSimHeader structure in it with 10 instances defined. In order to access any one instance, you'll need to use square brackets like you've shown. It makes no difference whether you use TSimHeader_arr[i], or s[i].
Here's a kludgy example:
class MyOtherClass
{
struct RFMAccess::TSimHeader *ts;
void foo( int x )
{
ts = &(RFMAccess::TSimHeader_arr[x]);
}
};
You could also add the following function to your RFMAccess class:
static struct TSimHeader *GetSingleInstance( int x )
{
return (&TSimHeader_arr[x]);
}
And use it in another class like:
void foo2( void )
{
struct RFMAccess::TSimHeader *ts;
ts = RFMAccess::GetSingleInstance(0);
}
Notice that qualification is still necessary for both usages.
|
|
|
|
|
OK I see what you are saying,
Thanks,
steven
|
|
|
|