Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using function from windows dll in abap program

Former Member
0 Likes
1,929

Hi

How can i use a function from a standard DLL that in c:\winnt\system32.?.

Ami

12 REPLIES 12
Read only

Former Member
0 Likes
1,406

The name of the DLL is ADVAPI32.DLL and the function i want to use is LogonUser, i want to use it in an ABAP program

thanx Ami

Read only

0 Likes
1,406

Hello ami,

here is the solution to your question - I know, a little bit late, but I hope not to late.

Cheers

Stefan



"-Begin-----------------------------------------------------------------
  Report  ZLOGON.

  "-Variables-----------------------------------------------------------
    Data Win32 Type OLE2_OBJECT.
    Data Token Type String Value '0000'.
    Data hToken Type Integer.
    Data phToken Type Integer.
    Data ret Type Integer.

  "-Main----------------------------------------------------------------
    Create Object Win32 'DynamicWrapperX'.

    If Win32-Handle > 0.

      "-Define external functions---------------------------------------
        Call Method Of Win32 'Register' Exporting
          #1 = 'advapi32.dll' #2 = 'LogonUserA'
          #3 = 'i=sssuup' #4 = 'r=l'.

        Call Method Of Win32 'Register' Exporting
          #1 = 'kernel32.dll' #2 = 'CloseHandle'
          #3 = 'i=h' #4 = 'r=l'.

        Call Method Of Win32 'Register' Exporting
          #1 = 'kernel32.dll' #2 = 'GetLastError'
          #3 = 'r=u'.

      Call Method Of Win32 'StrPtr' = phToken Exporting
        #1 = Token #2 = 's'.

      Call Method Of Win32 'LogonUserA' = ret Exporting
        #1 = 'bambi' #2 = '.' #3 = 'hugo' #4 = 2 #5 = 0 #6 = phToken.

      If ret <> 0.
        
        "-Logon successful----------------------------------------------
          Write: 'Logon as bambi user'.

        Call Method Of Win32 'NumGet' = hToken Exporting
          #1 = phToken.

        Call Method Of Win32 'CloseHandle' = ret Exporting
          #1 = hToken.

        If ret = 0.
          Call Method Of Win32 'GetLastError' = ret.
          Write: / ret.
        EndIf.

      Else.
        Call Method Of Win32 'GetLastError' = ret.
        Write: / ret.
      EndIf.

      Free Object Win32.

    EndIf.

"-End-------------------------------------------------------------------

Edited by: Stefan Schnell on Sep 6, 2011 7:07 AM

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

Hi...

Use this example

INCLUDE OLE2INCL.

"-Constants----


DATA IDYes TYPE i VALUE 6.

DATA IDNo TYPE i VALUE 7.

"-Variables----


DATA Win32 TYPE OLE2_OBJECT.

DATA ret TYPE i.

CREATE OBJECT Win32 'DynamicWrapperX'.

CALL METHOD OF Win32 'Register' (REGISTER IS A DLL)

EXPORTING

#1 = 'user32.dll' #2 = 'MessageBoxW'

#3 = 'i=hwwu' #4 = 'r=l'.

CALL METHOD OF Win32 'MessageBoxW' = ret (MESSAGEBOXW IS YOUR FUNCTION )

EXPORTING

#1 = 0 #2 = 'Hello World'

#3 = 'Test' #4 = 4.

IF ret = IDYes.

WRITE 'Ja'.

ELSEIF ret = IDNo.

WRITE 'Nein'.

ELSE.

WRITE '?'.

ENDIF.

FREE OBJECT Win32.

That should solve your question...

Hope to help, bye...

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

Sorry I mean

#1 parameter is you DLL

CALL METHOD OF Win32 'Register'

EXPORTING

#1 = 'user32.dll' #2 = 'MessageBoxW'

#3 = 'i=hwwu' #4 = 'r=l'.

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

Hi

you need also to register on your client this dll to make the example code working

http://www.script-coding.com/dynwrapx_eng.html#download

Put the dynwrapx.dll into win..system32 folder

and register after with command from RUN windows menù -> regsvr32.exe dynwrapx.dll

Read only

0 Likes
1,406

sorry but it didnt work

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

Hi..

have you done a debug session? What goes wrong?...

I tried and it worked with me....

Read only

0 Likes
1,406

hi

thanks but i dont have a way to upload the reg. file to all the users computers,

second i didnt know where to put the name of the dll and the function name ,

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

Hi...

try to

CALL METHOD OF Win32 'Register'

EXPORTING

#1 = 'advapi32.dll' #2 = 'LogonUser'

#3 = 'i=hwwu' #4 = 'r=l'.

CALL METHOD OF Win32 'LogonUser' = ret

EXPORTING

*#1 = 0 #2 = 'Hello World'

*#3 = 'Test' #4 = 4.

Here you'll have to use parameters of your function as indicated on msdn documentation

__in LPTSTR lpszUsername,

__in_opt LPTSTR lpszDomain,

__in LPTSTR lpszPassword,

__in DWORD dwLogonType,

__in DWORD dwLogonProvider,

__out PHANDLE phToken

More info I founded on http://msdn.microsoft.com/en-us/library/aa378184(v=vs.85).aspx

Naturally you must adeguate the code ... That's how it works.

Read only

0 Likes
1,406

do i need to upload the dll to the server?

Read only

roberto_vacca2
Active Contributor
0 Likes
1,406

HI...

no your Dll should be a standard dll....always present...

Read only

0 Likes
1,406

Hello Roberto.

I'm trying to call the example function 'MessageBoxW' from USER32.dll but when executes the function:

CALL METHOD OF win32 'MessageBoxW' = ret

EXPORTING

#1 = 0

#2 = 'Hello World'

#3 = 'Test'

#4 = 4.

The "RET" variable, always was 2.

And the program not make anything.

Please your help.

Regards.