|
I write one multithread program to download file using CAsyncSocket. I got one problem. Can anyone help me out?
I derive my thread class from CWinThread. In thread class
I new one CAsyncSocket instance. and create and connect it
when It is one thread, it can work normally.when it is 2 threads
it can work normally at most. but when thread numbers is large,
they will cause exception. at the same time,for per thread, when socket OnConnect arise, it return WSAEADDRINUSE error.
I found another problem. when I debug 2 thread. during socket
Create call. the socket in the first thread can create normal,
but the socket in the second thread, It will cause assert .
It means the the m_hSocket has been in socket map.
I didn't know why this happen. I think socket map should be
thread local.
thanks
|
|
|
|
|
I have read this article before. But I didn't want to pass handle between
thread, I generate one CAsyncSocket instance for per thread, and do owner
job in thread, I didn't detach,attach handle from one thread to another
I didn't know if it is possible.
|
|
|
|
|
CAsyncSocket is probaly not what you want to use with multiple threads, but you can use this class to connect multiple sockets (download multiple files) in ONE thread... it works nearly unblocking.
Well, with multi threaded networking (if you REALLY need it that hardcore) you might have to use the "naked" socket API... see http://www.ecst.csuchico.edu/~beej/guide/net/ ... or any other API that Microsoft provides (see MFC articles in Code Project).
Hope it helps, Moak
|
|
|
|
|
Can you explain why not using CAsyncSocket for per thread?
I cannot figure out
|
|
|
|
|
it was not designed for that purpose.
it serves as asynchronous networking class: unblocking network access with events when a operation (like connect/read/write) has finished. in theory you could use it in multiple threads, but as far as I remember Microsoft's implementation was not multi thread safe (you get an assert with some functions in a debug build if you still try).
Perhaps rethink your network strategy, perhaps you can go single threaded and use CAsynSocket within one thread context (simple application code). However, the class is not very perfect it has some problems with DNS lookups (they block).
|
|
|
|
|
hi,I have see you question about multithreaded downloader.now do you work it out.I need this module for my project.Would you please give me the code?
thank a lot!
|
|
|
|
|
Can someone demonstrate how you can use the put, peek and more of the functions in the fstream group by maybe making an example or better yet a program.
|
|
|
|
|
try the MSDN library
or any other help documents.
|
|
|
|
|
I did but they don't have a description for it, they only give how to use it. Please can someone help me... I never learned about alot of file functions and want to take advantage of functions that are in the fstream family.
|
|
|
|
|
IS there any STL data structure which behave like CMapPtrToPtr
thanks in advance
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Perhaps
std::map<void*,void*>
--
Joel Lucsy
|
|
|
|
|
Hi
I involved in a project that will need to create file database for usage..
I know of 2 ways,
1) is to use structure and fwrite, fread to store the database using C Runtime functions
2) Is to use WriteFile And ReadFile to store the database using APIs..
Anyone know about the limitations or problems with this 2 methods or is there a better way of storing file database. the accessing will be quite intensive and i need reliablity, stability and fast access.
Anyone that has been using this 2 methods can comment?
Thank you for your time and efforts. Greatly appreciated.
|
|
|
|
|
IceBerG71 wrote:
is there a better way of storing file database. the accessing will be quite intensive and i need reliablity, stability and fast access.
Have you considered an Access database? It satisfies all of your requirements much better than your current considerations.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Sorry, i did not furish with more details. the target device is on an embedded device with customize Window CE and using embedded Visual C++ 3.0. So i dun think Access is a good choice since memory consideration is critical.
i have been using Access on my PC application and it had given me quite a few problems.
|
|
|
|
|
I'm new to programming so I don't know much. How do I get a pointer to an in-memory device context if I want to move that area to another place, I don't mean bitblt and bitbltting to another dc but a portion of memory which I can operate on? Thanks
|
|
|
|
|
you will have to get the dc from which you can get a bitmap and from the bitmap the LPBYTES ,if you want to do sme fancy work do it with these bytes then convert them in to bitmap and use them
|
|
|
|
|
Can you provide a sample code?
|
|
|
|
|
When I make any changes in a cell, it only saves the change when I push enter otherwise, change doesn't apply to mdb. What I want to do is to save this change whenever user input a value. how can i acheve this?
Regards,
Shin
|
|
|
|
|
Simply, use the method of your class (recordset) like SetRecordsetValue or other(depends on the class you use).
The most important mistake - you use class DataGrid to set changes, but it is incorrect. You must use directly class Recordset-based.
|
|
|
|
|
Yes,
I just want to get the event where I can save the record.
Sorry to make you confused.
Regards,
Shin
|
|
|
|
|
I have an SDI with a listview.
Is there any way to add another window to the mainframe, besides use of controlbars? I want another window next to the listview.
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
you will probably have to use Splitter windows
or use formview and place mulitple controls
|
|
|
|
|
I have an MFC Win32 client application that needs to generate PDF
files. The easiest way to do it is to have our customers purchase and
install Adobe Acrobat, and then our program will use the "Adobe PDF" printer
driver to output our text to PDF files.
From any application like Notepad, Word, Excel, using the Adobe PDF writer
works fine when I do File\Print, click "Print to File", uncheck the printer
property of downloading fonts to printer--my PDF file is created fine.
I need to do this from C++. The user is not going to use File\Print in our
app, we need to convert files as we go.
Something is not working in my code which I've pasted below. I'm using OpenPrinter
to open the "Adobe PDF" printer (return code is good), I call StartDocPrinter setting
my output file name to "D:\temp\test.pdf" and set the datatype either to RAW or NULL,
same result occurs: a test.pdf file is created, but it is pure text "this is a test"
instead of PDF content.
Anyone see what I am doing wrong? It appears to me that I need another code for
pDatatype. Or should I not be using these OS calls for a printer driver?
#include <winspool.h>
...
BOOL PrintStringDirect( LPCSTR Str, LPTSTR PrinterName, LPSTR DeviceName )
{
BOOL bRet = FALSE;
HANDLE hPrinter;
if ( OpenPrinter( PrinterName, &hPrinter, NULL ) )
{
DOC_INFO_1 doc_info = {0};
doc_info.pDocName = "Test Document";
doc_info.pOutputFile = DeviceName;
//doc_info.pDatatype = (LPTSTR) NULL;
doc_info.pDatatype = "raw";
DWORD jobid = StartDocPrinter( hPrinter, 1, (LPBYTE)&doc_info );
if ( jobid != 0 )
{
DWORD written;
DWORD dwNumBytes = lstrlen( Str );
WritePrinter( hPrinter, (void*) Str,
dwNumBytes, &written );
if ( written == dwNumBytes )
bRet = TRUE;
}
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
}
return bRet;
}
PrintStringDirect("This is a test", "Adobe PDF", "D:\\temp\\test.pdf");
|
|
|
|
|
You should be creating the print job in exactly the same way as you would for a normal printer, but pass a filename through in the DOCINFO object so its written to a file instead.
If your doing this in MFC, this article of mine should be of help.
Setting default printer in MFC[^]
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Roger Allen wrote:
You should be creating the print job in exactly the same way as you would for a normal printer, but pass a filename through in the DOCINFO object so its written to a file instead.
Hmmm...I thought I was already doing what you said here:
DOC_INFO_1 doc_info = {0};
doc_info.pDocName = "Test Document";
doc_info.pOutputFile = DeviceName;
//doc_info.pDatatype = (LPTSTR) NULL;
doc_info.pDatatype = "raw";
DWORD jobid = StartDocPrinter( hPrinter, 1, (LPBYTE)&doc_info );
where DeviceName = "D:\\Temp\\test.pdf"
|
|
|
|