GetProcAddress

本文详细介绍了GetProcAddress函数的功能和使用方法,该函数用于检索指定DLL中的输出库函数地址。文章解释了函数的参数、返回值及如何正确地声明和使用获取到的函数地址。

GetProcAddress函数检索指定的动态链接库(DLL)中的输出库函数地址。

  函数原型:

  FARPROC GetProcAddress(

  HMODULE hModule, // DLL模块句柄

  LPCSTR lpProcName // 函数名

  );

 参数:

 hModule

  [in] 包含此函数的DLL模块的句柄。LoadLibrary、AfxLoadLibrary 或者GetModuleHandle函数可以返回此句柄。

  lpProcName

  [in] 包含函数名的以NULL结尾的字符串,或者指定函数的序数值。如果此参数是一个序数值,它必须在一个字的底字节,高字节必须为0。

  返回值:

  如果函数调用成功,返回值是DLL中的输出函数地址。

  如果函数调用失败,返回值是NULL。得到进一步的错误信息,调用函数GetLastError。

 

FARPROC 是一个4字节指针,指向一个函数的内存地址,例如
GetProcAddress 的返回类型就是一个FARPROC。
如果你要存放这个地址,可以声明以一个 FARPROC变量来存放。

 

GetProcAddress返回的是一个函数地址的指针。
声明:FARPROC WINAPI GetProcAddress(__in HMODULE hModule, __in LPCSTR LpProcName);
你应该知道你要的函数的类型是什么,可以用typedef的方法定义函数类型,然后定义一个这种类型的变量,你得到地址后,将地址的类型转换并存到那个变量中就行了。例如:

 这是RunHook定义:
BOOL _stdcall RunHook(HMODULE hModule,DWORD dwThreadId)
{
HWndHook=::SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)HOOKProc,hMod,dwThreadId);
return TRUE;
}

这是全局声明:
typedef BOOL (_stdcall *funRunHook)(HMODULE hModule,DWORD dwThreadID);

这两种调用都不行:
funRunHook RunHook;
RunHook=(funRunHook)GetProcAddress(hMod,"RunHook");

