|
The only other thing I can suggest is to search for issues with ADO and BLOBs. I don't remember having issues with them in the past, but it has been a while since I used them.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks for all the help....
Chris
|
|
|
|
|
I have great news. I finally figured it out. The problem was neither storing the file into the data nor getting the file out of the database. The problem was in my function to retreive the file out of the database I overloaded the = operator to copy RS_FILEs to each other and didn't copy a CLongBinary to the new CLongBinary. After doing this everything works perfectly.
Chris
|
|
|
|
|
Hello,
I'm having an issued figuring out how to use wininet to post form data to a website. So far I've been able to connect, send requests, and then read the result. However, I cannot seem to send form data to the website, and then read the resulting html the server sends back., (I.E. filling out the search form on the codeproject website.) I'm using the MFC version of wininet.
I connect:
CHttpConnection* pHttpConnection = sess.GetHttpConnection("www.codeproject.com");
sess is the CInternetSession object.
Then I create a request:
CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/");
CString header = _T("Content-Type: application/x-www-form-urlencoded");
CString mdata = _T("Search=wininet help");
pFile->SendRequest(header, header.GetLength(), (LPVOID)(LPCTSTR)mdata, mdata.GetLength());
When I do a pFile->Read() however, all i have received is the codeproject homepage, not the result from entering "wininet help" into the search form. Do I need to format the header differently? Or am I not requesting the correct object with OpenRequest? What am I missing?
Any help on this would be much appriciated. I'm new to wininet, and to writing internet client applications, so please bear with me, heh.
Thanks.
|
|
|
|
|
epicyeti wrote: CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/");
Last time I checked, there was no action associatd with the root/index for CP. I believe you want it to read:
CHttpFile* pFile = pHttpConnection->OpenRequest("POST", "/info/search.asp");
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Ok, so the object parameter(the second one) of OpenRequest should be the Action that is in the form. Do I need to parse the html to find this or is there an easier way to enter the form data? Also, how should the form data that i want to enter be formated? I tried:
CString mdata = _T("Search=wininet");
but it didn't seem to work.
btw, I like your sig.
|
|
|
|
|
The second parameter to OpenRequest will be an executable (cgi script, asp page, dll, etc). You will need to parse the HTML to see what fields they have (you can use a GET request on "/" to do that). Its been a while since I used POST in the raw form, but it should be something like "target=wininet" (the name of the form is "Search", but the field you are concerned with is named "target"). If there are multiple fields, they should be separated by a "&" (e.g. "field1=value&field2=another%20value ... etc").
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Sweet, thanks a lot man. I might have more questions, but i'm good for now.
|
|
|
|
|
|
I've created a Dialog that after some input collects data until the buffer is full or the user click on the Stop button.
The problem I'm having is I have a while loop the does the data collection code and once my gui has entered this loop all buttons in the dialog box have no functionality... (I can't click on anything). How would I check to see if the user has clicked on the "stop" button?
At 1st I thought maybe:
<br />
while( ... || ... || (m_nStopBtn.GetCheck() )<br />
{<br />
...<br />
}<br />
but that didn't work since the gui won't let me click on the stop button...
What could I be doing wrong?
Thanks,
Kitty5
|
|
|
|
|
you shouldn't put huge processes into the GUI thread...
move that loop into a worker thread to avoid the GUI to be frozen
|
|
|
|
|
You beat me to that answer :P
Also, make sure you use proper synchronization objects when doing this (do NOT just try to check a boolean variable each iteration of the loop to see if you should stop!).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
:->
Zac Howland wrote: NOT just try to check a boolean variable each iteration of the loop to see if you should stop!
of course
|
|
|
|
|
pardon my stupidity but....
Zac Howland wrote: proper synchronization objects
?
Thanks,
Kitty5
|
|
|
|
|
zac meant that as several threads access the same memory (see my other answer for the beginning of the discussion), two (or more) threads can access and modify the same variable at the same time.
very bad idea !!!
the solution for this is to "synchronize" the objects that are shared to avoid such problems/
google for semaphores and/or mutex for example
|
|
|
|
|
Basically, what you will want is to create a worker thread (as mentioned above). As part of the creation, you will want to pass in a variable that contains a handle to an event (typically, you will want to pass much more than just that, so a structure/class is created to hold everything you need to pass and then you pass a pointer to that object to the thread you are creating). Each iteration (or some on some interval) of your loop, your worker thread will call WaitForSingleObject and check to see if the event is signaled. If it is not, it continues doing its thing. During the whole loop, you should lock the data section you will be writing to using at least one critical section (which is a form of semaphore that Windows gives you). This way, your GUI thread (or any other thread for that matter -- all of which should also be using critical sections to access the shared data) cannot try to read/write to the memory that you are still loading.
If all of that sounds greek to you, read up on multithreaded programming in C/C++ (lots of good articles on here and Google can be a great help as well). Unless you are going to be working with other OS's, you can focus your search to Windows specific articles.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm new with creating MFC Application GUIs... please pardon the stupid question that follows....
What do you mean when you say:
toxcct wrote: move that loop into a worker thread to avoid the GUI to be frozen
?
Do I create a separate class for the worker thread and have the GUI call it?
The while loop is using member variables of the GUI...(i.e. checking to see whatever user inputs are.
thanks so much,
Kitty5
|
|
|
|
|
actually, the code is already executing in a thread (threads are some executing parts managed by the system). when you put the loop in the event handler, the execution leaves the event handler only when the loop exits and all the instructions where executed.
the problem with suc a design is that other event handlers (such as a button click - yeah, your stop for example) are pushed in the application events stack, but not poped until the current event is not finished.
then, what you can do for that is saying to the system that the loop will be executed in parallel. i mean, the event handler starts the loop, but doesn't wait for its end.
the system doesn't bother if the loop is using member variabless or not, because threads of a same process share the same memory...
|
|
|
|
|
I think you meant to say queue instead of stack
|
|
|
|
|
See here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
AfxBeginThread()
windows platform: process is comprised of main thread (UI thread on client-side) and can spawn additional threads (UI and/or worker) typically single cpu can process one thread any given moment and in this example spawn a worker thread to process data
Kuphryn
|
|
|
|
|
Thanks everyone!
All the answers have been a great help!
now I've got a lot of reading ahead of me!
Kitty5
|
|
|
|
|
|
I do agree that ideally you should employ the techniques suggested above, using worker threads. But sometimes a person does not have the time (or experience) for this route to be feasable.
I often use the pump message technique (equivalent in VB as DoEvents()) to prevent the UI freezing and also allow the user to interrupt lengthy sessions.
Have a look at the FAQ[^], under section
4.3 I have a dialog that does some lengthy processing, and I need to have a Cancel button so the user can abort the processing. How do I get the Cancel button to work?
I Dream of Absolute Zero
|
|
|
|
|
RChin wrote: I often use the pump message technique (equivalent in VB as DoEvents()) to prevent the UI freezing and also allow the user to interrupt lengthy sessions.
While I can understand not wanting to create tons of threads all over the place, creating what amounts to message pumps all over the place is a much worse practice and should be avoided (even in VB).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|