GetProcAddress

本文详细介绍了GetProcAddress函数的功能、参数、返回值以及使用注意事项,并通过代码示例展示了如何在实际开发中应用该函数来检索动态链接库中的输出函数地址。

GetProcAddress

编辑本段vc函数功能描述

  GetProcAddress函数检索指定的动态链接库(DLL)中的输出库函数地址。   函数原型:   FARPROC GetProcAddress(   HMODULE hModule, // DLL模块句柄   LPCSTR lpProcName // 函数名   );

编辑本段参数

  hModule   [in] 包含此函数的DLL模块的句柄。LoadLibrary、 AfxLoadLibrary 或者GetModuleHandle函数可以返回此句柄。   lpProcName   [in] 包含函数名的以NULL结尾的字符串,或者指定函数的序数值。如果此参数是一个序数值,它必须在一个字的底字节,高字节必须为0。   返回值:   如果函数调用成功,返回值是DLL中的输出函数地址。   如果函数调用失败,返回值是NULL。得到进一步的错误信息,调用函数GetLastError。

编辑本段注释

  GetProcAddress函数被用来检索在DLL中的输出函数地址。   lpProcName指针指向的函数名,拼写和大小写必须和DLL 源代码中的模块定义文件(.DEF)中输出段(EXPORTS)中指定的相同。Win32 API函数的输出名可能不同于你在代码中调用的这些函数名,这个不同被宏隐含在相关的SDK头文件中。如果想得到更多信息,请参考Win32函数原型(Win32 Function Prototypes)。   lpProcName参数能够识别DLL中的函数,通过指定一个与函数相联系的序数值(在.DEF中的EXPORTS段)。GetProcAddress函数验证那个指定的序数值是否在输出的序数1和最高序数值之间(在.DEF中)。函数用这个序数值作为索引从函数表中读函数地址,假如.DEF 文件不连续地定义函数的序数值,如从1到N(N是输出的函数序数值),错误将会发生,GetProcAddress将会返回一个错误的、非空的地址,虽然指定的序数没有对应的函数。   为了防止函数不存在,函数应该通过名字指定而不是序数值。   要求:   Windows NT/2000: 要求 Windows NT 3.1 或以后版本。   Windows 95/98: 要求Windows 95 或以后版本。   头文件: 在Winbase.h中声明,include Windows.h。   库文件: Use Kernel32.lib。

编辑本段参看

  动态链接库纵览( Dynamic-Link Libraries Overview), 动态链接库函数(Dynamic-Link Library Functions),FreeLibrary, GetModuleHandle, LoadLibrary   示例代码:   调用KERNEL32.DLL中的RegisterServiceProcess(仅在Windows98中适用)   HMODULE hModule=GetModuleHandle("kernel32.dll");   if (hModule)   {   typedef DWORD (CALLBACK *LPFNREGISTER)(DWORD,DWORD);   LPFNREGISTER lpfnRegister;   lpfnRegister=(LPFNREGISTER)GetProcAddress(hModule,"RegisterServiceProcess");   if (lpfnRegister)   {   (*lpfnRegister)(NULL,1L);   }   }
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、付费专栏及课程。

余额充值