Announcement

Collapse
No announcement yet.

Compiling and linking

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

  • Compiling and linking

    Hello everybody

    I would like to understand how I can LINK together an OBJ file produced by PBCC6 compiler and an OBJ file
    Compiled by the MASM Assembler- If the MASM Assembler is 64 bit, are they compatible?
    Does OBJ file compiled with PBCC6 is 32 bit or 64 bit?

    Thanks

  • #2
    PowerBASIC compilers are 32 bit, you can't combine 32bit and 64bit .

    Comment


    • #3
      Besides, the PowerBasic compilers don't produce obj. files and use its own integrated linker.
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        Under Windows, you don't use OBJ files.

        The Dynamic Link Library (PB "#COMPILE DLL") is the format used to combine executable code created using different source languages within a single process.

        [ADDED]
        Although I guess - and it is a guess - you could use a third-party linker. But I don't see any way to merge 32-bit and 64-bit code.
        [/ADDED]

        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Salvatore,

          As said above, 32 and 64 bit code are not compatible, they use a different memory addressing scheme, 32 bit is limited to 4 gig address range where 64 bit is much larger. 32 bit MASM code can be reasonably easily ported to 32 bit PowerBASIC code but only as pure mnemonic code, none of the MASM directives translate to PB.

          Now as far as modules, the current versions of PowerBASIC can create SLL (static link library) files but they are not object modules as COFF and OMF object modules cannot handle basic language constructions like dynamic strings and arrays.

          You can use memory mapped files to transfer data between 32 and 64 bit applications and you can send private messages back and fourth between them but its complicated and you must have access to 64 bit code production to make it work.
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment


          • #6
            OK guys, understood.

            At least I think it'd be possible to have a 32 bit PB program that invoke (RUN) a 64 bit program on a 64 bit machine.
            Isn't it?

            Thanks everybody for your help

            Comment


            • #7
              Hi Salvatore,

              A 32 bit app can certainly run a 64 bit executable using SHELL as either synchronous or asynchronous and if you want to get complicated, you can use memory mapped files to communicate between them. Works the other way as well, 64 bit calling 32 bit.
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment


              • #8
                Steve,
                What you stated above is true.
                I have used a 64bit program to shell execute a 32bit Powerbasic exe program, and it works marvelously .
                But not able to have a 64bit program to load a 32bit Powerbasic dll , perhaps due to my limited knowledge?

                Comment


                • #9
                  Originally posted by Anne Wilson View Post
                  But not able to have a 64bit program to load a 32bit Powerbasic dll , perhaps due to my limited knowledge?
                  64 bit processes cannot load a 32bit DLL - and vice versa. End of story!

                  But, if you grok RPC and out-of-process COM servers:

                  https://docs.microsoft.com/en-us/win...teroperability

                  "On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers). On 64-bit Windows, an out-of-process 32-bit COM server can communicate with a 64-bit client, and an out-of-process 64-bit COM server can communicate with a 32-bit client. Therefore, if you have a 32-bit DLL that is not COM-aware, you can wrap it in an out-of-process COM server and use COM to marshal calls to and from a 64-bit process."






                  Comment


                  • #10
                    You can call a 32-bit In-Process COM Server DLL from a 64-bit EXE.

                    I have done this with 32-bit In-Process COM Server DLLs that I have created using Visual Basic 6.0, PowerBASIC 10, and Visual FoxPro 9.0

                    You just need to call your 32-bit In-Process COM Server DLL via a DLLSurrogate.

                    This link shows how I call 32-bit In-Process COM Server DLLs from 64-bit Take Command Console.

                    https://github.com/JoeC4281/TakeComm...2064-bit%20TCC

                    Joe


                    Comment


                    • #11
                      Thanks Stuart and Joe

                      Regarding
                      You can call a 32-bit In-Process COM Server DLL from a 64-bit EXE
                      Are there code examples to create Powerbasic in Process COM server in this forum?

                      Comment


                      • #12
                        Anne, while you cannot use 32 bit code in 64 bit and vice versa, you can pass data both ways via a memory mapped file, as long as you stay in the address range of 32 bit which at its largest is just under 2 gig. As far as executing "commands", you can use SendMessage() with the %HWND_BROADCAST" handle to pass message from 32 and 64 bit either way. Its more work to set it all up and running but working through MMF memory is genuinely fast once you set it all up.
                        hutch at movsd dot com
                        The MASM Forum

                        www.masm32.com

                        Comment


                        • #13
                          Thanks Steve
                          I will try using MMF memory to pass data from 32bit Powerbasic exe to a 64bit exe program.
                          Currently I use a text file first written by the 32bit Powerbasic exe and read in by the 64bit exe program.
                          This text file is vulnerable !

                          Comment


                          • #14
                            Originally posted by Anne Wilson View Post
                            Thanks Steve
                            I will try using MMF memory to pass data from 32bit Powerbasic exe to a 64bit exe program.
                            Currently I use a text file first written by the 32bit Powerbasic exe and read in by the 64bit exe program.
                            This text file is vulnerable !
                            As an alternative to reading and writing a file, you could also look at "named pipes" https://docs.microsoft.com/en-us/win...pc/named-pipes

                            Comment


                            • #15
                              Anne,

                              Here are a few of the toys to use with MMFs. This usage of memory mapped files is one of shared memory so you have memory speed access both ways between 32 and 64 bit code.
                              Code:
                                ' *******************************************************************
                                  GLOBAL hMMF as DWORD            ' memory mapped file handle
                                  GLOBAL pMMF as DWORD            ' pointer to shared memory
                                  GLOBAL PM_COMMAND as DWORD      ' private message for communication
                                  MACRO MMFsize = 1024*1024*1024  ' memory mapped file size in BYTES
                                ' *******************************************************************
                              
                                ' **************************************************************************
                                  MMFcreate "data_transfer_buffer",MMFsize,VarPtr(hMMF),VarPtr(pMMF)
                                  PM_COMMAND = RegisterWindowMessage("host_private_message")
                                ' **************************************************************************
                              
                                ' you would change the two strings to those of your own choice. In both the 32 and 64 bit code, the
                                ' strings must be identical and by being able to specify the string data, you solve one of the
                                ' security problems of an exposed string. Both string formats are very tolerant as long as you don't
                                ' embed zeros so you can make it look like binary garbage and it will still work OK.
                              
                              ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                              
                              SUB MMFcreate( _
                                             mapfilename$, _
                                             ByVal bcnt as DWORD, _
                                             ByVal pHandle as DWORD, _
                                             ByVal pMemory as DWORD _
                                           )
                              
                                  LOCAL hMapFile as DWORD
                              
                                  hMapFile = CreateFileMapping( _
                                                &HFFFFFFFF, _                 ' open file handle
                                                ByVal %NULL, _                ' unused security attribute
                                                %PAGE_READWRITE, _            ' read write access to memory
                                                0, _                          ' unused high DWORD
                                                bcnt, _                       ' required size in BYTEs
                                                ByVal StrPtr(mapfilename$) _  ' set file object name here
                                                )
                                  PREFIX "!"
                                    mov ecx, pHandle                          ' store address of variable in ECX
                                    mov [ecx], eax                            ' write MMF handle to variable
                                  END PREFIX
                              
                                  MapViewOfFile(hMapFile, _
                                                %FILE_MAP_WRITE, _
                                                0,0,0)
                                  PREFIX "!"
                                    mov ecx, pMemory                          ' store address of variable in ECX
                                    mov [ecx], eax                            ' write start address to variable
                                  END PREFIX
                              
                              END SUB
                              
                              ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                              
                              SUB MMFclose( _
                                            ByVal mem as DWORD, _
                                            ByVal hfile as DWORD _
                                          )
                              
                                  UnmapViewOfFile mem
                                  CloseHandle hfile
                              
                              END SUB
                              
                              ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                              This is the basic code to operate it. Case 50 is the send code, Case 51 is the read back code.

                              Code:
                              Case 50
                              tln = GetWindowTextLength(hEdit)
                              GetWindowText hEdit,ByVal pMMF,tln
                              SendMessage %HWND_BROADCAST,PM_COMMAND,0,tln
                              SetWindowText hEdit,ByVal 0
                              
                              Case 51
                              SendMessage %HWND_BROADCAST,PM_COMMAND,1,0
                              SetWindowText hEdit,ByVal pMMF
                              hutch at movsd dot com
                              The MASM Forum

                              www.masm32.com

                              Comment


                              • #16
                                Thanks Steve
                                I will give that a try ... well the only problem the 64bit code is written in C++ ... will need to see how
                                to write that C++ code to retrieve/ write the MMF data

                                Comment

                                Working...
                                X