topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday April 15, 2024, 10:31 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Roaming among the Dinosaurs  (Read 5882 times)

parkint

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 119
  • It's bad luck to be superstitious
    • View Profile
    • Donate to Member
Roaming among the Dinosaurs
« on: February 09, 2010, 12:17 PM »
I am having trouble and hope one of my new-found friends (here on DC) can help.
In unmanaged C++ code, inside a simple DLL (for use with a proprietary interface), I need to access a COM port and read the data stream.
I can handle all the 'interpolation' of the data, but am having a real struggle getting access to the COM port; which, by the way is actually 'virtual' from a Bluetooth device.
Is there anyone out there with experience in this realm who is willing to help me?
I have scoured the Web for samples but none work as expected.

Inside this construct, I need to connect and read from a COM port:


BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD
               fdwReason,LPVOID
               lpvReserved){
                  switch (fdwReason)
                  {
                  case DLL_PROCESS_ATTACH:
                     /* Init Code here */
                     /* If there is something you need to do before the functions in this
                     * Library can be used, perform it here and return a true (or false if it fails) */
                     MessageBox ( NULL, L"Process Attach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_THREAD_ATTACH:
                     /* Thread-specific init code here */
                     MessageBox ( NULL, L"Thread Attach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_THREAD_DETACH:
                     /* Thread-specific cleanup code here.
                     */
                     MessageBox ( NULL, L"Thread Detach", L"DXExternal DLL", MB_OK);
                     break;
                  case DLL_PROCESS_DETACH:
                     /* Cleanup code here */
                     /* This is called as the DLL is being unloaded (most likely when your
                     * application is shutting down. */
                     MessageBox ( NULL, L"Process Detach", L"DXExternal DLL", MB_OK);
                     return false;
                     break;
                  }
                  /* The return value is used for successful DLL_PROCESS_ATTACH */
                  return true;
}

Thanks, in advance.

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #1 on: February 09, 2010, 06:58 PM »
I'm probably missing something here, but... COM Ports are accessed via OpenFile in Win2k and up (no direct hardware access).

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #2 on: February 09, 2010, 09:08 PM »
Eh, you want to read from the COM port in DllMain? Doesn't seem very smart to me, COM ports are slow and when control won't return back to the application loading the DLL before DllMain returns. So you'll probably either want to export some functions for dealing with the device interaction, or do CreateThread and handle the device in a background thread (and it'd still be smarter to export a StartLoggingDevice() rather than setting up the thread directly in DllMain).

At any rate, Stoic Joke is (almost :)) correct: you open the virtual COM ports with CreateFile, specying a name of \\.\COMx (for ports less than 10 you can use COM1, .. COM9 directly, but you might as well make the code generic).

You might want to check out what CodeProject has regarding serial comms :)
- carpe noctem

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #3 on: February 09, 2010, 09:16 PM »
Oops! *Shrug* Hay, it's been awhile... ;)

ElenRey

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #4 on: February 16, 2017, 06:38 AM »
The easiest way to access remote serial port is to use additional soft like Network Serial Port KIt or Serial to Ethernet Connector (as I prefer more). Here is a comparative article  http://www.eltima.co...kit-alternative.html

To log and analyze COM port data try Serial port Monitor - http://www.virtual-s...ducts/serialmonitor/


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #5 on: February 16, 2017, 07:21 AM »
You might find something useful in the source code from this project:
https://sourceforge....files/?source=navbar

Edit:  Also this page may be helpful
http://xanthium.in/S...ming-using-Win32-API

For DLL writing generally and examples what to do in the various required handlers you should be able to find something relevant in one of these C++ forums:
http://forums.codeguru.com/


« Last Edit: February 16, 2017, 08:02 AM by MilesAhead »