Menu

Symbolic links

Help
2009-07-22
2013-05-20
  • Terry Johnson

    Terry Johnson - 2009-07-22

    This question is more of a windows question than com0com, but I'm asking it here in case someone happens to know ...

    When com0com is installed, and a pair is created so that say com 5 and com 6 are mapped in, symbolic links are created Com5 maps to \Device\com0com10 and Com6 maps to \Device\com0com20

    If you then add a printer that uses com5, the symlink is changed to \Device\NamedPipe\Spooler\Com5. This means you can no longer open Com5 as a serial port, even if the print queue isn't being used. I've seen similar behaviour with LPT ports, but sometimes you get a NONSPOOLED_LPT1 link back to the original port. Can anyone tell me if this is something I can do directly, or does it require device driver voodoo...

     
    • Vyacheslav Frolov

      > I've seen similar behaviour with LPT ports, but sometimes
      > you get a NONSPOOLED_LPT1 link back to the original port.

      The following simple link NONSPOOLED_COM5 to the original port:

      /////////////////////////////////////////////////////////////////
      #include <windows.h>
      #include <iostream>
      using namespace std;

      int main(int /*argc*/, char* /*argv[]*/)
      {
        const char *pName = "COM5";
        const char *pAltName = "NONSPOOLED_COM5";

        char pathList[1000];

        if (!QueryDosDevice(pName, pathList, sizeof(pathList)/sizeof(pathList[0]))) {
          DWORD err = GetLastError();
          cerr << "QueryDosDevice: error - " << err << endl;
          return 1;
        }

        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
          cerr << "QueryDosDevice: INSUFFICIENT BUFFER" << endl;
          return 1;
        }

        cout << pName << ":" << endl;

        char *p, *pPath = NULL;
        int j;

        for (p = pathList, j = 0 ; *p ; p += lstrlen(p) + 1, j++) {
          cout << "  " << j << ": " << p << endl;
          pPath = p;
        }

        if (pPath) {
          if (!DefineDosDevice(DDD_RAW_TARGET_PATH, pAltName, pPath)) {
            DWORD err = GetLastError();
            cerr << "DefineDosDevice: error - " << err << endl;
            return 1;
          }

          cout << "OK: " << pAltName << " --> " << pPath << endl;
        }

        return 0;
      }
      /////////////////////////////////////////////////////////////////

      To be available NONSPOOLED_COM5 for HyperTerminal, you need also
      add code to modify Registry or import to Registry the following file:

      --- NONSPOOLED_COM5.reg ---
      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM]
      "\\Device\\com0com10"="NONSPOOLED_COM5"
      ---------------------------

       

Log in to post a comment.