Announcement

Collapse
No announcement yet.

Passing BASIC file handles into/out of DLLs

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

  • Jeff Burrell
    replied
    Yes, I can. Your previous post showed me the way and now
    all is working as desired.

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

    Leave a comment:


  • Eric Pearson
    replied
    > I wanted to be able to control the stepper...

    You can do that. You just have to pass a file handle from FILEATTR, not a file number.

    -- Eric

    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Jeff Burrell
    replied
    Thanks for the help. Usually try to encapsulate my file
    accesses, but in this case I am writing a DLL to control
    an XYZ stepper assembly that needs to be called by BASIC
    and "C" programs. I wanted to be able to control the
    stepper using a modeless dialog and so needed a way to
    pass the file number back and forth.

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

    Leave a comment:


  • Eric Pearson
    replied
    hAcquisitionFile is not a file handle, it is a file number that only has meaning within a given EXE or DLL. For example, OPEN... AS #1 in one module has no relationship whatsoever to an OPEN... #1 in another module. ("Module" here means an EXE or a DLL.)

    Use the FILEATTR function to obtain a handle (for a file number) that can be passed to other modules, then use OPEN HANDLE in the other module, before the GET. And don't forget to CLOSE the handle after the GET (or at some point after you are done using the handle).

    Better yet, it's generally a good idea to put all of your file-handling operations in one module or the other.

    -- Eric


    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited July 26, 2001).]

    Leave a comment:


  • Sven Blumenstein
    replied
    Try it with
    Code:
    FUNCTION GetPacket(AcquisitionFile AS LONG, _
    PktBuf AS PIUDataPktStruc) EXPORT AS LONG
    ------------------
    E-Mail (home): mailto:[email protected][email protected]</A>
    E-Mail (work): mailto:[email protected]s[email protected]</A>

    Leave a comment:


  • Jeff Burrell
    started a topic Passing BASIC file handles into/out of DLLs

    Passing BASIC file handles into/out of DLLs

    I have been having trouble passing file handles into and
    out of DLLs. I have tried several times to open a file thus:

    AcquisitionFileName = "MyAcqFile.ACQ"
    hAcquisitionFile = FREEFILE
    OPEN AcquisitionFileName FOR BINARY AS #hAcquisitionFile BASE = 0

    I then try to call a function in a DLL and pass the file
    handle (hAcquisitionFile) as a parameter to the function and
    use it as:

    FUNCTION GetPacket(AcquisitionFile AS INTEGER, _
    PktBuf AS PIUDataPktStruc) EXPORT AS LONG
    ...
    GET #AcquisitionFile,,PktBuf
    ...

    END FUNCTION

    When I examine the contents of the PktBuf TYPE, I find all
    zeros. I have found that if I open the file in the DLL all
    goes swimmingly and the packet buffer is filled as expected.

    I have looked at the Microsoft documentation in my VC++
    compiler, Petzold, and checked the FAQ and PB for Windows
    areas for hints about the problem to no avail.

    Does anyone know what is happening here? It seems that you
    must be able to pass a file handle. The only help I saw was
    a C function that would translate a C file handle to an
    operating system file handle. This is, of course, of no
    help in PB.

    ------------------
Working...
X
😀
🥰
🤢
😎
😡
👍
👎