|
csrss wrote: ...my server prototype is running on localhost and not event close to be loaded so every call to wsasend / wsarecv completes right away without waiting and i am manually posting completion packets with PostQueuedCompletionStatus to simulate expected behavior, where key param is my struct of course, and IO operation is updated before packet is actually posted. So on the other end, i am parsing IO operations correctly. But, i am thinking now, if wsarecv will block and completion packet will arrive some time later
Maybe overthinking it? First, even if wsasend/wsarecv complete immediately, you still get completion packet from IOCP on an IOCP thread, so no need to handle special case of error on wsasend/wsarecv if there's no error or error code is "pending". Second, WSARecv won't block on an overlapped operation, so I'm not sure what you're thinking there.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Alright, thanks guys, going to experiment a bit longer with this.
By "blocking" i meant a situation where you "post" wsarecv / wsasend and it returns error_io_pending and then awaits for completion packet in worker thread :P
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
csrss wrote: By "blocking" i meant a situation where you "post" wsarecv / wsasend and it returns error_io_pending and then awaits for completion packet in worker thread :P
Gotcha. But technically that is not blocking...that's asynchronous I/O
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
One framework I created that used ICOP had the following classes:
IoObj - Base class for I/O
IoHnd - IFS handle based
File - OS file access
NetSocket - Network socket
NetIpClnt/NetIpSvc, NetTCP*, NetUdp*, NetIrda*, NetBth*, ...
NetFPT*, NetNNTP*, ...
WSAOVERLAPPED
IoOL - Base overlapped; adds flags, timestamps, type, control, buffer
NetIoOLAddr - specialied for sendto/recfrom, contains remote address
NetIoOLAccept - specialized for handling AcceptEx
IoCP - I/O completion port
The IoCP had the main posting functions and GetQueuedCompletionStatus loop.
To post a msg on an IoCP you'd pass an IoObj* and IoOL*.
The IoObj* would be the key, the IoOL* the overlapped (per call).
The IoCP GetQueuedCompletionStatus loop would call (something like) IoObj->Msg(IoOL*).
With the above you can use one or more IoCP instances to handle any combination of files, sockets, or other IoObj based objects (e.g. jobs/tasks).
I found both having key and OL convenient. Without an explicit key param you'd have to add it as state to your extended OL ... which you may want anyways.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Thanks for the reply. Currently i am trying to dig into IOCP and get some descent understanding what's going on behind scenes. Could you check my latest reply to Mark? There is some important question i am trying to figure out though. Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi all,
i want to encrypt/decrypt the string.
what method or option is gud for this.
please help me for this.
if possible please provide me any sample or example.
thanks in advance.
|
|
|
|
|
If you are working under windows then check out The Cryptography API[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Depending on your needs, the following may be sufficient:
CryptProtectData()
CryptUnprotectData()
They encrypt using either machine or user specific key and help you avoid having to mess with the Crypto API.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
From my application, I need to launch another window which will display some data like an SDI application. Also, this launched window should
(a) find a separate mention in taskbar
(b) close when my application is closed
I think a good way to achieve this is to have an MFC DLL, exporting a function to launch this other window as we create an SDI document.
I don't want to perform any File I/O from the DLL currently, so I inherited from
CDocument without putting any code inside
Serialize .
So I have:
CSingleDocTemplate *pPeopleListDocumentTemplate;
pPeopleListDocumentTemplate = new CSingleDocTemplate(IDS_DUMMY_STRING, RUNTIME_CLASS(CPeopleDoc),
RUNTIME_CLASS(CFrameWnd), RUNTIME_CLASS(CDLLDocView));
That is, I give my frame class as CFrameWnd.
This kind of worked: I do see the document when I call the DLL function. But, the window is totally "transparent" initially, and takes the appearance of whatever's present on the screen behind it, and retains it as I move it. What are the properties of the Frame which I need to change? What will be a good time to change it?
|
|
|
|
|
How to import database into C++ or C++ to any other applications..?
|
|
|
|
|
Your question is not clear, you cannot import a database into C++. You can, however, access a database using a program written in C++.
The best things in life are not things.
|
|
|
|
|
You don't typically "import" a database into an application. You simply access it using some sort of common interface, usually over a network or internally (using sockets is the most common way), using a common language. A common interface language for databases is SQL, a query based language that defines the type of query/response system and language.
There's several libraries that are available from different parties that make this task a lot easier. Here's a couple (for SQL, its up to the database maker what languages they support):
http://www.sqlapi.com/[^]
http://soci.sourceforge.net/[^]
|
|
|
|
|
Hi ppl.
I have this code:
void descargar(string path1, SOCKET sock)<br />
{<br />
string variable = getenv("windir");<br />
char* variablee = getenv("windir");<br />
string variable1 = getenv("userprofile");
char* variable11 = getenv("userprofile");
<br />
strcat(variablee,"\\System32\\ftp.exe -s:");<br />
strcat(variablee,variable11);<br />
strcat(variablee,"\\command1.txt host.com");<br />
FILE * file;<br />
file= fopen((variable1+"\\command1.txt").c_str(),"w");
if(file != NULL)<br />
{<br />
fputs("name\n",file);
fputs("pass\n",file);
fputs("cd /public_html\n",file);
fputs(("put \"" + path1+"\"").c_str(),file);
fputs("\nquit",file);<br />
fclose(file);<br />
}<br />
<br />
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcInfo;
memset(&ProcInfo, 0, sizeof(ProcInfo));
memset(&StartInfo, 0 , sizeof(StartInfo));
StartInfo.cb = sizeof(StartInfo);
int res = CreateProcess(NULL,variablee, NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo);
{<br />
::WaitForSingleObject(ProcInfo.hProcess, INFINITE);<br />
CloseHandle(ProcInfo.hProcess);<br />
CloseHandle(ProcInfo.hThread);<br />
}<br />
}
The problem, is that, the first time i call this function works fine, but the second time it is called, it gives segmentation fault error in line:
file= fopen((variable1+"\\command1.txt").c_str(),"w");
Any idea?
Thanks
|
|
|
|
|
Hope so, but likely not -
I'd try something along these lines:
char filenameToOpen[MAX_CHAR];
sprintf(filenameToOpen, "%s\\command.txt",variable1.c_str());
file = fopen(filenameToOpen, "w");
If that failed, I'd ask myself if I'd closed the file between each time it was opened as I can't remember how whether or not fopen opens the file for exclusive access or not.
|
|
|
|
|
According to the C++ documentation, you are not allowed to change the value returned by getenv().
http://www.cplusplus.com/reference/clibrary/cstdlib/getenv/[^]
Get environment string
Retrieves a C string containing the value of the environment variable whose name is specified as argument. If the requested variable is not part of the environment list, the function returns a NULL pointer.
The string pointed by the pointer returned by this function shall not be modified by the program.
In these statements,
strcat(variablee,"\\System32\\ftp.exe -s:");
strcat(variablee,variable11);
strcat(variablee,"\\command1.txt host.com");
you are appending to (altering) the contents of the memory pointed to by the return from getenv(). You need to use a temporary location to copy the data and only then start appending. Remember that strcat does not do additional allocation, it just blindly appends to memory.
Lastly, you have both char * and string copies of these environment variable contents. You should use the string versions which will do the copying for you and remove the use of the char * versions.
|
|
|
|
|
Hi. So, i got my custom static control (class which inherits from CStatic), which displays a text on a dialog window and thats it. Now i am trying to determine its style, which was sat in resource editor. For example, center image was sat, SS_CENTERIMAGE, so i am doing this:
DWORD dwStyle = this->GetStyle();
if((dwStyle & SS_CENTERIMAGE) == TRUE)
{
::AfxMessageBox(L"center image");
}
It is not working. Nothing is working actually. I am trying to check text alignment - not working, what am i doing wrong? Thanks.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
csrss wrote: if((dwStyle & SS_CENTERIMAGE) == TRUE)
& is not a boolean operation, nor is SS_CENTERIMAGE equal to 1 . Try:
if ((dwStyle & SS_CENTERIMAGE) == SS_CENTERIMAGE)
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Thanks!
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I build an app w/VC++6 . I design a window with an EDIT CONTROL (IDD_MYEDIT) , associate a CEdit control (m_myedit ). I switched on the PASSWORD style of the control.
Can be triggered this style on or off during the program running?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
This should do it:
void ToggleStyle(HWND hEdit)
{
if(SendMessage(hEdit,EM_GETPASSWORDCHAR,0,0) == '*')
SendMessage(hEdit,EM_SETPASSWORDCHAR,0,0);
else
SendMessage(hEdit,EM_SETPASSWORDCHAR,(WPARAM)'*',0);
SetFocus(hEdit);
}
You can have a look here[^] for an explanation, if you're interested
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thx I will try it tomorrow. It is 2105.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
As far as I know, and according to the docs[^], after the edit control has been created, the ES_PASSWORD style can't be changed.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That's true, you can't add or remove ES_PASSWORD directly with SetWindowLong, but with EM_SETPASSWORDCHAR[^] you can still have the desired effect.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Cool thanks!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How to create a modeless or embedded CFileDialog, GetOpenFileName() or GetSaveFileName() into user Dialog?
Thanks
|
|
|
|
|