点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
很久以前,我在这里提出了一种可能性,即如何从 ABAP 内的演示服务器的库中调用 DLL 函数。
不久前,我在这里介绍了如何在 ABAP 中使用 Windows PowerShell 的可能性。
现在这里有一个共生关系,如何在 ABAP 中通过 PowerShell 调用 DLL 函数:
"-Begin----------------------------------------------------------------- Program zCallDLL. "-TypePools--------------------------------------------------------- Type-Pools OLE2 . "-Constants--------------------------------------------------------- Constants CrLf(2) Type c Value %_CR_LF. Constants OUTPUT_CONSOLE Type i Value 0. Constants OUTPUT_WINDOW Type i Value 1. Constants OUTPUT_BUFFER Type i Value 2. "-Variables--------------------------------------------------------- Data PS Type OLE2_OBJECT. Data Result Type i Value 0. Data strResult Type String Value ''. Data tabResult Type Table Of String. Data PSCode Type String Value ''. "-Macros------------------------------------------------------------ Define _. Concatenate PSCode &1 CrLf Into PSCode. End-Of-Definition. "-Main-------------------------------------------------------------- Create Object PS 'SAPIEN.ActiveXPoSH'. If sy-subrc = 0 And PS-Handle <> 0 And PS-Type = 'OLE2'. Call Method Of PS 'Init' = Result Exporting #1 = 0. If Result = 0. Call Method Of PS 'IsPowerShellInstalled' = Result. If Result <> 0. Set Property Of PS 'OutputMode' = OUTPUT_BUFFER. _ '$sig = @"'. _ '[DllImport("User32.dll")]'. _ 'public static extern int MessageBoxA(int hWnd, String Text, String Caption, int Type);'. _ '"@;'. _ '$DLL_User32 = Add-Type PBexpMsgBox -MemberDefinition $sig -PassThru'. _ '$DLL_User32::MessageBoxA(0, "Hello World", "From WinAPI", 0);'. Call Method Of PS 'Execute' Exporting #1 = PSCode. Call Method Of PS 'OutputString' = strResult. Split strResult At cl_abap_char_utilities=>cr_lf Into Table tabResult. Loop At tabResult Into strResult. Write: / strResult. EndLoop. EndIf. EndIf. Free Object PS. EndIf. "-End-------------------------------------------------------------------
上面的示例显示了 WinAPI 调用的使用。