|
This should give you a starting point.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I work in C,C++ Windows platform. I am to write code to format a pendrive. I searched and found DeviceIOControl() that seemed to fulfill my purpose. But I cannot proceed any further. Plz help me in this regard.
thanx
Shayantani
|
|
|
|
|
One way, generally, is to use the function FormatEx() from fmifs.dll.
I have been using it for years, but yesterday, I tried to use it for formatting an USB stick/pendrive.
The format itself seemed to work very well, but I got "delayed write error" when I tried to write big files to the pen drive after formatting it (with FormatEx).
I ended up with using Windows normal Format, and after that, the pen drive seemed to work as before.
I suspect the cause of the problem is in the second parameter to the FormatEx() function.
It seems as there are just two known values (outside MS) out of 24! (The known values are FMIFS_FLOPPY and FMIFS_HARDDISK). Another value might do the trick.
So your DeviceIOControl() call might be a way to do it. It seems possible that the formatting code is included with the driver. Might be worth to investigate further.
You say "I cannot proceed any further". Why? What's the problem?
<edit>I'm going on Xmas leave now. Back on the 7:th of January (GMT+1)
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
modified on Thursday, December 20, 2007 11:18:08 AM
|
|
|
|
|
Dear All
how can i get the size of a function (its code size in the memory in bytes) from its pointer (its function pointer)
function like
double add (double , double)
i tried sizeof by many ways and no result
any tips
thanks all
bye
|
|
|
|
|
You cannot.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
what if i want to copy the function code from the memory to a file?? !!
thanks
|
|
|
|
|
Why would you need/want this? Even if it were possible, the "code" you'd end up with would be machine code.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
IMHO (I'm not expert about), you need to hack DLL (or executable) internals, i.e. you need to know PE file format, have a look at http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx[^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
The only way would be a loop that reads through the assembly code looking for the next ret . This would only work with simple functions having only one ret . Once you put the code in a file it would be useless anyway because code with jump instructions in it (most code) is usually address dependent. ie. if you don't load the code back at the same address it won't work anymore. As you can never gaurentee to do this in any future instance of the process it would be of no use to have the unbased machine code in a file, except possibly for comparison to detect a code modifying virus attack or something. There are better ways to do that anyway like security cookie checks which are already built into every function for you by the MS Compiler. See the /GS compiler switch. If you want to know more have a look at some disassemblers which turn compiled code back into something almost readable.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Caveat: This is dubious practice. The memory layout is not guaranteed and should not be relied upon. Pointer arithmatic is not good. It is mostly just an "irresistible" question.
Given the above: an old technique is to use two function pointers
void functionA()
{
}
void functionB()
{
}
void dontdothis()
{
void * p1 = functionA;
void * p2 = functionB;
char * p3 = static_cast<char *>(p1);
char * p4 = static_cast<char *>(p2);
size_t sizeFn = p4 - p3;
}
There is little, if anything, that can be done with this.
|
|
|
|
|
can u kindly explain more what the meaning by ur code ??
you just sub. two addr of two pointer of two function !! how this be the size and size of which one ..
i really misunderstand
thx
|
|
|
|
|
Assuming the two functions are back-to-back in memory, you can simply take the difference of their addresses to obtain the size. In other words, if functionA() is at 0x1234 and functionB() is at 0x2345, then the size of functionA() would be 4,369 bytes.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Nicely said.
This is precisely what is happening.
Once more, don't do this.
|
|
|
|
|
Member 754960 wrote: Once more, don't do this.
I wouldn't. I was just explaining to Adore what was happening.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
ooh sure should not be used !!
nothing can guaranty that the two functions are above each other in the memory !!!
see no way here ..
indeed its a client request for what i don't know !
thx all
|
|
|
|
|
Since that won't do, try this:
Load the program in a debugger and read the starting and ending address of the function and do the math.
Otherwise you need to do a lot more research before you can ask your question.
|
|
|
|
|
I am adapting for Visual C++ 2008 a Borland C++ 4.5 program which includes this function:
int is_dir(char*path){struct stat i; stat(path,&i); return i.st_mode&S_IFDIR;}
which returns non-zero if path is the name of a directory. But Visual C++ does not know the type struct stat. Please how could I do this in Visual C++ (preferably without using classes)?
|
|
|
|
|
|
That help page describes a function PathIsDirectory() ; howeer, the result was
\2d\ppp_vc\ppp_vc\mwproc.cpp(396) : error C3861: 'PathIsDirectory': identifier not found
|
|
|
|
|
Look at the bottom of the doc page. It will list the header and lib file needed to use the function.
Judy
|
|
|
|
|
Did you include header file?
|
|
|
|
|
As stated in the documentation, you have to include shlwapi.h header file and link with shlwapi.lib library.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Why you didn't write it needs to the header file?
|
|
|
|
|
OMG, I also forgot to tell him he needs a compiler (perhaps a computer too)!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
I saw your answers they are nice;) .
|
|
|
|