如何编写c++dll函数来获取com端口Reading

How to write c++ dll function to get com port Reading

本文关键字:com 端口 Reading 获取 何编写 c++dll 函数      更新时间:2023-10-16

所有我都是c++的新手,我试图从c中的函数读取COM端口++下面是代码的说明,有人能帮我完成吗?函数应该获取注释中的值,请帮助我感谢

int ComPortReading( short, wchar_t * Data[], wchar_t **Output, SIZE_T *OutputSize )
{
int result = 1;
if( Data[0] )
{
    *OutputSize = 50;
    *Output = (wchar_t *) CoTaskMemAlloc(*OutputSize);
    if( *Output )
    {
        wchar_t *EndPtr;
        double v11 = wcstod(Data[0], &EndPtr);  // Port Name
        double v12 = wcstod(Data[1], &EndPtr);  // Baud Rate
        double v13 = wcstod(Data[2], &EndPtr);  // Data Bits
        double v14 = wcstod(Data[3], &EndPtr);  // Stop Bits
        double v15 = wcstod(Data[4], &EndPtr);  // Parity
 // Need to write code here to read COM port
       // Com port settings can be taken from the above v11 - v15 values
        swprintf(*Output, L"%.10lf", v11);
        result = 0;
    }
}
return result;
}

我建议使用一个库,它封装了硬东西。例如,CodeProject上的这个库或Boost.Asio.的实现