Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • December 10, 2016, 08:38:58 AM
  • Proudly celebrating 10 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 1447 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:32 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,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #1 on: February 09, 2010, 06:58:17 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,029
  • [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:53 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,296
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Roaming among the Dinosaurs
« Reply #3 on: February 09, 2010, 09:16:33 PM »
Oops! *Shrug* Hay, it's been awhile... ;)