Announcement

Collapse
No announcement yet.

Need 2 lines of C++ converted to PB please!

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

  • Florent Heyworth
    replied
    Wayne

    what is g_module declared as in the original file - without
    this it's impossible to give you an accurate translation - the
    2 lines you supplied are not enough!

    However the line would translate to something like (again
    this depends on what g_module points to - is it a byte pointer
    to the beginning of a file?):

    Code:
    FUNCTION OPTHDROFFSET( BYVAL g_module AS DWORD ) AS DWORD
        LOCAL ptImageDosHeader AS IMAGE_DOS_HEADER PTR
    
        ptImageDosHeader = g_module
        'SIZE_OF_NT_SIGNATURE = SIZEOF of DWORD or Pointer
        FUNCTION = g_module + @ptImageDosHeader.e_lfanew + SIZEOF(ptImageDosHeader) _
                            + LEN(IMAGE_FILE_HEADER)
        
    END FUNCTION
    
    LOCAL ptImageOptHeader AS IMAGE_OPTIONAL_HEADER PTR
    LOCAL dwSize AS DWORD
    
    ptImageOptHeader = OPTHDROFFSET( g_module )
    dwSize = @ptImageOptHeader.SizeOfImage
    If you want to be sure show what g_module corresponds to.

    Cheers

    Florent



    [This message has been edited by Florent Heyworth (edited June 19, 2001).]

    Leave a comment:


  • Wayne Diamond
    replied
    Russ, somebody also once described C++ as Extended Chinese, and for all I can tell it might as well be
    the basic language just makes sense to me - I can pretty much put code down that reads exactly how I think - "if this, then do that, else, do this", etc... C on the otherhand is a mindgame that i dont think i ever want to get into


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

    Leave a comment:


  • Russ Srole
    replied
    Wayne,

    Someone once described C as a write only language! That statement
    makes more sense to me then the code you're translating. This is
    why I stick with PB.



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

    Leave a comment:


  • Wayne Diamond
    replied
    Strewth, all that from just one line? No wonder I'm still scratching my head
    Thanks very much for your input Tom, I'm slowly getting there


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

    Leave a comment:


  • Tom Hanlin
    replied
    Code:
      DWORD dwSize=((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(g_module))->SizeOfImage;
    Without more information, the odds of correctly translating this part are dubious. OPTHDROFFSET
    looks like a macro of some sort. The "->" says that SizeOfImage is referenced by a pointer, not
    as part of an array element. I'd gather that you collect the necessary pointer by processing
    g_module through OPTHDROFFSET, returning a pointer to a value of type IMAGE_OPTIONAL_HEADER,
    from which you get the SizeOfImage.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Lance Edmonds
    replied
    My doc's say it is NT only, so you may be better off maintaining a separate INC file for use with your NT apps.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Wayne Diamond
    replied
    Incidently, I have to use VirtualFreeEx() with this as I'm getting kinky with another process, which is undefined in win32api.inc and 0 references found in poffs2
    According to an MSDN description at http://msdn.microsoft.com/library/ps...emman_5diw.htm , the prototype is:
    BOOL VirtualFreeEx(
    HANDLE hProcess, // handle to process
    LPVOID lpAddress, // starting address of memory region
    SIZE_T dwSize, // size of memory region
    DWORD dwFreeType // operation type
    );
    The only difference between VirtualFree and VirtualFreeEx being "HANDLE hProcess"
    From my win32api.inc is this VirtualFree declaration:
    DECLARE FUNCTION VirtualFree LIB "KERNEL32.DLL" ALIAS "VirtualFree" (lpAddress AS ANY, BYVAL dwSize AS LONG, BYVAL dwFreeType AS LONG) AS LONG
    So I think this is right for VirtualFreeEx:
    DECLARE FUNCTION VirtualFreeEx LIB "KERNEL32.DLL" ALIAS "VirtualFreeEx" (hProcess AS LONG, lpAddress AS ANY, BYVAL dwSize AS LONG, BYVAL dwFreeType AS LONG) AS LONG

    The exact same applies to VirtualAllocEx

    (Just for the next time the win32api.inc file gets updated, no rush - Ive already updated mine )


    [This message has been edited by Wayne Diamond (edited June 18, 2001).]

    Leave a comment:


  • Wayne Diamond
    replied
    Thankyou very much kind sir!
    The original C lines actually make a bit of sense now that I've read their PB counterpart


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

    Leave a comment:


  • Lance Edmonds
    replied
    Sheesh... I'll give it a shot, but I'm probably off base...
    Code:
      DWORD dwSize=((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(g_module))->SizeOfImage;
    ~
      DIM dwSize AS DWORD
      DIM OPTHDROFFSET(...) AS PIMAGE_OPTIONAL_HEADER ' The C code suggests (to me) this a UDT array
      dwSize = OPTHDROFFSET(g_mopdule).SizeOfImage
     
     
      char *pMem=(char *)pVirtualAllocEx(hProc,g_module,dwSize,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
    ~
      DIM pMem AS BYTE PTR
      pMem = VirtualAllocEx(hProc,  h_module, dwSize, %MEM_COMMIT OR %MEM_RESERVE, %PAGE_EXECUTE_READWRITE)
      ' Now reference the byte "array" with @pMem[index]
    Please don't shoot me if I'm wrong...

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Wayne Diamond
    started a topic Need 2 lines of C++ converted to PB please!

    Need 2 lines of C++ converted to PB please!

    Can somebody pretty pretty please convert these two lines of C++ for me? I can't make any sense out of them - variables are declared so much differently in basic
    Code:
      DWORD dwSize=((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(g_module))->SizeOfImage;
      char *pMem=(char *)pVirtualAllocEx(hProc,g_module,dwSize,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);

    ------------------
Working...
X