|
if you run this code what happens?
HANDLE handle;
DWORD m_Pos,m_NumberofFile=0;
handle=CreateFile(_T("e:\\1.bmp"),
GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
dwPos = SetFilePointer(handle, 0, NULL, FILE_END);
LockFile(handle, m_Pos, 0, m_NumberofFile, 0);
|
|
|
|
|
How to get the file properities programatically.For ex get the last visited time of a file.
|
|
|
|
|
VC++ provides a series of file functions, this is one of them, search for "file functions" in MSDN and choose function to meet your requirement...
all the best
|
|
|
|
|
You can use of FindFirstFile or GetFileAttributes .
|
|
|
|
|
Hello all,
I am desparete and need help! I have been trying to figure this out for over a week now and cannot spend anymore time on this. Basically I am doing something that I have done a million times, but for sone reason it is not working in this instance. But even more bizarre, its not just working from one location...
Basically I am trying to do a HTTP_VERB_POST to log in to a popular web site. I have done this type of code over and over and its very straight forward. I wrote code to perform this task on my laptop while at work. After a while, I finally got it to work perfectly. It seems goes to the web site to the login page, extracts the values needed for the post and then I do an OpenRequest and then a SendRequest. Next, I read in the data from the CHttpFile. This completely worked. It downloaded the page saying that I have logged in. All was well, until I got home. Running the same program from teh same computer, but now on a different network (my home network, different IP address), it fails. But it fails in a way I have never seen before. The page returned from the HttpFile is complete garbage - unrecognizable characters (nothing I could display on here). I have never seen anything like this. And to add to my confusion, if I open up Internet Explorer and manually go to the website and log in, it works just fine. So this is not a case of the IP got banned or something like that. But computers use a router and both are behind a firewall. But I tested it with the firewall disabled, and no changes. But like I said, if I do it manually using IE, it works just fine. One other thing, in this SAME program, I log into a different web site (using the same code) and it works just fine...
Below is basically the code I used. The original code had the following in different functions, but I merged it together to make it an easier read. But I believe i got it all... Anyone have any clue at all on what could be going on. I'm deparate!!!!
Thanks,
Chris
Code:
------
CInternetSession *session;<br />
CHttpConnection* pConnection;<br />
<br />
session = new CInternetSession(NULL,1,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,INTERNET_FLAG_DONT_CACHE);<br />
<br />
strFormData = "SESSIONID=24325235&......";<br />
CString strHeaders = CString("Accept: image/gif, image/x-xbitmap, .....\r\n");<br />
<br />
DWORD dwServiceType;<br />
USHORT nPort;<br />
CString currentURL = CString(http:www.???);
AfxParseURL( currentURL, dwServiceType, sServerName, sObjectName, nPort );<br />
<br />
CString fileText;<br />
<br />
CHttpFile* pFile = NULL;<br />
<br />
try {<br />
pConnection = session->GetHttpConnection(_T(sServerName),nPort,"","");<br />
<br />
pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, _T(sObjectName), NULL,1,NULL,NULL, INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_DONT_CACHE );<br />
<br />
BOOL result = pFile->SendRequest(strHeaders, (LPVOID)(LPCTSTR) strFormData, strFormData.GetLength());<br />
<br />
if (pFile) {<br />
int len = pFile->GetLength();<br />
char buf[2000];<br />
<br />
int numread =0;<br />
CString cc;<br />
<br />
while ((numread = pFile->Read(buf,sizeof(buf)-1)) > 0) {<br />
buf[numread] = '\0';<br />
fileText += CString(buf);<br />
}<br />
}<br />
}<br />
<br />
catch (CInternetException* m_pException)<br />
{<br />
pFile = NULL;<br />
char test[1024];<br />
m_pException->GetErrorMessage(test,1024);<br />
m_pException->Delete();<br />
}<br />
<br />
CString webPage = fileText;
Chris
|
|
|
|
|
In accordance with W3C HTTP/1.1 standards, HTTP does not always necessarily respond in plain text. You are probably recieving a gzip compressed stream from the webserver.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html[^]
Try removing "Accept-Encoding: compress, gzip" from the headers you are sending. If the webserver is compliant it should assume you do not accept compressed streams. On the other hand if the webserver ignores you and continues to send gzip compressed streams then you can possibly link with the zlib library to decompress the stream manually.
There may be a more simple method of decoding the stream but unfortunately this is not my area of expertise. Perhaps someome with greater knowledge with the CInternetSession and derivitive classes will respond.
Hope this helps,
-Randor (David Delaune)
|
|
|
|
|
That worked! I simply removed the "Accept-Encoding: compress, gzip" and it now reads in as normal HTML. I can't express how thankful I am! I'd gone over every aspect of it, but never considered it was compressed. Thanks so much!
Chris
|
|
|
|
|
I would like to take the first character from some text in an Edit box and add it as a new line in a Listbox.
Say I have Edit1 with the text C:\whatever
I want to add the first character C to the ListBox.
I'm at a loss as how to do this. Any help would be appreciated.
Using Borland c++ builder 6
|
|
|
|
|
You can use
GetWindowText() to copy the edit control string to a buffer
Set the character at offset 1 in the buffer to '\0'
Send the LB_ADDSTRING message to the listbox to add the string
I've left out error handling including making sure there's actually characters in
the edit control.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Wow thanks for the fast reply. So i would use this function.
int GetWindowText(
HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
I'm assuming hWnd would be Edit1, lpString would be LB_ADDSTRING, AND nMaxCount would be 0. But when I input that in I get errors.
[C++ Error] yadda.cpp(402): E2152 Default expression may not use local variables
[C++ Error] yadda.cpp(402): E2034 Cannot convert 'int' to 'char *'
[C++ Error] yadda.cpp(402): E2150 Type mismatch in default argument value
Any ideas what I'm doing wrong. Thanks for all the help and sorry for basically asking you to hold my hand and walk me through it.
|
|
|
|
|
Your program is Win32 or MFC?
|
|
|
|
|
I don't know Borland C++ builder so I suggested Win32 APIs.
GetWindowText() takes the handle of the edit control (HWND),
a pointer to a buffer to copy the text into, and the size of the buffer.
TCHAR buffer[80];<br />
GetWindowText(hwndEdit, buffer, sizeof(buffer)/sizeof(TCHAR));<br />
<br />
buffer[1] = 0;<br />
<br /> To add a string to a listbox, you can send it a LB_ADDSTRING message...
SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)buffer);
That's the basics, with no error checking.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay thanks for that. here is what i've done
void __fastcall TForm1::Edit1Change(TObject *Sender)<br />
{<br />
TCHAR buffer[80];<br />
GetWindowText(hwndEdit1, buffer, sizeof(buffer)/sizeof(TCHAR));<br />
<br />
buffer[1] = 0;<br />
SendMessage(hwndListBox3, LB_ADDSTRING, 0, (LPARAM)buffer);<br />
<br />
}<br />
These are the errors i get
[C++ Error] yadda.cpp(403): E2451 Undefined symbol 'hwnd'
[C++ Error] yadda.cpp(403): E2121 Function call missing )
[C++ Error] yadda.cpp(407): E2121 Function call missing )
Here is my includes
#include <vcl.h>
#pragma hdrstop
#include <iostream>
#include <fstream.h>
#include "yadda.h"
#include <filectrl.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <process.h>
And Hamid the app is win32.
Thanks for the help thus far. I answer questions on a video forum and now feel like one of the newbies I help on a daily basis.
|
|
|
|
|
hmmm I'm running out of help here, since I don't know Builder...
I don't see "hwnd" anywhere in your code so I can't imagine what's causing the error.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay. Thanks for the help so far. You've pointed me in the right direction.
|
|
|
|
|
Hi all,
I am trying to extract messages from outlook express on a server and file them in a folder. - contact, subject and text
Does anyone know if this is possible or can direct me to a place where I can get help on this.
Many thanks in advance
|
|
|
|
|
try using SimpleMapi for outlook express....
search this in codeproject
An article by PJ Naughter
http://www.naughter.com[^]
|
|
|
|
|
what is the best way to resize a structure during run time. I have a struct that rights out a record to a file. Now I will have 2 scenarios that that requires that one of the fields in the middle of the struct be a different size. All the fields in the struct are char or char[]. can this be done with unions? I have code in place that does all the formating, so I don't want to have to rechange everything.
|
|
|
|
|
A struct should always have the same size and never be resizable. If you have the need to store items of an unkown size, store the pointer/offset to the data in the struct and write the data where the struct can find it.
For example:
struct MyStruct
{
DWORD szText;
char szSoreText[ 28 ];
struct UnknownStruct
{
...
}
} foo;
When writing this to a file you would set the szText to sizeof( MyStruct ) . This indicates that the string is stored right after the struct. To get the text you would do something like:
char* szStructsText = (char*)( &foo + foo.szText );
Waldermort
|
|
|
|
|
Resizable structure is not possible.
If u r using C++ then u can derive new structure from existing one like class..
ThankXXXX..
|
|
|
|
|
Hi,
I know there are a few good articles regarding driver development here, but unless I missed it, I couldn't find something about sending an asynchronous IOCTL from user space to kernel.
Any help or link would be great.
|
|
|
|
|
When you open the device, you need to specify that you will be doing overlapped I/O. Then, when calling DeviceIoControl, use the overlapped parameter.
Judy
|
|
|
|
|
Hi there,
Just inherited some VC++ code from a colleague, including .cpp,.CPP,.h,.H, i know nothing about Visual C++, but I was told the program was executable.......my silly questions are:
1) .cpp and .CPP the same ?
2) How to build them into one project to make it executable using Visual Studio 2005?
I couldn't find the straightforward answer from the Internet.
Any hint? Many thanks.
Regards,
Aloha
|
|
|
|
|
Aloha2007 wrote: Just inherited some VC++ code from a colleague, including .cpp,.CPP,.h,.H,
What version of VS was s/he using?
Aloha2007 wrote: 1) .cpp and .CPP the same?
Yes.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
Many thanks for reply.
He use Visual Studio 2003 or even earlier version.
The built-up project was executable in 2003 version, but when run it on 2005 version, it says: the project is out of date.
Then I asked for the original codes, but don't know how to build it on Visual Studio 2005.
Regards,
Aloha
|
|
|
|
|