GetProcAddress()

本文详细介绍了GetProcAddress函数的使用方法,包括如何获取动态链接库中函数或变量的地址。文章解释了函数参数的意义,返回值的含义,并提供了注意事项及示例代码。

GetProcAddress

获得一个指定动态链接库的输出函数或者变量的地址。


FARPROC WINAPI GetProcAddress(

__in    HMODULE hModule ,

__in    LPCSTR lpProcName 

);

参数:

hModule:目标DLL的句柄。函数 LoadLibrary 或 GetModuleHandle 可得到此句柄。

lpProcName:函数或者变量名,或者函数的顺序值。如果是顺序值,那么它必须处于 low-order word(低字节),high-order word(高字节)必须为零。

返回值:

成功:目标函数或者变量的地址。

失败:NULL

获得更多错误信息请调用函数 GetLastError 。

附注:

传给参数 lpProcName 的函数名必须是必须是DLL文件的导出名,即def文件中的函数名。由于使用的SDK(软件开发包)中可能会存在宏定义,导致导出名可能和你在程序里调用的函数名不一样。更多信息请参阅:Convirtion for Function Prototypes 。

参数 lpProcName 可以依靠一个在DLL文件的函数输出表中的顺序值进行对应的识别。函数确保这个值是从1开始到def文件中定义的最大数量。接着把这个值作为索引在函数表里查询对应的函数地址。如果在def文件中不是按从1到N(N是导出函数的数量)的顺序进行连续的编号,那么可能会返回一个错误的或者无效的值,即使指定的地方没有函数。

为了防止指定的函数不存在,最好按函数名寻找函数而不是按顺序。

源码例:

参阅:Using Run-Time Dynamic Linking

要求:

头文件:声明于:Winbase.h;包含于:Windows.h

库:Kernel32.h

动态链接库:Kernel32.h

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、付费专栏及课程。

余额充值