Announcement

Collapse
No announcement yet.

Assembly help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Assembly help

    I have not done much in the way of assembly with Win32 and I am
    hoping to give myself more time in this area. One of the ways
    to quickly learn is to cut and paste some existing code. I am
    converting a small TASM win32 example to compile in PBDLL60. I want
    to preserve as much ASM code as possible. My question is if PB allows
    me to use the ASM 'call' instruction to make an API call.

    For instance,

    Code:
        '*GET some needed SystemMetrics
     
        ! push %SM_CXSIZEFRAME
        ! call GetSystemMetrics
     
        ! mov [SM_CX_SizeFrame], eax
    
        ! push %SM_CYSIZEFRAME
        ! call GetSystemMetrics
    I could convert this back to an API call, but I want to preserve as
    much as I can. What I think I need is the address of the function
    GetSystemMetrics to use the asm call instruction. So perhaps CODEPTR()
    would be the answer?

    Code:
        Local lpAnyApiCall As Dword
        lpAnyApiCall = CODEPTR(GetSystemMetrics)
    
        ! push %SM_CXSIZEFRAME
        ! call GetSystemMetrics
     
        ! mov [SM_CX_SizeFrame], eax
    
        ! push %SM_CYSIZEFRAME
        ! call lpAnyApiCall
    Any tips, suggestions, comments are much appreciated.

    Thanks!
    Regards, Jules



  • #2
    Hi Jules

    CODEPTR will only return the address of a function/label/sub in your file not in a dll.

    For your purpose something like:

    Code:
    LOCAL hLib AS LONG
    LOCAL dwCall AS DWORD
    LOCAL lResult AS LONG
    
    hLib = LoadLibrary( "user32.dll" )
    IF hLib <> %NULL THEN
        dwCall = GetProcAdress( hLib, "GetSystemMetrics" )
        IF dwCall <> %NULL THEN
            ! push %SM_CXSIZEFRAME
            ! call dwCall
            ! mov lResult, eax
            
            MSGBOX STR$(lResult)
            
            ! push %SM_CXFULLSCREEN
            ! call dwCall
            ! mov lResult, eax
            
             MSBOX STR$(lResult)
    would do the trick

    Cheers

    Florent

    ------------------

    Comment


    • #3
      Thanks Florent!

      I think I have seen this demonstrated before? Maybe Hutch? I thought the
      codeptr boundaries was limited only for labels?

      In any case your solution works.

      I thought that user32.dll was already loaded by the win32api.inc delares?
      If so, perhaps another method to obtain the address is possible?
      Just thinking of reducing 3 lines of code,

      LoadLibrary
      GetProcAddress
      FreeLibrary

      to one line. Otherwise it would now be worth just converting back to a conventional
      PB function with a parameter list.

      Regards, Jules


      Comment


      • #4
        hi jules

        codeptr will work for functions, subs and labels which have actual "bodies" in your code - procedures in a dll are not accessible.

        it's true that user32.dll is mapped in your process space - however i can't, offhand, think of any simple way to access the mapped dll without having to consider stuff like readprocessmemory and such which would significantly increase the complexity of the code and would offset any negligible advantage you might get by not calling loadlibrary, etc

        a quick search on the pb site did indeed reveal some code by hutch at

        as they say in french "qui cherche trouve" (he who seeks findeth)

        florent


        [this message has been edited by florent heyworth (edited may 26, 2000).]

        Comment

        Working...
        X