Click to See Complete Forum and Search --> : ntfs disk quota COM interface problem


barex
December 13th, 2006, 04:05 AM
Hi,
A couple of days ago I found an interesting article about how to query NTFS quota entries:
http://www.codeproject.com/system/DiskQuota.asp

I want to write my own console application, but I'm stuck whit a runtime crash in the very begining of my code: main2.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

I'm new in COM programming, so there is a chance that I do sommething wrong.
I found this in the event viewer:
Faulting application main2.exe, version 0.0.0.0, faulting module dskquota.dll, version 5.1.2600.2180, fault address 0x00008afe.

I'm using visual studio 6 SP6 with windows xp SP2.
Please if somebody have time for this then look at my code(maybe debug :-) ) and help me.
There is the code:

#define UNICODE
#define _UNICODE
#define INITGUIDS

#define DISKQUOTA_IS_SUPPORTED(s) (FILE_VOLUME_QUOTAS == ((s) & FILE_VOLUME_QUOTAS))

#include <dskquota.h>
#include <stdio.h>
#include <comdef.h>
#include <assert.h>

int main(){

CoInitialize ( NULL );
_COM_SMARTPTR_TYPEDEF(IDiskQuotaControl, IID_IDiskQuotaControl);
_COM_SMARTPTR_TYPEDEF(IEnumDiskQuotaUsers, IID_IEnumDiskQuotaUsers);
_COM_SMARTPTR_TYPEDEF(IDiskQuotaUser, IID_IDiskQuotaUser);

IDiskQuotaControlPtr ptrDQControl;
IEnumDiskQuotaUsersPtr ptrEnumDQUsers;
IDiskQuotaUserPtr ptrDQUser;
//DWORD pdwState;
DWORD dwFlags;
HRESULT hr;
TCHAR szLogonName[128],szDisplayName[128];
GetVolumeInformation(L"c:\\", NULL, 0, NULL, NULL, &dwFlags, NULL, 0);
if (DISKQUOTA_IS_SUPPORTED(dwFlags)){
wprintf(L"suported\n");
}

ptrDQControl.CreateInstance(CLSID_DiskQuotaControl);
if(NULL != ptrDQControl)
hr = ptrDQControl->Initialize(L"c:\\", TRUE);
else assert(false);

if (SUCCEEDED(hr)){
hr = ptrDQControl->CreateEnumUsers(NULL,
0,DISKQUOTA_USERNAME_RESOLVE_SYNC,
&ptrEnumDQUsers);
if (SUCCEEDED(hr)){
while ( ptrEnumDQUsers->Next(1,&ptrDQUser, NULL) == NOERROR){
/*CRASH->*/ hr = ptrDQUser->GetName(NULL, /*<- CRASH*/
0,
szLogonName,
sizeof(szLogonName)/2,
szDisplayName,
sizeof(szDisplayName)/2);

//"main2.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

if (NOERROR == hr)
wprintf(L"Logon name = ]%s[ | Display name]%s[\n", szLogonName,szDisplayName);
}
}
}
CoUninitialize();
return 0;
}


Thanks...

barex
December 15th, 2006, 08:51 AM
Hi,
After 2 days I found the answer...
The problem was that I used the old dskquota.h file shipped with Visual Studio 6.0. and apparently the dskquota.dll (in windows xp sp2)
was not happy about it :-)
After I installed the windows paltform sdk and included the new header (dskquota.h) it worked just fine.

Br,
barex