Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Obtaining a HANDLE from IO.Ports.SerialPort

Obtaining a HANDLE from IO.Ports.SerialPort

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheIdleProgrammer
    wrote on last edited by
    #1

    Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.

    P S 2 Replies Last reply
    0
    • T TheIdleProgrammer

      Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.

      P Offline
      P Offline
      pbraun
      wrote on last edited by
      #2

      If I am remembering right the handle you are looking for is ".SafeHandle". Just look down the intellisense list.

      Phil

      T 1 Reply Last reply
      0
      • P pbraun

        If I am remembering right the handle you are looking for is ".SafeHandle". Just look down the intellisense list.

        Phil

        T Offline
        T Offline
        TheIdleProgrammer
        wrote on last edited by
        #3

        Hi Phil, As far as I can see it's not possible to obtain a SafeHandle object from the SerialPort object. I might be missing something but I don't think it's obvious though. Thanks anyway, Chris.

        1 Reply Last reply
        0
        • T TheIdleProgrammer

          Hi Everyone, Thanks for taking the time to read my question! I have an old unmanaged DLL that will handle all of the low level bootloader communications to a device on the serial port, however most of the functions in the DLL require a handle to the serial port. I also want to communicate with the device on the serial port using another protocol first (to put the device into bootloader mode) and this would be easiest done using some command classes that have already been written for another project using the System.IO.Ports.SerialPort class. Does anybody know of any fancy footwork that will allow me to begin using the serial port with the SerialPort class and then obtain a corresponding handle and pass that into the DLL calls? I'm definately not an expert in this area - it's been enough just looking into marshalling to use the unmanaged DLL, but I'm really stuck on this problem. Any help is greatly appreciated! Chris Chambers.

          S Offline
          S Offline
          snorkie
          wrote on last edited by
          #4

          Have you tried using the .CreateObjRef() method. You'll have to pass it the type of the low level dll, but it might work. Hogan

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups