|
The first arguments should be:
const char *path - the routine shouldn't be modifying the text.
const CString &path - Same thing again but also avoids an extra copy constructor.
const std::string &path - Same thing as with const CString &path.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Off the top of my head.
if ((hFile = CreateFile (filePath, GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL)) == (HANDLE)(-1))
{
return 0;
}
DWORD dwFileSize = GetFileSize (hFile, NULL);
return dwFileSize;
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
There are various ways, but you probably want one of the following:
GetFileSize()
GetFileSizeEx() (For sizes larger than a DWORD value)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
thank you both for the help, anyway I've managed to figure it out myself, however due to a netsplit I couldn't access codeproject.com, I made a func almost similar you described.
btw. it's possible to get the size of a file with GetFileSize, as if it puts the high dword to the DWORD pointed by the second argument.
|
|
|
|
|
hi,
i read that a virus copies itself onto a exe/com file;some part in the front and some in the middle or back something like this.
file: FF
virus: VV
infected file: VFVF
with the first part of the virus taking care of the original exe/com running etc etc.
my question is --
how does it (virus) account for the extra file size on the disk.the os will have already a record of the different parts of the file according to its original conents.
then how can the infected file load correctly?
virus demolishacus
PS: sorry if this is off topic but this is a popular board with many people visiting!!
|
|
|
|
|
Anonymous wrote:
how does it (virus) account for the extra file size on the disk
Back in the DOS days, some viruses would have a memory-resident part that hooked various DOS calls (int 13 and/or int 21), and if a call was made to, say read or get the size of an infected file, the virus would modify the returned data to try and hide itself.
These days I doubt virus writers go to that much trouble, since no one keeps mental track of file sizes, and it wouldn't gain much.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
You cannot stop me with paramecium alone!
|
|
|
|
|
yeah , back in dos times the virus wirters tried to make their code as small as possible or make it multiples of 100 so that they dont modifty the last 2 digits of the original file size as it would be very obvious that something has changed.
Now a days virus are about 20k compared to 1 or 2 kb in dos days.
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
Most viruses/works/trojan horses these days just replace a good with with an infected file. The OS looks for a program by filename only so svchost.exe (infected) and svchost.exe (clean) look the same, until the AV software kicks in.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
can you give me some code samples or good advice?
|
|
|
|
|
Hello,
does anyone know how to embed and Automate a Word Document with MFC containing graphics, tables and bitmaps?
Thanks.
Sebas
|
|
|
|
|
Use the Word Automation model.
There exists an object called 'Word.Application' on every machine where Microsoft Word in installed. The version of Word makes no difference, this object refers always to the latest version.
Using the COM-thinking, you can request for a pointer to the IUnknown interface of a Word application (either a running one or a new instance) by using the above object name as a parameter in CLSIDFromProgID function call, and the returned CLSID in a call to either GetActiveObject or CoCreateInstance
At this point, you might want to use the ClassWizard / ClassView to derive a new IDispatch-wrapper class for 'Word.Application'. Then, you use the IUnknown pointer's QueryInterface to ask for an interface called IID_IDispatch . You can then attach the newly created wrapper class to this interface by calling AttachDispatch .
Now, you have complete access to the Word application, allowing you to create new documents, insert images, graphics, etc etc etc.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thank you very much. At tjis point I can open a word document, I know how to put text into it and how to put tables, but I don't know how to put graphics and images. Do you (or anyone) know where couls I find an example of code doing this?
Thanks a lot another time.
Sebas
|
|
|
|
|
I can't provide you with direct example code, but after a bit browsing through the interfaces provided by Microsoft Word Object Library, I found the CanvasShapes IDispatch interface.
This interface has a method called AddPicture , and the parameters of this function call determine the source file name, width, height, top coord, left coord and so on.
It might be precisely what you're looking for. I will attempt to implement it myself today, so if you can't get it working, I'll create some source code to help you out.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks Antti.
I've done what you say and I've found the code to put a picture and it is:
oShapes.AddPicture("c:\\picture.jpg", vtFalse, vtTrue, vtOptional, vtOptional, vtOptional, vtOptional, vtOptional);
Do you know what is the parameter to put that picture fixed in the word document at a position?
Another thing, what type is VARIANT? It can be:
vtTrue
vtFalse
vtOptional
anymore?
Thanks another time
|
|
|
|
|
Sebas. wrote:
Do you know what is the parameter to put that picture fixed in the word document at a position?
No, sorry. I haven't familiarized myself with Word Automation now that you got it working. You need to find this one out yourself. Perhaps downloading the Office Developer's SDK will help. It has, for the least, wizards to create applications that automate Office family programs.
Sebas. wrote:
Another thing, what type is VARIANT?
VARIANT is a structure. It basically functions as a collection of possible parameter values. Like, there are members in the structure for integer, long, double, boolean, BSTR, CString, IDispatch, IUnknown and so on. You set one of these members to the right value, then use the vt member to tell the using function which of the members this VARIANT structure represents.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
|
Sebas,
It looks like you have done some work on MS Word automation more like to what I'm trying to do. Can you help? I have done word automation in VB but I am new to C++ and running into problems.
|
|
|
|
|
What do you need to accomplish ? What problems are you facing ?
If you've done Word automation in VB, you know a whole lot of the work already. All Office applications, whether running or stopped, expose an interface that can be used to invoke the methods. The procedure is similar: initialize COM (CoInitialize-call), either create a new object (CoCreateInstance) or try to find an existing one (GetActiveObject).
When the object is created, you always have access to the IUnknown interface. You can use this interface to query for alternative interfaces on the object (see the Word Automation Model reference for a comprehensive list of interfaces) to accomplish your needs.
Remember to release all interfaces, so that the object gets terminated and will not remain in memory after your program execution has stopped.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
For starters, I need a starting push. Do I start with a wrapper class with a type library or something else? Any reference code on how to initialize COM,instantiate
a COM object will help...
|
|
|
|
|
With Visual Studio, you get a handy little application installed that's called 'OLEViewer'. This program can be easily used to browse through the COM libraries installed on your machine. For example, if you go there, and find the Word Automation Server, you can fire up Word by creating an instance of that server. Know, however that if you start Word this way, it will not display it's user interface. But you can use CTRL+ALT+DEL and see 'WinWord.exe', which is the Word's executable, running there. Word is running, acting as an automation server, but just doesn't show an UI.
Another tool, called 'Runtime Object Table Viewer' or 'ROT Viewer' is also installed with Visual Studio. It probably doesn't have a shortcut, but you can easily add one. The name of the executable is 'irotview.exe'. Find it on your machine and add a shortcut. This application shows all running objects that are registered with OLE/COM. In english, if you fire up Word, it starts it's own automation server at the same time, and this server is registered to OLE/COM. So, if you run Word, you'll see it's automation server instance there.
I can create a small sample application that will help you get started. It will show step-by-step how to initialize COM, and allow you to query for a running Word instance or start a new instance, and then shut this instance down. It should take a few days. I'll send it to your e-mail when it's done.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks a lot, I await your sample app. I forgot to mention that my environment is Visual C++ 7.1
|
|
|
|
|
Dear all,
I checked through the network, it appears need SOAP Client SDK which only comes with XP Pro. Just wondering is there any SOAP Client which installed automatically with .NET Framework or XP Home+.
Thank you in advance.
|
|
|
|
|
Dear Sir,
I actually want some code which can get the Processor's or Mainboard's Serial Number.
Regards,
Kashif Mughal.
|
|
|
|
|
Go to Intel's website and try to find an article on how to retrieve the Processor Serial Number if there is one. I have some code from last year which I don't remember if it works or not and since I cannot compile it and test it right now I will leave that up to you. Sorry, but I don't remember much about getting a number from the motherboard. To my knowledge you can dump the BIOS info (I don't even remember how to do) and somewhere in there you can find the number of the motherboard but my memory on that area is very murky, so I cannot help you at all.
CString strPSN;
BOOL bPSNExists;
LARGE_INTEGER liPI64, liPI32;
__asm
{
mov eax, 01h;
cpuid;
mov liPI64.LowPart, edx;
}
if( (liPI64.LowPart & 0x00040000) > 0 )
bPSNExists = TRUE;
else
bPSNExists = FALSE;
if( bPSNExists )
{
__asm
{
mov eax, 01h;
cpuid;
mov liPI32.LowPart, eax;
mov eax, 03h;
cpuid;
mov liPI64.HighPart, edx;
mov liPI64.LowPart, ecx;
}
strPSN.Format( "%08x-%08x-%08x", liPI32.LowPart,
liPI64.HighPart, liPI64.LowPart );
}
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
See here.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|