GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll 
Author Message
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

When I use GetDiskFreeSpaceExA via a fn pointer returned by GetProCAddress
it works O.K in Win32. When I try the same thing in an MFC dll, the call
crashes.
Here is the code snippet in question:

    hLib=AfxLoadLibrary("Kernel32.dll"); // Using LoadLibraryExA makes no
difference

   pGet= (GET*) GetProcAddress(hLib,"GetDiskFreeSpaceExA");
   if(pGet!=NULL)
   {
    ...

    // This works in Win32 AND in MFC Debug mode, but crashes in MFC
release:

     if (  (*pGet) (NULL,&FreeBytes,&TotalBytes,&TotalFreeBytes) )

    // The direct call works in both Win32 and MFC.
    // The problem is I cannot use this because
    // if Windows version is earlier than OSR2, Kernel32 doesn't have it

     if ( GetDiskFreeSpaceExANULL,&FreeBytes,&TotalBytes,&TotalFreeBytes) )
    {

Anyone else had this problem and found out what to do to make the call work?

Thanks,
-Peter



Tue, 15 May 2001 03:00:00 GMT  
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll
Are you running 98? It seems as if just about every area of 98 is causing
page fault in KERNEL32>DLL! I sure hope Microsoft gets off their ass and
comes up with a patch soon.

--
URL:  http://otool.hypermart.net

In Memory:  http://otool.hypermart.net/inmemory.htm

Quote:

>When I use GetDiskFreeSpaceExA via a fn pointer returned by GetProCAddress
>it works O.K in Win32. When I try the same thing in an MFC dll, the call
>crashes.
>Here is the code snippet in question:

>    hLib=AfxLoadLibrary("Kernel32.dll"); // Using LoadLibraryExA makes no
>difference

>   pGet= (GET*) GetProcAddress(hLib,"GetDiskFreeSpaceExA");
>   if(pGet!=NULL)
>   {
>    ...

>    // This works in Win32 AND in MFC Debug mode, but crashes in MFC
>release:

>     if (  (*pGet) (NULL,&FreeBytes,&TotalBytes,&TotalFreeBytes) )

>    // The direct call works in both Win32 and MFC.
>    // The problem is I cannot use this because
>    // if Windows version is earlier than OSR2, Kernel32 doesn't have it

>     if ( GetDiskFreeSpaceExANULL,&FreeBytes,&TotalBytes,&TotalFreeBytes) )
>    {

>Anyone else had this problem and found out what to do to make the call
work?

>Thanks,
>-Peter



Tue, 15 May 2001 03:00:00 GMT  
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

Quote:
>    // This works in Win32 AND in MFC Debug mode, but crashes in MFC
>release:

>     if (  (*pGet) (NULL,&FreeBytes,&TotalBytes,&TotalFreeBytes) )

Peter,

It's likely that you've got your definition of the function pointer
slightly wrong. Debug code will mask this in some circumstances.

If you have VC++ 6, its new /GZ compiler option will catch these
incorrect calling conventions in debug mode too.

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Wed, 16 May 2001 03:00:00 GMT  
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

Hello Chuck;

No, I'm not on Win98, I'm running Visual C++ Version 5.0 on Win95 OSR2;

Hello David;

No error in the typedef of GET,
here it is:

typedef BOOL (GET)
(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
then I have
GET* pGet;

Anyway, the data returned by *pGet is correct when it doesn't crash. It
"only" crashes in MFC release mode.
When it does, I opt to invoke debug without the source code capability in
release mode. Visual Studio informs me of Unhandled Exception in the module
that has this code. After that, I decided to try and catch the b...in the
most basic way :

try
    {
    retValueGET=(*pGet)(NULL,&FreeBytes,&TotalBytes,&TotalFreeBytes);
    }
    catch(...)
    {
     AfxMessageBox("GET didn't work!");
    }

Incredibly now there is nothing to catch! The code "works", but as you might
imagine, we're not amused!
I can't imagine this to be reliable for release, nor do I think I'm doing
anything wrong. Others must have bumped into this, so probably there'll be
more responses. Microsoft is as yet mum on the subject. At least, I cannot
find any reference to it.

Thanks fellows for your responses!

-Peter



Wed, 16 May 2001 03:00:00 GMT  
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

Quote:
>No error in the typedef of GET,
>here it is:

>typedef BOOL (GET)
>(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);

Peter,

Try this instead:

typedef BOOL (CALLBACK GET)
(LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);

VC6 does have its good points, the debug build throws up these subtle
sorts of errors straight away :)

Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Wed, 16 May 2001 03:00:00 GMT  
 GetDiskFreeSpaceExA called with pointer causes invalid page fault in MFC dll

Right on Dave!
The GetProcAddress documentation confirmed your diagnosis:
I do indeed need a pointer to a WINAPI type function. The code now works as
it should. Maybe I'll upgrade to Visual C++ Version 6.0.

Thanks again!
-Peter



Thu, 17 May 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. MSDEV caused an invalid page fault in Module SSSCC.DLL After Install SP2

2. CONNECT caused an invalid page fault in module KERNEL32.DLL at 017f:bff7b9f2

3. MSDEV.EXE caused an invalid page fault in module SSSCC.DLL

4. 3rd party implicit (load-time) dll when exitting app causes invalid page fault

5. caused an invalid page fault in module ...

6. MSDEV causing invalid page fault: HELP!

7. MSDEV causing invalid page fault: HELP!

8. RasHangUp() -> RNAAPP causing invalid page fault

9. NEED HELP: Thread Termination causes invalid page fault in Release built only

10. What causes invalid page fault?

11. MSDEV invalid page faults in RCDLL.DLL and MFC42.DLL

12. MSDEV invalid page faults in RCDLL.DLL and MFC42.DLL

 

 
Powered by phpBB® Forum Software