function LoadDLL_wpFunc: Boolean; begin Result := False; lhwpFunc := SafeLoadLibrary(DM.AppPath + DL_Funcs); if lhwpFunc <> 0 then try // @WriteToReg := GetProcAddress(lhwpFunc, PAnsiChar('_WriteToReg')); // @ReadFromReg := GetProcAddress(lhwpFunc, PAnsiChar('_ReadFromReg')); @FindTask := GetProcAddress(lhwpFunc, PAnsiChar('_FindTask')); @WpGetTempPath := GetProcAddress(lhwpFunc, PAnsiChar('_WpGetTempPath')); @DelTree := GetProcAddress(lhwpFunc, PAnsiChar('_DelTree')); // @XorCrypt := GetProcAddress(lhwpFunc, PAnsiChar('_XorCrypt')); @HelpShow := GetProcAddress(lhwpFunc, PAnsiChar('_HelpShow')); @EraseNode := GetProcAddress(lhwpFunc, PAnsiChar('_EraseNode')); @GetTreeText := GetProcAddress(lhwpFunc, PAnsiChar('_GetTreeText')); @FileSetAttribute := GetProcAddress(lhwpFunc, PAnsiChar('_FileSetAttribute')); @DeleteFiles := GetProcAddress(lhwpFunc, PAnsiChar('_DeleteFiles')); @WriteFormPos := GetProcAddress(lhwpFunc, PAnsiChar('_WriteFormPos')); @ReadFormPos := GetProcAddress(lhwpFunc, PAnsiChar('_ReadFormPos')); @IsInList := GetProcAddress(lhwpFunc, PAnsiChar('_IsInList')); @SetAutoStart := GetProcAddress(lhwpFunc, PAnsiChar('_SetAutoStart')); @IsValidFileName := GetProcAddress(lhwpFunc, PAnsiChar('_IsValidFileName')); @StrToListBox := GetProcAddress(lhwpFunc, PAnsiChar('_StrToListBox')); @StrToIDList := GetProcAddress(lhwpFunc, PAnsiChar('_StrToIDList')); @Str2Int := GetProcAddress(lhwpFunc, PAnsiChar('_Str2Int')); @WriteDebugFile := GetProcAddress(lhwpFunc, PAnsiChar('_WriteDebugFile')); @EncodeStream := GetProcAddress(lhwpFunc, PAnsiChar('EncodeStream')); @DecodeStream := GetProcAddress(lhwpFunc, PAnsiChar('DecodeStream')); @EncodeString := GetProcAddress(lhwpFunc, PAnsiChar('EncodeString')); @DecodeString := GetProcAddress(lhwpFunc, PAnsiChar('DecodeString')); @EncodeBase64 := GetProcAddress(lhwpFunc, PAnsiChar('EncodeBase64')); @DecodeBase64 := GetProcAddress(lhwpFunc, PAnsiChar('DecodeBase64')); @PrinterExist := GetProcAddress(lhwpFunc, PAnsiChar('_PrinterExist')); @DateUnitUnformat := GetProcAddress(lhwpFunc, PAnsiChar('_DateUnitUnformat')); @DateToName := GetProcAddress(lhwpFunc, PAnsiChar('_DateToName')); // @PowerCheck := GetProcAddress(lhwpFunc, PAnsiChar('_PowerCheck')); @FileCompare := GetProcAddress(lhwpFunc, PAnsiChar('_FileCompare')); @GetOnlyFileName := GetProcAddress(lhwpFunc, PAnsiChar('_GetOnlyFileName')); //////////////////////////////////////////////////////////////////////////////// @CombinePeg := GetProcAddress(lhwpFunc, PAnsiChar('_CombinePeg')); @StrToPeg := GetProcAddress(lhwpFunc, PAnsiChar('_StrToPeg')); @PegMarksReal := GetProcAddress(lhwpFunc, PAnsiChar('_PegMarksReal')); @PegMarksChar := GetProcAddress(lhwpFunc, PAnsiChar('_PegMarksChar')); @PegMarkSQLStr := GetProcAddress(lhwpFunc, PAnsiChar('_PegMarkSQLStr')); @PegKeyPress := GetProcAddress(lhwpFunc, PAnsiChar('_PegKeyPress')); @DoubleKeyPress := GetProcAddress(lhwpFunc, PAnsiChar('_DoubleKeyPress')); @IntKeyPress := GetProcAddress(lhwpFunc, PAnsiChar('_IntKeyPress')); @ClearStringGrid := GetProcAddress(lhwpFunc, PAnsiChar('_ClearGrid')); @FillGridNo := GetProcAddress(lhwpFunc, PAnsiChar('_FillGridNo')); @InsLeftCol := GetProcAddress(lhwpFunc, PAnsiChar('_InsLeftCol')); @InsRightCol := GetProcAddress(lhwpFunc, PAnsiChar('_InsRightCol')); @DelCol := GetProcAddress(lhwpFunc, PAnsiChar('_DelCol')); @AddLeftXCol := GetProcAddress(lhwpFunc, PAnsiChar('_AddLeftXCol')); @AddRightXCol := GetProcAddress(lhwpFunc, PAnsiChar('_AddRightXCol')); @DelXCol := GetProcAddress(lhwpFunc, PAnsiChar('_DelXCol')); @AddUpRow := GetProcAddress(lhwpFunc, PAnsiChar('_AddUpRow')); @AddDownRow := GetProcAddress(lhwpFunc, PAnsiChar('_AddDownRow')); @DelRow := GetProcAddress(lhwpFunc, PAnsiChar('_DelRow')); @RowIsNull := GetProcAddress(lhwpFunc, PAnsiChar('_RowIsNull')); @CalcGridError := GetProcAddress(lhwpFunc, PAnsiChar('_CalcGridError')); @CreateSGPtFixedRect := GetProcAddress(lhwpFunc, PAnsiChar('_CreateSGPtFixedRect')); @MultiCellDraw := GetProcAddress(lhwpFunc, PAnsiChar('_MultiCellDraw')); @ComnGridDrawCell := GetProcAddress(lhwpFunc, PAnsiChar('_ComnGridDrawCell')); @ComnTrvDrawItem := GetProcAddress(lhwpFunc, PAnsiChar('_ComnTrvDrawItem')); @BallyPeg := GetProcAddress(lhwpFunc, PAnsiChar('_BallyPeg')); @BallyPegEx := GetProcAddress(lhwpFunc, PAnsiChar('_BallyPegEx')); @BallyDate := GetProcAddress(lhwpFunc, PAnsiChar('_BallyDate')); @CompareBEPeg := GetProcAddress(lhwpFunc, PAnsiChar('_CompareBEPeg')); @CenterTextOut := GetProcAddress(lhwpFunc, PAnsiChar('_CenterTextOut')); @DrawGridText := GetProcAddress(lhwpFunc, PAnsiChar('_DrawGridText')); @XColInARowIsNull := GetProcAddress(lhwpFunc, PAnsiChar('_XColInARowIsNull')); @XColIsNull := GetProcAddress(lhwpFunc, PAnsiChar('_XColIsNull')); @isPegMark := GetProcAddress(lhwpFunc, PAnsiChar('_isPegMark')); @Amend := GetProcAddress(lhwpFunc, PAnsiChar('_Amend')); @FormatDouble := GetProcAddress(lhwpFunc, PAnsiChar('_FormatDouble')); @FormatFS := GetProcAddress(lhwpFunc, PAnsiChar('_FormatFS')); @FormatSS := GetProcAddress(lhwpFunc, PAnsiChar('_FormatSS')); @FormatSSCanNull := GetProcAddress(lhwpFunc, PAnsiChar('_FormatSSCanNull')); @GetCanNullValue := GetProcAddress(lhwpFunc, PAnsiChar('_GetCanNullValue')); @GetFirstRow := GetProcAddress(lhwpFunc, PAnsiChar('_GetFirstRow')); @MyTrim := GetProcAddress(lhwpFunc, PAnsiChar('_MyTrim')); @DToD := GetProcAddress(lhwpFunc, PAnsiChar('_DToD')); @Floor := GetProcAddress(lhwpFunc, PAnsiChar('_Floor')); @FormatLandSlide := GetProcAddress(lhwpFunc, PAnsiChar('_FormatLandSlide')); @Average := GetProcAddress(lhwpFunc, PAnsiChar('_Average')); @StdDev := GetProcAddress(lhwpFunc, PAnsiChar('_StdDev')); @Variance := GetProcAddress(lhwpFunc, PAnsiChar('_Variance')); @Absoluteness := GetProcAddress(lhwpFunc, PAnsiChar('_Absoluteness')); @Precision := GetProcAddress(lhwpFunc, PAnsiChar('_Precision')); @Deputation := GetProcAddress(lhwpFunc, PAnsiChar('_Deputation')); @MaxValues := GetProcAddress(lhwpFunc, PAnsiChar('_MaxValues')); @MinValues := GetProcAddress(lhwpFunc, PAnsiChar('_MinValues')); @Sum := GetProcAddress(lhwpFunc, PAnsiChar('_Sum')); @Log10 := GetProcAddress(lhwpFunc, PAnsiChar('_Log10')); @Log2 := GetProcAddress(lhwpFunc, PAnsiChar('_LogN')); @LogN := GetProcAddress(lhwpFunc, PAnsiChar('_LogN')); @CalcBelieveT := GetProcAddress(lhwpFunc, PAnsiChar('_CalcBelieveT')); @GetAngleT := GetProcAddress(lhwpFunc, PAnsiChar('_GetAngleT')); @GetIntension := GetProcAddress(lhwpFunc, PAnsiChar('_GetIntension')); @GetBayDegree := GetProcAddress(lhwpFunc, PAnsiChar('_GetBayDegree')); @GetTemperatureAmend := GetProcAddress(lhwpFunc, PAnsiChar('_GetTemperatureAmend')); @Beton3Intensity := GetProcAddress(lhwpFunc, PAnsiChar('_Beton3Intensity')); @SortBomp := GetProcAddress(lhwpFunc, PAnsiChar('_SortBomp')); @Sort := GetProcAddress(lhwpFunc, PAnsiChar('_Sort')); @SortInteger := GetProcAddress(lhwpFunc, PAnsiChar('_SortInteger')); @FindIndex := GetProcAddress(lhwpFunc, PAnsiChar('_FindIndex')); @FindIndexB := GetProcAddress(lhwpFunc, PAnsiChar('_FindIndexB')); @FormatStr2Num := GetProcAddress(lhwpFunc, PAnsiChar('_FormatStr2Num')); @MessageShow := GetProcAddress(lhwpFunc, PAnsiChar('_MessageShow')); @ShowDWG := GetProcAddress(lhwpFunc, PAnsiChar('_ShowDWG')); @ShowTimeMessage := GetProcAddress(lhwpFunc, PAnsiChar('_ShowMSG')); @IIF := GetProcAddress(lhwpFunc, PAnsiChar('_IIF')); //040703 @CanFocusMe := GetProcAddress(lhwpFunc, PAnsiChar('_CanFocus')); //061026 @CheckPrinterStatus := GetProcAddress(lhwpFunc, PAnsiChar('_CheckPrinterStatus')); //040703 @ShowMsgFmt := GetProcAddress(lhwpFunc, PAnsiChar('_ShowMsgFmt')); //040703 @ShowMsgPos := GetProcAddress(lhwpFunc, PAnsiChar('_ShowMsgPos')); //040703 @DispMSG := GetProcAddress(lhwpFunc, PAnsiChar('_DispMSG')); //040703 @ShowMSG := GetProcAddress(lhwpFunc, PAnsiChar('_ShowMSG')); //040703 @FirmMSG := GetProcAddress(lhwpFunc, PAnsiChar('_FirmMSG')); //040703 @FirmTimeMSG := GetProcAddress(lhwpFunc, PAnsiChar('_FirmTimeMSG')); //060815 @DialogMsg := GetProcAddress(lhwpFunc, PAnsiChar('_DialogMsg')); //061210 @InputDlg := GetProcAddress(lhwpFunc, PAnsiChar('_InputDlg')); //040703 @SetAppSilence := GetProcAddress(lhwpFunc, PAnsiChar('_SetAppSilence')); @GetAppSilence := GetProcAddress(lhwpFunc, PAnsiChar('_GetAppSilence')); @SmallToBig := GetProcAddress(lhwpFunc, PAnsiChar('_SmallToBig')); @GetGridMinHeight := GetProcAddress(lhwpFunc, PAnsiChar('_GetGridMinHeight')); @AddToArray := GetProcAddress(lhwpFunc, PAnsiChar('_AddToArray')); @AddToSubArray := GetProcAddress(lhwpFunc, PAnsiChar('_AddToSubArray')); @CurrStrToCurr := GetProcAddress(lhwpFunc, PAnsiChar('_CurrStrToCurr')); @SeparatorStr := GetProcAddress(lhwpFunc, PAnsiChar('_SeparatorStr')); @StrToStrList := GetProcAddress(lhwpFunc, PAnsiChar('_StrToStrList')); //20180831 @MultiSeparator := GetProcAddress(lhwpFunc, PAnsiChar('_MultiSeparator')); @SQLCondition := GetProcAddress(lhwpFunc, PAnsiChar('_SQLCondition')); @NewID := GetProcAddress(lhwpFunc, PAnsiChar('_NewID')); @IntToTimeString := GetProcAddress(lhwpFunc, PAnsiChar('_IntToTimeString')); @GetPdfPageCount := GetProcAddress(lhwpFunc, PAnsiChar('_GetPdfPageCount')); @IndexOfStrList := GetProcAddress(lhwpFunc, PAnsiChar('_IndexOfStrList')); //20180831 @DynamicCreateField := GetProcAddress(lhwpFunc, PAnsiChar('_DynamicCreateField')); //100321 @CopyField := GetProcAddress(lhwpFunc, PAnsiChar('_CopyField')); //100321 @CopyCDSFields := GetProcAddress(lhwpFunc, PAnsiChar('_CopyCDSFields')); //100321 @GetTheLastNode := GetProcAddress(lhwpFunc, PAnsiChar('_GetTheLastNode')); //100321 @VarToInt := GetProcAddress(lhwpFunc, PAnsiChar('_VarToInt')); //100321 @VarToFloat := GetProcAddress(lhwpFunc, PAnsiChar('_VarToFloat')); //100321 @CDSModified := GetProcAddress(lhwpFunc, PAnsiChar('_CDSModified')); //100321 @StrToCondition := GetProcAddress(lhwpFunc, PAnsiChar('_StrToCondition')); //100321 @SetControlItems := GetProcAddress(lhwpFunc, PAnsiChar('_SetControlItems')); //100321 @SetControlItemsEx := GetProcAddress(lhwpFunc, PAnsiChar('_SetControlItemsEx')); //100321 @CheckImageType := GetProcAddress(lhwpFunc, PAnsiChar('_CheckImageType')); //20190802 finally Result := True; end; // Sleep(100); end;
最新发布
10-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值