|
jon_80 wrote: C1010 - unexpected eof. Says it needs a header file, but I "forgot" what to include. Afiak the header file includes:
stdafx.h - it's probably got pre-compiled headers enabled if it's a VS project.
You don't need the Sieve.h file.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
To be true, I have never used dllimport in my code while using a module. What's the actual use of it? No matter we use it or not, we are able to access the exported symbol right?
----------------------------
286? WOWW!
|
|
|
|
|
Hi 8086,
Raymond Chen wrote a series about imports and exports[^] and its implementation history. Its an excellent read and I think you will enjoy it.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for the Pointer Randor!
----------------------------
286? WOWW!
|
|
|
|
|
Hi Randor,
Just found this in MSDN :
Using __declspec(dllimport) is optional on function declarations, but the compiler produces more efficient code if you use this keyword. However, you must use __declspec(dllimport) for the importing executable to access the DLL's public data symbols and objects. Note that the users of your DLL still need to link with an import library.
Thanks for your reply.
----------------------------
286? WOWW!
|
|
|
|
|
Thats a fair but short description of dllimport. I apologize for sending you off to do your own research. Its just that sometimes I feel like I am answering the same questions over and over. Here is a thread from 2008 where dllimport was discussed. You can be surprised with what a well-formed codeproject search will find.
http://www.codeproject.com/Messages/2431922/Re-import-library.aspx[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi
We know that, WinMain is buried in the MFC Framework. OK but how can Windows call it?
I opened MFC project in VC++ and tried to find out how it imports the dll(Mfc90ud.dll) and functions in that dll. But i couldn't find it. I also disassembled the mfc90ud.dll but there is no function like WinMain in exported function list. Function names are just numbers.
So, I have 2 questions.
1-) How does VS knows that Mfc90ud.dll must be imported and Windows know that it must call a function in a dll that is imported by EXE?
2-) If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?
Thanks...
|
|
|
|
|
Normally WinMain is not exported in DLLs. What happens is that WinMain is not called directly by the loader (and main(), likewise). The code that calls it, is a bootloading code, which is addressed by a DLL/EXE entry point. This code does all the initialization and at the end of it calls into WinMain/main(), the address of which is known during compilation.
|
|
|
|
|
sawerr wrote: We know that, WinMain is buried in the MFC Framework. OK but how can Windows call it?
The linker tries to locate and execute an entry-point in your code, which may be dependent on the type of application you are building: WinMain (or wWinMain if built for Unicode) or main (or wmain if built for Unicode). The former is for windowed applications and the latter is for console applications. If no entry point is defined in your application, you will get an undeclared identifier from the linker.
sawerr wrote: If i import a dll and although i do not use one of the imported function in that dll, OS can still call that function? Or OS can only call imported dll functions which are used by exe?? If the function doesn't import by exe, it is never be called?
That depends. There are DLLs that you may not reference directly from your code but Windows will load and execute code from those libraries. This is because some of the functions in those libraries may be indirectly referenced. Other than that, only what you are calling from your code will be loaded or executed.
The fact is that this is a larger topic to be discussed in a thread like this. If you really are wanting to read up on how programs work and how Windows work, I'll recommend the book by Jeffrey Richter and Christopher Nasarre (every edition of the book gets a new name. The latest one is called Windows Via C/C++).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks for answers.
I know that loader must fill IAT with imported functions. If I don't import a function so function can't be placed in IAT. So even this function is exported from dll, Windows can't call it. But i'm not sure about that so i started that thread.
I understand that winmain(or whatever) isn't added to import section by exe, this is special case for entry point. A function can be called without adding IAT is entry point. This is valid just for entry point. Is that right?
|
|
|
|
|
Exported functions can be called (or, rather, located and addressed) from the outside - so, whenever you need a function to be addressable from the outside you (or compiler/linker) make it exported. This is the only rule
|
|
|
|
|
Hii
In my application , wanna copy all files from one partition to another partition.
First I copied a file that I taken default and copied to another partition.
The above operation is done by using the control code "FSCTL_GET_RETRIEVAL_POINTERS".
The clusters used are read and wrote into destination volume using readfile() and writefile() windows functions.
Now I gotta copy all files.....
So how to proceed ....??
Thanking you.
|
|
|
|
|
Hi krish,
krish_kumar wrote: So how to proceed ....??
Why are you using DeviceIoControl to copy files? Are you doing this from usermode or ring0/kernelmode?
Best Wishes,
-David Delaune
|
|
|
|
|
|
Well, if you're in user-mode, just iterate through *all* the files in the partition, read them into memory and write them into the other partition. Not tricky.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
krish_kumar wrote: I use it in user mode.
Yes, I remember you now. Your the guy who has been asking this question in all of the kernelmode driver forums for the last few weeks.
Doron Holan over at Microsoft and many other highly respected engineers have given you the same advice. You should just copy the partition from usermode using the standard functions. Your not going to get much benefit from using kernel functions from usermode.
Now with that being said, what exactly are you having problems with? You state in this post[^]
I used the "FSCTL_GET_VOLUME_BITMAP" to get the cluster usage details.And I'm
getting the used and free cluster counts correctly.And the cluster number I got
is continuous.This makes problem for me. I wanna copy the used clusters to a
different partition.
Mark Roddy over at Microsoft wrote an article about finding and copying disk sectors. Have you read it?
Adventures in Luserland: Finding Disk Sectors Associated with File Records.[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hii
First I started with kernel mode and after that as per replies from Mr.Doron Holan Presently I do my application in user mode only.
In Mark Roddy's article ,takes each file handle and it's appropriate clusters.
So here in my program I took a sample file and get it's corrresponding cluster
details using "FSCTL_GET_RETRIEVAL_POINTERS" along with DeviceIoControl and copied it into another partition.
And this successfully copied the source file .
Like this I wanna get all files.So it may take much more time..?
How to get all file one by one.?
And I tried one more way using "FSCTL_GET_VOLUME_BITMAP"along with DeviceIoControl.In this case I take the
whole volume as handle to createfile() and find out the used cluster only;and simply copied them to another partition.After that I can't open some folders in the destination partition...
Here I'm not reinitializing links among them...and have to reallocate MFT..?
Thanking you...
|
|
|
|
|
krish_kumar wrote: I took a sample file and get it's corrresponding cluster
details using "FSCTL_GET_RETRIEVAL_POINTERS" along with DeviceIoControl and copied it into another partition.
And this successfully copied the source file .
Like this I wanna get all files.So it may take much more time..?
Yes. Of course it will take more time if you are enumerating all files/directories and copy them individually via FSCTL_GET_RETRIEVAL_POINTERS ReadFile/WriteFile. Your wasting your time here. Your other method which read the partition in 50MB increments will probably be faster.
krish_kumar wrote: How to get all file one by one.?
What is preventing you from enumerating all files? If you can copy 1 file... why not 2? If you can copy 2 files... why not 20,000? Are you having trouble enumerating files?
krish_kumar wrote: And I tried one more way using "FSCTL_GET_VOLUME_BITMAP"along with DeviceIoControl.In this case I take the
whole volume as handle to createfile() and find out the used cluster only;and simply copied them to another partition.
Without seeing your code I cannot possibly know what you did wrong. However as others have stated... there is alot of complexity involved. The NTFS $MFT contains logical offsets which map to physical locations. In addition.. you are dealing with logical and physical offsets[^] when dealing with the $Bitmap.
I dont want to discourage you. I am sure you have a valid reason why you want to copy a 2GB partition in 5 seconds rather than 10 seconds. I believe that using FSCTL_GET_VOLUME_BITMAP to get a list of all used clusters and copy only the used clusters may work. However you need to put the clusters back into the same offsets on the new partition.
What does your FSCTL_GET_VOLUME_BITMAP code look like? Are you trying to copy all of the used clusters onto the new partition in a contiguous stream? Keep in mind that you need to preserve the offsets. Can you show some code?
Good Luck,
-David Delaune
|
|
|
|
|
#include "WinIoCtl.h"
#include "stdio.h"
#include "ntddvol.h"
#include "stdafx.h"
#include "Cluster_Used_Logical_to_Phy_Ofst.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
DWORD BytesReturned,dwBytesReturnedh;
LARGE_INTEGER li_add;
int i=0;
UINT32 *BitmapDetail;
DWORD dwError;
LPDWORD lpBytesReturned;
int iCopy_Count=0;
LONGLONG llCountUsed=0;
LONGLONG llCountFree=0;
LONGLONG llTotalCount=0;
LONGLONG llChunk_Size=512;
LONGLONG Rest_Size=llVolume_Size;
LONGLONG dwclusterSizeInBytes=512;
LPVOID bBuffer1 = VirtualAlloc(NULL,512,MEM_COMMIT,PAGE_READWRITE);
BOOL IsClusterUsed (UINT64 Cluster)
{
return ((BitmapDetail[Cluster / 32] & (1<< (Cluster % 32))) ? TRUE : FALSE);
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if(!AfxWinInit(::GetModuleHandle(NULL), NULL,::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
HANDLE h_MyDrive_Src,h_MyDrive_Dest,hDevice;
DWORD dwRetBytes1,dwRetBytes2;
hDevice = CreateFile( _T("\\\\.\\PhysicalDrive0"),
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hDevice==INVALID_HANDLE_VALUE)
{
printf("\nUnable to Open the Device: Error Number is : %d\n",GetLastError());
}
h_MyDrive_Src = CreateFile( L"\\\\.\\H:",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING,
NULL);
if (h_MyDrive_Src==INVALID_HANDLE_VALUE)
{
printf("\nUnable to Open Device: Error No: %d\n",GetLastError());
}
h_MyDrive_Dest=CreateFile( L"\\\\.\\I:",
GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING,
NULL);
if (h_MyDrive_Dest==INVALID_HANDLE_VALUE)
{
printf("\nUnable to Open Device: Error Number:%d\n",GetLastError());
}
STARTING_LCN_INPUT_BUFFER StartingLCN;
VOLUME_BITMAP_BUFFER *Bitmap = NULL;
UINT32 BitmapSize;
DWORD BytesReturned1;
BOOL Result;
ULONGLONG ClusterCount = 0;
StartingLCN.StartingLcn.QuadPart = 0;
BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + 4;
Bitmap = (VOLUME_BITMAP_BUFFER *) malloc (BitmapSize);
Result = DeviceIoControl(h_MyDrive_Src,
FSCTL_GET_VOLUME_BITMAP,
&StartingLCN,
sizeof (StartingLCN),
Bitmap,
BitmapSize,
&BytesReturned1,
NULL);
if (Result == FALSE &&GetLastError()!= ERROR_MORE_DATA)
{
free (Bitmap);
goto label12;
}
ClusterCount = Bitmap->BitmapSize.QuadPart -
Bitmap->StartingLcn.QuadPart;
cout<<"\n Tot no of clusters :"<<ClusterCount<<"\n";
BitmapSize = sizeof (VOLUME_BITMAP_BUFFER) + (Bitmap->;BitmapSize.QuadPart / 8) + 1;
Bitmap = (VOLUME_BITMAP_BUFFER *) realloc (Bitmap, BitmapSize);
Result = DeviceIoControl(h_MyDrive_Src,
FSCTL_GET_VOLUME_BITMAP,
&StartingLCN,
sizeof (StartingLCN),
Bitmap,
BitmapSize,
&BytesReturned,
NULL);
DWORD LastError = GetLastError ();
if (Result == FALSE)
{
printf ("\nCouldn't properly read volume bitmap\n");
free (Bitmap);
goto label12;
}
BitmapDetail = (UINT32 *) malloc (sizeof(UINT32) * (1 + (ClusterCount / 32)));
memcpy (BitmapDetail, Bitmap->Buffer, sizeof(UINT32) * (1 + (ClusterCount / 32)));
UINT64 Max;
UINT64 cc;
Max=ClusterCount;
UINT64 usedcluster=0;
LONGLONG llReturnValue = 0;
for (cc = 0; cc< Max; cc++)
{
if ( IsClusterUsed (cc))
{
llCountUsed++;
printf("\n used %I64d",llCountUsed);
llTotalCount++;
LARGE_INTEGER li_Lcn;
li_Lcn.QuadPart=(LONGLONG)cc;
VOLUME_LOGICAL_OFFSET logicalOffset;
logicalOffset.LogicalOffset= li_Lcn.QuadPart *dwclusterSizeInBytes;
VOLUME_PHYSICAL_OFFSETS physicalOffsets;
DWORD dw_Bytes_Returned;
if (!DeviceIoControl(h_MyDrive_Src,
IOCTL_VOLUME_LOGICAL_TO_PHYSICAL,
&logicalOffset,
sizeof(VOLUME_LOGICAL_OFFSET),
&physicalOffsets,
sizeof(VOLUME_PHYSICAL_OFFSETS),
&dw_Bytes_Returned,
NULL) )
{
printf("\n Error occoured :%d",GetLastError));
goto label12;
}
llReturnValue += physicalOffsets.PhysicalOffset [0].Offset;
printf("\n physical offsets = %I64d",llReturnValue);
if(!SetFilePointer(hDevice,llReturnValue,NULL,0))
{
printf("\nSetFilePointer Failed: Error Number : %d\n",GetLastError());
}
if(!ReadFile(hDevice,bBuffer1,llChunk_Size,&dwRetBytes1,0))
{
printf("\nUnable to Read ( src _ handle disk) the Drive Error: %d\n",GetLastError());
}
if(!WriteFile(h_MyDrive_Dest,bBuffer1,llChunk_Size,&dwRetBytes2,0))
{
printf("\nUnable towrite the Drive Error:%d\n",GetLastError());
}
}
else
{ llCountFree++;
llTotalCount++;
}
}
cout<<"\n Total no of clusters :"<<llTotalCount<<"\n";
cout<<"\n Used no of clusters :"<<llCountUsed<<"\n";
cout<<"\n Free no of clusters :"<<llCountFree<<"\n";
CloseHandle(h_MyDrive_Src);
CloseHandle(h_MyDrive_Dest);
BOOL bupdate= DeviceIoControl(hDevice,
IOCTL_DISK_UPDATE_PROPERTIES,
NULL,
NULL,
NULL,
NULL,
&dwBytesReturnedh,
NULL);
CloseHandle(hDevice);
label12:
cout<<"\n Press any key to continue...........\n\n";
char c=getchar();
}
return nRetCode;
}
In the above code I have not touch MFT ,simply copied ; I think that is my problem.And you suggested that the logical offsets must represent the corresponding physical offsets; And I have converted the logical offset to physical.That physical offests returning are giving correct values.
Result
I:\ is not accessible
The file or directory is corrupted and unreadble.
modified on Tuesday, June 16, 2009 9:10 AM
|
|
|
|
|
Don't Be Afraid of seeing my code - Krish : no time for fear
Don't Be Afraid of seeing my code - Krish : no time for fear
Don't Be Afraid of seeing my code - Krish : no time for fear
Don't Be Afraid of seeing my code - Krish : no time for fear
|
|
|
|
|
Hi,
May i know why c++ doesn"t have virtual constructor...and why virtual destructors are present...?
|
|
|
|
|
The "virtual" mechanism depends on the VTable, which will be setup by the constructor. So, the constructor itself cannot be virtual (not with C++), even though you could try something like this[^]. The link that I've provided to you is among one of the best C++ FAQs on the internet. You may as well refer to it to read about Virtual destructors and other basic C++ stuff.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
In addition to Rajesh' reply: when you construct your object, you always know the type of object you want to create at that time (you always call a specific constructor, not the one from the base class). So, it doesn't make sense to have a virtual constructor.
Virtual destructors make more sense: when you destroy your object, you often manipulate objects as a pointer to their base class (typical scenario where polymorphism is used). In that case, you want to call the correct version of your destructor.
|
|
|
|
|
Consider this Example
class Base
{
};
class Derived: public Base
{
};
Consider this Base *b = new Base()
This means we need to create a Base object we are really not worried on who has derived from Base.
Consider this Derived *d = new Derived(); or Base *b = new Derived();
This mean we want a derived object and by default the base class constructor is called before the Derived.
So there is no use of virtual constructors.
-Arun
|
|
|
|
|
Is it possible to write an array function that returns long strings (300-600 characters) in Excel? I have tried writing a C++ dll with Excel C API and also using VBA, but get #VALUE! error if I do not truncate the strings to 255 characters. Using VBA, I have found that it is possible for single cell function.
For I = 1 To 2056
Query = Query & "A"
Next I
LongStringFunction = Query
modified on Saturday, June 13, 2009 5:25 AM
|
|
|
|
|