|
Hi,
I have a derived CAsyncSocket class which is a protected member of a Derived CWinThread class
There are 4 of the derived CWinThread Classes each with their own derived CAsynSocket Class
I create or rather allocate storage for the derived CWinThread class on the heap via new
after I create the CWinThread derived class suspended and set various members as the ipaddr
Then I do a Resumethread
in the CwinThread::Initinstance I do the CAsyncSocket::Create
this is where the issue is
while tracing the code under VS debugger the code jumps out the CWinThread::Initinstance
back to my main line loop
When I allocate a CAsyncSocket Class on the stack outside of the loop and do a Create
everything is cool
I get a return code of 1
|
|
|
|
|
Hi
I moved my code from the initinstance to the CWinThread constructer and it worked ?
Don't know why
|
|
|
|
|
What was the issue? ...you never actually say what the problem was.
|
|
|
|
|
Hi
I have a loop in my CWinApp::Initinstance where I create 4 Derived CWinThreads
a derived CAsyncSocket class is a protected member
When I step into with the debugger to the CasyncSocket::create it takes a wild which is in the CWinThread::Initinstance it takes a branch out the CWinThread::Initinstance back to the loop as if there some sort of exception I tried a try { around the code but it didn't go to the catch it just jumped out of the CWinThread::Initinstance back to the loop
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
threadptr[i] = new SockCLeintThread(start_port);
if (threadptr[i] == NULL)
AfxMessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
ret = threadptr[i]->CreateThread(CREATE_SUSPENDED);
if(ret == 0)
errcd = GetLastError();
threadptr[i]->flags.is_connected = 0;
threadptr[i]->flags.busy = 0;
threadptr[i]->ResumeThread();
BOOL SockCLeintThread::InitInstance
{
AfxSocketInit();
ipaddr = (LPCTSTR)"10.0.0.205";
if(thisocket.Create(thisocket.port,SOCK_STREAM,(FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE),ipaddr)== 0)
{
error_code = thisocket.GetLastError();
}
DWORD value;
BOOL val, return_code;
const void *valptr = &val;
thisocket.AsyncSelect(FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE); val = 1;
return_code = thisocket.SetSockOpt(SO_KEEPALIVE,valptr,sizeof(BOOL)); val = 1;
return_code = thisocket.SetSockOpt(SO_OOBINLINE,valptr,sizeof(BOOL));
value = 1;
return_code = thisocket.IOCtl(FIONBIO,&value);
return_code = thisocket.IOCtl(FIONREAD,&value);
return_code = thisocket.IOCtl(SIOCATMARK,&value);
sockbuffer = new TCHAR[100];
}
When I move this code to the SockCLientThread constructor it works
|
|
|
|
|
Hello,
A wchar_t array contains two sentences inside which I need to save in two separate variables.
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";
I want to split in a way that first sentence and second sentence equals to these:
wchar_t first_sentence[MAX_PATH]=L"'This is the first sentence'";
wchar_t second_sentence[MAX_PATH]=L"'This is the second sentence'";
I am using below code but it does not work as expected.
#include "stdafx.h"
#include <wchar.h>
#include <windows.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t str[] = L"'This is the first sentence' 'This is the second sentence'";
wchar_t first_sentence[MAX_PATH];
wchar_t second_sentence[MAX_PATH];
swscanf_s(str, L"'%s' '%s'", first_sentence, _countof(first_sentence), second_sentence, _countof(second_sentence));
printf("first_sentence=%ls\nsecond_sentence=%ls\n", first_sentence, second_sentence);
system("PAUSE");
return 0;
}
As far as I understand swscanf_s is pausing when it encountes the first white space. How am I suppose to get whole string between single quotes with swscanf_s please?
|
|
|
|
|
the format specifier you want is %[^'] i.e. all chars that are not a single quote.
|
|
|
|
|
Thank you very much for your help. Works great.
One more question please. How can I select all the characters till to a specific word?
Say, I want to select all characters till "the" word? I tried
%[^(the)]
but to no avail.
Cheers
|
|
|
|
|
Even if that worked, it probably wouldn't do what you wanted - e.g. if the input text was "a small withered man with the axe", you'd get "a small wi" copied to your output variable.
Depending on what you're trying to do, maybe regex() might be a better tool in this case, though I'm not sure about regex() and wide strings.
|
|
|
|
|
I see. Thanks again for your help.
Cheers
|
|
|
|
|
Hi,
In server program I do a createfilemapping followed by MapViewOfFile
in The Client I do a OpenFileMapping using the name last parameter from CreateFilemapping
and then I do a MapViewOfFile and I get 2 different address from MapViewOfFile in the
Client and Server
shouldn't they be the same since its shared storage
Thanks
|
|
|
|
|
No. They will be different because the processes are different.
The addresses will be different but the data is guaranteed to be the same between the two.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Technically:
the physical memory is the same, but the MMU maps it to available free logical address in the destination process.
|
|
|
|
|
|
Hi
If Do a CreateProcess with bInheritHandles set to true
and I create a event with name/string in the Parent Process
In the Child I do a OpenEvent
Do I still have to do a DuplicateHandle to have access to the event handle
|
|
|
|
|
No you don't need to duplicate handle if you have enabled inheritance int the CreateEvent of parent process setting lpEventAttributes parameter.
You need a duplicated handle if the event is created in the child process.
For detailed info see[^].
|
|
|
|
|
|
What I am trying to do is each thread gets to print out its 5 characters before potentially yielding to another thread. It works but it does not do what I want. THanks for help.
for (unsigned i = 0; i < _repCount; ++i) {
unique_lock<mutex> lck(mtx);
cv.wait(lck, []{return !inUse; });
inUse = true;
for (auto c : _printMe) {
cout << c;
cout.flush();
}
inUse = false ;
}
|
|
|
|
|
ramonlarodo wrote: It works but it does not do what I want. What do you want?
|
|
|
|
|
Hi everybody,
is there a possibility to edit the year in the short format(yy) aswell?
I set the format "dd.MM.yy" and the date is shown correctly as "23.04.15"
But if I place the cursor in the year-section, the year switches from 15 to 2015.
I need that the year keeps 15 at the edit-mode.
Big thanks for any information
Regards
-baerten-
|
|
|
|
|
What edit mode are you talking about? Where is this value displayed that changes, and how is the change displayed?
|
|
|
|
|
Thanks for your reply
I call it edit mode if I place simply the cursor into it.
Without the focus the control displays 24.04.15
If I place the cursor in the day section of the control it displays 24.04.15
If I place the cursor in the year section of the control it displays 24.04.2015
I use Visual Studio 2013. It has the same behaviour on Windows 7 and 8
Thanks for any information
|
|
|
|
|
So exactly what programming problem are you having?
|
|
|
|
|
I use the short format of the DateTime Control.
So, I want only 2 digits for the year.
But if I place the cursor in the year, it becomes 4 digits.
Is there a possibility to avoid this?
To recreate the OnDraw/OnKey logics is not so rational
|
|
|
|
|
Hi Guys,
I have a weird problem debugging my project.
I have upgraded my VS 2008 project to VS 2010 by opening the solution file and successfully built the project (debug and release configurations). But when I run the project within Visual Studio I get the following weird error saying:
"Unable to start program"
"System cannot find the file specified"
Anyone knows hows how to fix this issue.
thanks
|
|
|
|