|
ForNow wrote: Would I get ",Asid=01" I don't believe so, I think you'd get "01" as the format() would overwrite your initial value.
How about trying.
CString buffer;
buffer.Format(",Asid=%2x", asid);
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Thanks so much I got to get into the habit of using CString
|
|
|
|
|
Try making a small test project and play around with the format syntax and the specifiers. Knowing it will help you with other (non-CString) areas as well.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Hi,
I'm developing a client-server C language in Windows.
The client connects to server and every 5 seconds send a message. The communication is OK and server receives messages.
I try to develop multi-client (.bat file starts client.exe) - server but I have problem: A segmentation fault appears after n messages.
This is my code:
main
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0){
printf("Failed. Error Code : %d",WSAGetLastError());
return 1;
}
if((s = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET){
printf("Could not create socket : %d" , WSAGetLastError());
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons( 8888 );
if( bind(s ,(struct sockaddr *)&server , sizeof(server)) == SOCKET_ERROR){
printf("Bind failed with error code : %d" , WSAGetLastError());
}
listen(s , 10000);
puts("Waiting for incoming connections...");
while( TRUE ) {
new_socket = accept(s , (struct sockaddr *)&client, &c);
if (new_socket == INVALID_SOCKET){
printf("accept failed with error code : %d" , WSAGetLastError());
}else{
clientInfo[cont].clientAddr = client ;
clientInfo[cont].hClientSocket = new_socket;
hClientThread[cont] = CreateThread(NULL,0,( LPTHREAD_START_ROUTINE ) cliTh1,( LPVOID ) &clientInfo[cont],0,&dwThreadId ) ;
if ( hClientThread[cont] == NULL ){
printf("Unable to create client thread");
} else {
printf("thread OK\n");
CloseHandle( hClientThread[cont] ) ;
cont++;
}
}
}
Thread function (cliTh1)
DWORD WINAPI cliTh1( LPVOID lpData ){
struct CLIENT_INFO *pClientInfo;
char szClientMsg[250];
static int j = 0;
int i = 0;
char *message;
pClientInfo = (struct CLIENT_INFO *)lpData ;
printf("SOCKET:%d - THREAD_ID:%ld\n", pClientInfo->hClientSocket, GetCurrentThreadId());
while ( 1 ){
if(WSAGetLastError()){
printf("CURRENT:%ld\n", GetCurrentThreadId());
closesocket(pClientInfo->hClientSocket);
ExitThread(GetCurrentThreadId());
}
if(recv( pClientInfo -> hClientSocket, szClientMsg, sizeof( szClientMsg ), 0 ) > 0){
if(j>5000){j=0;};
strcpy(bufferRx[j].packet, szClientMsg);
for(i=0; i < sizeof( szClientMsg ); i++){
szClientMsg[i] = 0;
}
printf("RECEIVE %d: %s",j, bufferRx[j].packet);
j++;
}
}
return(TRUE);
}
I read on Internet, but I don't know where is Error.
Thanks.
|
|
|
|
|
You are accepting an unlimited number of connections but did not check if cont reaches the limit of your clientInfo and hClientThread array sizes. This results in segmentation faults when cont is equal to the number of array items.
|
|
|
|
|
Thanks for reply.
I declared:
HANDLE hClientThread[65000]
struct CLIENT_INFO clientInfo[10000]
I launch 20 client process.
|
|
|
|
|
I find my error!!!! thanks a lot. You advised me to control array size....
|
|
|
|
|
So that is not the error source. But why you are using different sizes?
Another possible source is in these lines in the thread function:
if(j>5000){j=0;};
strcpy(bufferRx[j].packet, szClientMsg);
This requires that the packet contains a null terminated string. You are also using a constant value for the bufferRx size without showing the definition or allocation. It would be better to use a variable when it is allocated or sizeof() when using a fixed size.
|
|
|
|
|
Thanks for your advices!!!! I will correct code source.
|
|
|
|
|
I picked up a function RecursiveDelete on the internet, as I needed to erase all files and folders on an SD card (as part of a larger project). I was having problems insofar as the function would fail on removing the folders after CFileDialog DoModal - there were two nested folders, the deepest failing with code 32 ("in use by another proicess") and the shallowest with 145 ("folder not empty" - expected !)
However, if I call the function BEFORE the DoModal, then everything works fine.
I have extracted the relevent code into a simpler project and it still fails
Perhaps some kind soul can throw some light on why this is so !!
CFileDialog dlgFileBrowse(true);
UINT uiFileBrowseDlgRC;
RecursiveDelete("F:");
uiFileBrowseDlgRC = dlgFileBrowse.DoModal();
void CDeleteFolderTestDlg::RecursiveDelete(CString szPath)
{
CFileFind ff;
BOOL bResult;
CString path = szPath;
if(path.Right(1) != '\\')
path += '\\';
path += "*.*";
bResult = ff.FindFile(path);
BOOL bItemDelete;
DWORD dwLastError;
CString szFilePath;
while(bResult)
{
bResult = ff.FindNextFile();
if (!ff.IsDots() && !ff.IsDirectory())
{
szFilePath = ff.GetFilePath();
bItemDelete = DeleteFile(szFilePath);
if(!bItemDelete)
dwLastError = GetLastError();
}
else if (ff.IsDirectory() && !ff.IsDots())
{
path = ff.GetFilePath();
RecursiveDelete(path);
bItemDelete = RemoveDirectory(path);
if(!bItemDelete)
dwLastError = GetLastError();
}
}
}
Doug
modified 16-Jun-15 3:39am.
|
|
|
|
|
I assume that the CFileDialog object contains a handle to the directory once it's opened and that the handle is freed when the dialog object is destroyed. You could try the following:
CFileDialog * dialog = new CFileDialog(true);
dialog->DoModal();
delete dialog;
RecursiveDelete("F:");
Alternatively you could try:
{
CFileDialog dialog(true);
dialog.DoModal();
}
RecursiveDelete("F:");
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Snap.
You beat me by seconds with the solution.
|
|
|
|
|
Freak30 wrote: CFileDialog * dialog = new CFileDialog(true);
dialog->DoModal();
delete dialog;
RecursiveDelete("F:");
Hi Freak30,
Tried the dynamic allocation of the CFileDialog (and deletion before the call to RecursiveDelete)as you suggested, but still get the same result (files deleted, but deepest folder gets RC=32 and shallowest gets RC=145.
Very confused !!
Doug
|
|
|
|
|
When dlgFileBrowse.DoModal() returns, the dialog window has been closed but the object itself still exists and may have open file handles. These should be closed by the destructor of the browse dialog. I have not tested this but it seems a probable reason.
So you should try to call your delete function after the browse dialog object is destroyed:
UINT uiFileBrowseDlgRC;
{
CFileDialog dlgFileBrowse(true);
uiFileBrowseDlgRC = dlgFileBrowse.DoModal();
}
RecursiveDelete("F:");
Alternatively you can create the dialog using new and delete it before calling RecursiveDelete .
|
|
|
|
|
Apologies for the double posting - thought that the original hadn't worked !!
Tried dynamic allocation of dialog and subsequent deletion before calling RecursiveDelete as Freak32 suggested, but get exactly the same result. Wierd !!
Could someone else run this and see if they can reproduce this behaviour ? (Driving me mad !)
Doug
|
|
|
|
|
A quick web research brought some more infomation.
CFileDialog will change the current working directory which may lead to the locked directory. So you may try to also set the current working directory to something else (e.g. to another drive) before calling your delete function:
SetCurrentDirectory(_T("C:\\"));
|
|
|
|
|
Hi Jochen,
Just done a quick check (I actually used _chdir) and that SEEMS to have fixed it. Hopefully, when I migrate these changes to my REAL code, it will stay fixed !
Many thanks to everybody who helped with this - wierd problem, eh ?
Doug
|
|
|
|
|
Thank you for your feedback. _chdir will internally call SetCurrentDirectory .
A directory that is selected as current directory is treated like a file in use and can't be deleted. It seems that the file dialog selects the actually shown directory as the current one and does not change it back. There is an OFN_NOCHANGEDIR file dialog option to restore the original directory but that is ignored for opening files (only supported for the Save as dialog).
|
|
|
|
|
Still learning how to code wrote: I picked up a function RecursiveDelete on the internet, as I needed to erase all files and folders on an SD card... Why not just use SHFileOperation() with the FO_DELETE operation?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
So I have a video stream of known resolution and I have a VR headset via HDMI at a known resolution.
Is there an existing library to create the slight fisheye and side-by-side layout for these headsets?
Target: Win 7/8/10
|
|
|
|
|
I have a csv file. I want to load the csv fil to a database.
I tried by using CDAOSatabase instance with 'Microsoft Text Writer' jet enine.
( One Problem I found that when I execute a query to ceate a new table, the file equivalent to the new table is created in physical disk, even though I didn't commit the transaction)
Also I heard that in windows there will not be a 64bit 'Microsoft Text Writer' in winows 64 bit.
( In my spec there is no MSOffice installed separately on this winows 64 bit machine )
Could ou please let me know is there any solution to use 'Microsoft Text Writer' in Windows64 bit machine without Microsoft office installed.
aks
|
|
|
|
|
|
Hello eeryone, I am Mark, am attending Foothill College in SOCAL and I am cmpletely new to all of this. I am having trouble with my first assignment, I will show you. I am on DEV C++ :
#include
using namespace std;
int main()
{
cout<< "Tran says this is her first computer program.";
}
{ -----------------------------------------
intmain()
cout<< "Tran says that.";
cout<< "this is her first computer program.";
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that,";
cout<< "this is her first computer program.";
cout<< "Tran said that, "This is my first computer program."";
cout<< "Train said that,.";
cout<< ""this is my first computer program."";
cout<< "Tran said that,.";
""this is my first computer program."";
cout<< "Tran said that.";
cout<< ""this is my first computer program."";
}
This is what My teacher said :
Hi Mark,
You can only have "int main()" once in your program. Once you put the close curly brace to end it, you can't have any more code below that. If you take another look through the lesson and the textbook reading, you'll see that all of the examples follow that pattern.
The solution is to put all of the cout statements inside the first set of curly braces, so you don't need any additional curly braces.
Dave
Now, I did this here and this is what happened :
#include
using namespace std;
int main()
{
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that.";
cout<< "this is her first computer program.";
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that,";
cout<< "this is her first computer program.";
cout<< "Tran said that, "This is my first computer program."";
cout<< "Train said that,.";
cout<< ""this is my first computer program."";
cout<< "Tran said that,.";
""this is my first computer program."";
cout<< "Tran said that.";
cout<< ""this is my first computer program."";
}
This is what my computer said :
( I want to post the Pic, I cannot copy and paste it down.Can somone show me how topost pics on here ? Thanks, If I cannot then I will privately email you. )
So I did what the teacher said to do and then I compile and got more lines all messed up. I am confused...
Thanks
|
|
|
|
|
Start simple. First have only one statement within main() :
#include <iostream>
using namespace std;
int main()
{
cout << "Tran says this is her first computer statement." << endl;
return 0;
}
The above is the complete program. No other statements above and below these.
Then, upgrade the program to have two statements:
#include <iostream>
using namespace std;
int main()
{
cout << "Tran says this is her first computer statement." << endl;
cout << "Tran says this is her second computer statement." << endl;
return 0;
}
And then, go on progressively increasing the complexity.
Some compilers need the return 0 statement since your main is returning int .
|
|
|
|
|
I get it, lets try that.
Nope it still wont compile..
Ill keep in touch and sow the tutor tommorow.
Thanks
|
|
|
|