Announcement

Collapse
No announcement yet.

Can 32-bit program call 16-bit DLL?

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

  • Can 32-bit program call 16-bit DLL?

    I have MS Visual BASIC 6.0, Power BASIC DLL Compiler 6.0, and Power BASIC Console Compiler 2.0. Can a 32-bit BASIC program call a 16-bit DLL or do I have to write a 16-bit BASIC program? How do I convert code in header files for C programs to BASIC code? Jeffrey.

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

  • #2
    PB delivers a thunking DLL but only for win95, not NT.
    From 32 to 16 bit is called a flat thunk, HARD!
    A 16 to 32 is called a generic thunk wich i use quite often.
    It works very nice unless you wich to use 32bit custom classes in the dll
    If you wish to use 32bit popup's etc. forget that!

    In the 3th party i have a JET10 project wich works this way.
    calling a 16bit VB3 exe and communicate with it from 32bit app.


    ------------------
    hellobasic

    Comment


    • #3
      Whether you can do it, and how, depends a lot on the target OS. It's
      much easier under the Win95-based operating systems. Basically, you'd
      have to write a specialized "thunking" DLL to act as an interface
      between the 16-bit and 32-bit code. If you want to run under NT or
      Windows 2000, that's another matter. If it's practical to avoid, I'd
      suggest avoiding it!

      C headers, hmmm. Well, if they are Windows API headers, or for some
      common commercial program, you may be able to find a PowerBASIC
      translation in the Downloads area. Otherwise, you'll need to find
      someone to help you, or learn C. If you can tell us more about it,
      perhaps we can offer other ideas.


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

      Comment


      • #4
        I have Windows ME. The header file has Windows API calls and defines. The header file and the DLL file came from a 16-bit Windows program that controls model train layouts. When I wrote a Visual BASIC that uses the DLL, I get "File not found" runtime error message but the DLL file is in the same folder as the program that I'm trying to write. Copying the DLL file to C:\WINDOWS\SYSTEM folder didn't work. How can I enable word wrap when I'm typing messages on this text box? Jeffrey.

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

        Comment


        • #5

          With C to PB conversion, you might want to download: http://www.kgpsoftware.com/downloads/hdr2inc.zip

          It's a small prog that attempts to convert C (.h) files to PowerBASIC.
          Even if it doesn't work out, there is a file included that shows C type translations to PB (ie. HANDLE => LONG)
          (The utility is still in very early stages of development yet)

          BTW. You can't wrap text on this BBS, the enter key is the answer.

          ------------------
          Kev G Peel
          KGP Software, Bridgwater, UK.
          mailto:[email protected][email protected]</A>
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Wrapping depends on the Browser being used to Create or Edit a message...

            If you use MSIE, just type long lines and it will be displayed wrapped when viewed after submitting it to the BBS.

            If you do your own formatting with ENTER, it will often look unusual (and difficult to read) to everyone else viewing with different screen resolutions (esp in 640x460).

            Thanks!

            PS: Jeffrey, VB often gives that error when the <U>real</U> problem is that a Sub/Function in the DLL is not present, or VB is using the wrong capitalization of it's name.

            Check out the ALIAS clause in the DECLARE statement in PB and in VB.

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

            Comment


            • #7
              I made an error,
              the JET does not use thunking.
              Search for HUGEMEM to see a 16 to 32 bit thunk example for VB3
              (If interested of course)

              ------------------
              hellobasic

              Comment


              • #8
                Kev, I tried your HDR2INC program but it didn't work on the header file that came with the program. Lance, how can I check the capitalization of Windows API calls in the DLL file? Jeffrey.

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

                Comment


                • #9
                  If the DLL is a MS-Windows DLL (ie, a system DLL which is part of Windows itself, such as KERNEL32 or USER32, etc), then you can simply use the DECLARE's in the WIN32API.INC (and associated file set) which have the ALIAS clauses with the correct capitalization. This is certainly easier than trying to convert VB declares to PowerBASIC!

                  For other 32-bit DLL's, use a tool like "DEPENDS" to show you the exported Sub/Function names (with the correct capitalization).
                  http://www.powerbasic.com/files/pub/.../depends10.zip

                  For 16-bit DLL's, the Sub/Function names are usually always capitalized (IIRC).

                  I hope this helps!

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

                  Comment


                  • #10
                    'k. You are not going to be able to call a 16-bit DLL directly from a 32-bit EXE,
                    which is the first problem. You will need to either rewrite the DLL in 32 bits,
                    write the program with a 16-bit compiler, or write a "thunking" DLL to provide
                    an interface between the 32-bit program and 16-bit DLL.

                    As far as 16-bit and 32-bit Windows headers go, if you used the default location
                    for PowerBASIC, you'll find them in C:\PBCC20\WINAPI\ ...the latest versions of
                    the 32-bit headers may be downloaded from http://www.powerbasic.com/files/pub/pbwin/
                    (the 16-bit headers have not changed in some time, although you can find them in
                    the PBDLL16 download area if you need the latest files).

                    Capitalization is extremely unlikely to be an issue with your 16-bit code. By
                    convention, all 16-bit compilers converted symbols to uppercase automatically, so
                    symbols were effectively not case-sensitive. This is not true for 32-bit code,
                    which is where you need to have the right ALIASes in your declarations. The
                    PowerBASIC header files take care of this for you in the functions they declare.


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

                    Comment


                    • #11
                      Lance, How can I send binary values through the serial port? The first byte is &hFE and the command format looks like this to set track switch number 27 to curved leg: 0100110110011111. The bit order is from 15th to 1st. Jeffrey.

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

                      Comment


                      • #12
                        This is really best to be posted in a new topic, but you use COMM OPEN... followed by COMM SET... to set up the communication parameters (See "Serial Communications" in the help file), then:

                        COMM SEND #hComm&, CHR$(&H0FE, 27)

                        or

                        COMM SEND #hComm&, CHR$(&B001001101, &B010011111)

                        Note the leading zeros - this signifies unsigned values to avoid confusion when the leading (Most Significant) bit is set - which generally indicates a signed value.

                        PS, I'm not sure how you derived "27 and "FE" from that binary value? Was that just an adhoc example?

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

                        Comment


                        • #13
                          Lance, The program that I'm trying to write is supposed to send three bytes to the hardware that controls model train layout. The first byte is &hFE. The second and third bytes change depending on which command to send to the hardware. The manual that comes with the hardware only gives me binary values for the second and third bytes. Jeffrey.

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

                          Comment


                          • #14
                            Ok, you should be able to work them out as Decimal or Hex, or use the Binary approach I showed above (which is MSB to LSB, left to right).

                            Is the concept of Serial Comms operation clear now though? Does this mean you can drop the 16-bit DLL and just do the serial comms with native PowerBASIC statements?



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

                            Comment


                            • #15
                              Lance, I was able to drop the 16-bit DLL and use the COMM statements in PB. I used PBCC for experiments. How can I set up the program to check the sensors that are installed on my model train layout? The sensor status is stored in upper 4 bits of a byte. The program for the sensor modules is written using Visual BASIC. I'm not sure if I can convert VB code to PB code or convert the PB code that I wrote for the hardware that controls my model train layout to VB code. Jeffrey.

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

                              Comment


                              • #16
                                Lance, I wrote an experimental VB program to control my model train layout and it worked. I combined two programs into one program and it worked. Jeffrey.

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

                                Comment

                                Working...
                                X