ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

delayimp.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS SDK Library
00003  * LICENSE:         LGPL, see LGPL.txt in top level directory.
00004  * FILE:            lib/sdk/delayimp/delayimp.c
00005  * PURPOSE:         Library for delay importing from dlls
00006  * PROGRAMMERS:     Timo Kreuzer <timo.kreuzer@reactos.org>
00007  *
00008  */
00009 
00010 #include <windows.h>
00011 #include <delayimp.h>
00012 
00013 /**** load helper ****/
00014 
00015 FARPROC WINAPI
00016 __delayLoadHelper2(PCImgDelayDescr pidd, PImgThunkData pIATEntry)
00017 {
00018     DelayLoadInfo dli;
00019     int index;
00020     PImgThunkData pIAT;
00021     PImgThunkData pINT;
00022     HMODULE *phMod;
00023     FARPROC pProc;
00024 
00025     pIAT = PFromRva(pidd->rvaIAT);
00026     pINT = PFromRva(pidd->rvaINT);
00027     phMod = PFromRva(pidd->rvaHmod);
00028     index = IndexFromPImgThunkData(pIATEntry, pIAT);
00029 
00030     dli.cb = sizeof(dli);
00031     dli.pidd = pidd;
00032     dli.ppfn = (FARPROC*)pIATEntry->u1.Function;
00033     dli.szDll = PFromRva(pidd->rvaDLLName);
00034     dli.dlp.fImportByName = !(pINT[index].u1.Ordinal & IMAGE_ORDINAL_FLAG);
00035     if (dli.dlp.fImportByName)
00036     {
00037         /* u1.AdressOfData points to a IMAGE_IMPORT_BY_NAME struct */
00038         PIMAGE_IMPORT_BY_NAME piibn = PFromRva((RVA)pINT[index].u1.AddressOfData);
00039         dli.dlp.szProcName = (LPCSTR)&piibn->Name;
00040     }
00041     else
00042     {
00043         dli.dlp.dwOrdinal = pINT[index].u1.Ordinal & ~IMAGE_ORDINAL_FLAG;
00044     }
00045     dli.hmodCur = *phMod;
00046     dli.pfnCur = (FARPROC)pIAT[index].u1.Function;
00047     dli.dwLastError = GetLastError();
00048     pProc = __pfnDliNotifyHook2(dliStartProcessing, &dli);
00049     if (pProc)
00050     {
00051         pIAT[index].u1.Function = (DWORD_PTR)pProc;
00052         return pProc;
00053     }
00054 
00055     if (dli.hmodCur == NULL)
00056     {
00057         dli.hmodCur = LoadLibraryA(dli.szDll);
00058         if (!dli.hmodCur)
00059         {
00060             dli.dwLastError = GetLastError();
00061             __pfnDliFailureHook2(dliFailLoadLib, &dli);
00062 //          if (ret)
00063 //          {
00064 //          }
00065             // FIXME: raise exception;
00066             return NULL;
00067         }
00068         *phMod = dli.hmodCur;
00069     }
00070 
00071     /* dli.dlp.szProcName might also contain the ordinal */
00072     pProc = GetProcAddress(dli.hmodCur, dli.dlp.szProcName);
00073     if (!pProc)
00074     {
00075         dli.dwLastError = GetLastError();
00076         __pfnDliFailureHook2(dliFailGetProc, &dli);
00077         // FIXME: handle return value & raise exception
00078         return NULL;
00079     }
00080     pIAT[index].u1.Function = (DWORD_PTR)pProc;
00081 
00082     return pProc;
00083 }
00084 
00085 /*** The default hooks ***/
00086 
00087 FARPROC WINAPI
00088 DefaultDliNotifyHook2(unsigned dliNotify, PDelayLoadInfo pdli)
00089 {
00090     return NULL;
00091 }
00092 
00093 FARPROC WINAPI
00094 DefaultDliFailureHook2(unsigned dliNotify, PDelayLoadInfo pdli)
00095 {
00096     return NULL;
00097 }
00098 
00099 PfnDliHook __pfnDliNotifyHook2 = DefaultDliNotifyHook2;
00100 PfnDliHook __pfnDliFailureHook2 = DefaultDliFailureHook2;

Generated on Sat May 26 2012 04:35:37 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.