|
Hi all:
I'm wondering why the following code need type conversion from PVOID to PBYTE, is it because of the type of "Size"? and why PBYTE, will any other type will do the same thing?
PVOID pvAddressBlk;
SIZE_T RegionSize;
pvAddressBlk = (PVOID) ((PBYTE) pvAddressBlk + Size);
Thanks,
|
|
|
|
|
Because you are doing pointers arithmetics here. A PVOID pointer is a pointer to an unknown type (so, which size is not known). In that case, you cannot increment the pointer because the size to which it points to is unknown (so, impossible to go to the next element). A pointer to a byte (PBYTE) knows the size to which it points to (1 byte), so incrementing the pointer will move to the next byte.
Similarly, if you casted your pointer to int* for example, then incrementing (++) the pointer would make it points 4 bytes after its current position (because the size of an int is 4 bytes, so, the next integer is 4 bytes after the current position).
Hope it is clear.
|
|
|
|
|
Thanks for the reply, the code makes sense to me now: it's trying to increment the address by (type size * n) bytes.
|
|
|
|
|
LiYS wrote: is it because of the type of "Size"?
No. Let me explain with an example. Suppose you have two pointer variables say
int *pInt and <br />
char *pchar
And you increament both this varibales by one
pInt++;<br />
pChar++;
In the above case the pInt will increament by four. But pChar will be advanced by only one.( i. e when a pointer is increamented or added for n times, compiler actually adds n times the size of datatype the pointer pointing to )
In your case it is a void* pointer. So it cannot decide how much to increment. thats why compiler gives the error.
|
|
|
|
|
Thanks for the reply, the code makes sense to me now!
|
|
|
|
|
I want all the filenames in perticular folder of web server
with http call.
InternetFindNextFile function falis
some sample of code.
.
.
CString sUserAgentName = "Microsoft Internet Explorer";
DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG ;
DWORD dwFlags =INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ;
//pInternetSession = new CInternetSession(sUserAgentName,dwContext,dwAccessType,NULL,NULL,dwFlags);
CString sUrl="http://www.test.com/1";
WIN32_FIND_DATA wfd;
HINTERNET hInternetFind,hInternetOpen = InternetOpen(sUserAgentName,dwAccessType,NULL,NULL,0);
CStringArray saFileName, saDirectoryName;
CString sName;
CString sServerName , sServerObjectName ;
DWORD dwServiceType = 0 ;
INTERNET_PORT nServerPort = 0;
CString strHeaders ;
CString sUserName = "";
CString sPassword ;
DWORD dwContext = 0;
if(AfxParseURL(sUrl,dwServiceType,sServerName,sServerObjectName,nServerPort)==FALSE)
{
AfxMessageBox("AfxParseURL() Fails");
return false;
}
int err;
//pConnection = pInternetSession->GetHttpConnection(sServerName,nServerPort,sUserName,sPassword);
//HINTERNET hInternetConnect =
::InternetConnect(hInternetOpen,sServerName,nServerPort,sUserName,sPassword,INTERNET_SERVICE_HTTP,dwFlags,dwContext);
//err = GetLastError();
//hInternetFind = FtpFindFirstFile(hInternetConnect,"*.*",&wfd,0,0);
/*if i try function FtpFindFirstFile than it returns null and errorcode is
ERROR_INTERNET_INCORRECT_HANDLE_TYPE(12018)
*/
//err = GetLastError();
hInternetFind = InternetOpenUrl(hInternetOpen,sUrl,NULL,0,INTERNET_FLAG_RAW_DATA| INTERNET_FLAG_RELOAD|
INTERNET_FLAG_DONT_CACHE,0);
/* if i try InternetOpenUrl than it retrn not null but when InternetFindNextFile is called than it returns FALSE
ERROR_INTERNET_INVALID_OPERATION(12016)*/
err = GetLastError();
if (hInternetFind ==NULL)
{
AfxMessageBox("(hInternetFind == NULL)");
}
if (InternetFindNextFile(hInternetFind, &wfd) == FALSE)
{
err = GetLastError();
AfxMessageBox("(InternetFindNextFile = fails)");
}
do
{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
sName = (const char*) &wfd.cFileName;
if(!sName.IsEmpty())
{
if (sName.GetAt(0) == '.')
continue;
saDirectoryName.Add(sName);
}
}
else
saFileName.Add(sName);
}
while (InternetFindNextFile (hInternetFind, &wfd));
InternetCloseHandle(hInternetFind);
.
.
.
thanx
|
|
|
|
|
jay_p_patel wrote: InternetFindNextFile function falis
So what does GetLastError() return?
"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
|
|
|
|
|
i wrote in that code
ERROR_INTERNET_INVALID_OPERATION(12016)
|
|
|
|
|
Your code snippet is next to impossible to read. I can't tell what you've got commented out and what's actual code. Please reformat it AND make use of the <pre> tags.
You need something similar to:
HINTERNET hOpen = InternetOpen(...);
if (hOpen != NULL)
{
HINTERNET hConnect = InternetConnect(hOpen, ...);
if (hConnect != NULL)
{
WIN32_FIND_DATA findData;
HINTERNET hFind = FtpFindFirstFile(hConnect, NULL, &findData, ...);
if (hFind != NULL)
{
do
{
...
} while (InternetFindNextFile(hFind, &findData))
}
}
}
"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
|
|
|
|
|
Hello Sir,
The code you send me that i already tried.
when i use
HINTERNET hFind = FtpFindFirstFile(hConnect, NULL, &findData, ...);
it returns hFind = NULL
and in GetLastError it returns
Error No.12018 ERROR_INTERNET_INCORRECT_HANDLE_TYPE
i read in msdn that we can use InternetOpenUrl in place of FtpFindFirstFile
HINTERNET hFind = InternetOpenUrlhInternetOpen,sUrl,NULL,0,INTERNET_FLAG_RAW_DATA| INTERNET_FLAG_RELOAD|
INTERNET_FLAG_DONT_CACHE,0);
now hFind is not Null but when i use this hFind in
InternetFindNextFile API than it return false.
So this is the problem.
Anyway thanx for helping me.
sorry for ur inconvinience.
|
|
|
|
|
Hi dear
I want to ask you if you know where the first address for image data in monochrome bitmap is. I know the header allocate 54 bytes but I am not sure about this in Monochrome images.
Please if you can tell me where is the location of the first data, I will be so thankful.
Note: Monochrome Bitmaps (one bit per pixel)
Thanks
|
|
|
|
|
The image data address is stored in the image header itself. So better you read it and check. I think you are not considering color table info.
- NS -
|
|
|
|
|
I answered this before for you and you still haven't provided enough information.
If the BMP is a file, the file begins with a BITMAPFILEHEADER structure.
The bfOffBits member of this struct is the offset of the pixel bits from the
beginning of the file.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all, here's my question.
First I read a binary file, which includes large number of streams of bytes. Each stream has specific details. Using a buffer I read each stream and extract some details. Actually stream consist two parts, fixed data and a message. Fixed data length actually fixed in 24 number of bytes. Rest of the bytes include the message. What I want to do is, read the bytes which message include and print as a String(actually as a message).
Those bytes are in the buffer and I know how many bytes are there.
I work on Visual Studio .Net 2003
Can you guys help me to solve this.
Thanks
-- modified at 0:45 Wednesday 10th October, 2007 -- adding more details
Hi all....
|
|
|
|
|
Eranga Thennakoon wrote: What I want to do is, read the bytes which message include and print as a String(actually as a message).
this sentence is not clear can you just elaborate it?
|
|
|
|
|
Ok, after reading each stream I've found that number of bytes which include the message of each and every stream separately. As a example,
stream 1 - message use 4 bytes
stream 2 - message use 1500 bytes
stream 3 - message use 100 bytes
etc..
Right now all those bytes are in a buffer. What I want to do is read that bytes in the buffer and find the message there, I mean read stream 1 bytes of 4 and find the message. Then read the stream 2 bytes of 1500 and find the message and so on
I think it is clear now.
-- modified at 1:10 Wednesday 10th October, 2007
I appreciate your help all the time...
|
|
|
|
|
if you are able to read the number of bytes in the message from the stream,
i dont understand whats the problem in reading the message, since you know the size of the message.
on thing please be specific.
all the data, what you call it as a stream is available in the file?
and what is that you are referring the buffer as?
|
|
|
|
|
No, only thing is that I know the number of bytes use a message. I'm confusing how to read it, and get the message. If you want I can put my code here.
I appreciate your help all the time...
|
|
|
|
|
Maintain a counter where you are.
In a loop read till the end of the file.
Inside the loop,
read the length, using memcpy in a DWORD and update counter
use ur string class, and copy the buffer, till that length just read like string
s=string(buffer+counter,length); (assuming there is a constructor like this,which many
have)
update counter
end loop
Simple,
|
|
|
|
|
I'm not clear what's usage of a counter. If I read the message just after finding the length I think it is easy, because to find the length of each and every stream message I have to use a loop. Difficulty I come across with is some message length is higher than the buffer size I used.
What's your comment?
I appreciate your help all the time...
|
|
|
|
|
if you have posted your code to my mail id,
then i will get back to you in a couple of hours. keep in touch.
|
|
|
|
|
Eranga Thennakoon wrote: Can you guys help me to solve this.
Sure, which part are you stuck on? What code do you have so far?
"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
|
|
|
|
|
Ok, here is my code. Sorry I don't use tags here, it gives a real mess to read the code correctly.
=============================================================================================================
#include <iostream>
#include <fstream>
#include <string>
using namespace std ;
ofstream filedata ;
// Packet content of initial 16 bytes
struct pac_cont
{
unsigned int des_list ;
unsigned int mem_ID ;
unsigned char dm_con ;
unsigned char ser_ID ;
unsigned short act ;
};
void dataExtract(int length, char *buffer)
{
struct pac_cont* p = (struct pac_cont*)buffer;
filedata.open( "RecordData.txt", ios::app ) ;
if(filedata.is_open())
{
filedata << "\t" << static_cast<int>(p->des_list) << "\t\t" << static_cast<int>(p->mem_ID)
<< "\t\t" << static_cast<int>(p->dm_con) << "\t\t" << static_cast<int>(p->ser_ID)
<< "\t\t" << static_cast<int>(p->act) << "\n";
filedata.close() ;
}
else
{
filedata << "Error in opening file RecordData.txt\n" ;
}
}
int main ()
{
ifstream fileopen ;
ofstream filerecord ;
char buffer[5000] ;
unsigned int tmp_len = 0 ; // Length of a stream
int count_mess = 0 ; // Count total message
int ID = 1 ; // Stream ID
// Open the file in binary format
fileopen.open ( "G00046_002_01.srf", ios_base::binary ) ;
// Record the stream length
filerecord.open ( "RecordLength.txt", ios_base::out ) ;
if((fileopen.is_open()) && (filerecord.is_open()))
{
// Headers of the RecordLength.txt file
filerecord << "Stream ID\tLength\t\tDescription\n\n" ;
// Headers of the RecordData.txt file
filedata.open ( "RecordData.txt", ios_base::out ) ;
if(filedata.is_open())
{
filedata << "Destination List\t" << "Member ID\t" << "Data/Message\t"
<< "Service ID\t" << "Activity ID\n\n" ;
filedata.close() ;
}
else
{
cout << "Error in opening file\n" ;
}
while(!fileopen.eof())
{
fileopen.read(buffer, 4); // Dummy read of 4 bytes
fileopen.read(buffer, 4) ; // Read next 4 bytes
tmp_len = *(unsigned int*)buffer ; // Integer value of previous 4 bytes
if(tmp_len <= 5000)
{
filerecord << ID << "\t\t" << tmp_len << "\t\t" << "-\n" ;
if(tmp_len > 16)
{
// Procesing initial 16 bytes
fileopen.read(buffer, 16) ;
dataExtract(16, buffer) ;
// Move the buffer pointer
fileopen.seekg((tmp_len - 16), ios_base::cur) ;
}
else
{
cout << "Stream is in wrong length\n" ;
}
}
else
{
filerecord << ID << "\t\t" << tmp_len << "\t\t" << "Large Size - More than 5000 bytes\n" ;
// Processing intial 16 bytes
fileopen.read(buffer, 16) ;
dataExtract(16, buffer) ;
// Move the buffer pointer
fileopen.seekg((tmp_len - 16), ios_base::cur) ;
}
ID++ ;
count_mess++ ;
}
cout << "Number of streams: " << ( ID - 1 ) << endl ;
cout << "Number of messages: " << ( count_mess - 1 ) << endl ;
fileopen.close() ;
filerecord.close() ;
}
else
{
cout << "Error in opening files" << endl ;
}
cin.get() ;
return 0 ;
}
============================================================================================================
I'll comment it as much as possible. First I read a binary file, and found how many stream of bytes are there. Actually length of those streams are not same.
Basically each stream contain three part, four bytes for part one, four bytes for part two and int value of that four bytes gives the next part bytes. The third part have 16 fixed bytes at the beginning of each. I've extract the data there using dataExtract() function, you can see that. Up to now it is ok.
Now I want to read the bytes in part three except first 16 bytes. There is a message, actually record from a online chat. I want to read it and write to a file. How can I do that.
Thanks.
I appreciate your help all the time...
|
|
|
|
|
What does stepping through each line of code with the debugger reveal?
"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
|
|
|
|
|
DavidCrow wrote: debugger reveal
Please can you explain it little more. It is really new for me.
Eranga
I appreciate your help all the time...
|
|
|
|
|