修复字符串函数BUG

This commit is contained in:
gb 2024-02-27 13:38:39 +08:00
parent 33eeb4986e
commit 87d975f523
5 changed files with 81 additions and 38 deletions

View File

@ -72,6 +72,7 @@ Revision History:
#define NUM_STRING_DESC_TO_GET 32
//*****************************************************************************
// L O C A L F U N C T I O N P R O T O T Y P E S
//*****************************************************************************
@ -455,7 +456,7 @@ EnumerateHostController (
size_t cbDriverName = 0;
HRESULT hr = S_OK;
hr = StringCbLength(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
hr = StringCbLengthA(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
if (SUCCEEDED(hr))
{
DevProps = DriverNameToDeviceProperties(driverKeyName, cbDriverName);
@ -577,7 +578,7 @@ EnumerateHostController (
size_t cbHubName = 0;
HRESULT hr = S_OK;
hr = StringCbLength(rootHubName, MAX_DRIVER_KEY_NAME, &cbHubName);
hr = StringCbLengthA(rootHubName, MAX_DRIVER_KEY_NAME, &cbHubName);
if (SUCCEEDED(hr))
{
EnumerateHub(hHCItem,
@ -723,7 +724,7 @@ EnumerateHub (
// Allocate a temp buffer for the full hub device name.
//
hr = StringCbLength("\\\\.\\", MAX_DEVICE_PROP, &cchHeader);
hr = StringCbLengthA("\\\\.\\", MAX_DEVICE_PROP, &cchHeader);
if (FAILED(hr))
{
goto EnumerateHubError;
@ -738,12 +739,12 @@ EnumerateHub (
// Create the full hub device name
//
hr = StringCchCopyN(deviceName, cchFullHubName, "\\\\.\\", cchHeader);
hr = StringCchCopyNA(deviceName, cchFullHubName, "\\\\.\\", cchHeader);
if (FAILED(hr))
{
goto EnumerateHubError;
}
hr = StringCchCatN(deviceName, cchFullHubName, HubName, cbHubName);
hr = StringCchCatNA(deviceName, cchFullHubName, HubName, cbHubName);
if (FAILED(hr))
{
goto EnumerateHubError;
@ -751,7 +752,7 @@ EnumerateHub (
// Try to hub the open device
//
hHubDevice = CreateFile(deviceName,
hHubDevice = CreateFileA(deviceName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
@ -849,11 +850,11 @@ EnumerateHub (
dwSizeOfLeafName = sizeof(leafName);
if (ConnectionInfo)
{
StringCchPrintf(leafName, dwSizeOfLeafName, "[Port%d] ", ConnectionInfo->ConnectionIndex);
StringCchCat(leafName,
StringCchPrintfA(leafName, dwSizeOfLeafName, "[Port%d] ", ConnectionInfo->ConnectionIndex);
StringCchCatA(leafName,
dwSizeOfLeafName,
ConnectionStatuses[ConnectionInfo->ConnectionStatus]);
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName,
" : ",
sizeof(" : "));
@ -862,10 +863,10 @@ EnumerateHub (
if (DevProps)
{
size_t cbDeviceDesc = 0;
hr = StringCbLength(DevProps->DeviceDesc, MAX_DRIVER_KEY_NAME, &cbDeviceDesc);
hr = StringCbLengthA(DevProps->DeviceDesc, MAX_DRIVER_KEY_NAME, &cbDeviceDesc);
if(SUCCEEDED(hr))
{
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName,
DevProps->DeviceDesc,
cbDeviceDesc);
@ -876,7 +877,7 @@ EnumerateHub (
if(ConnectionInfo != NULL)
{
// External hub
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName,
HubName,
cbHubName);
@ -884,7 +885,7 @@ EnumerateHub (
else
{
// Root hub
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName,
"RootHub",
sizeof("RootHub"));
@ -1262,7 +1263,7 @@ EnumerateHubPorts (
{
size_t cbDriverName = 0;
hr = StringCbLength(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
hr = StringCbLengthA(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
if (SUCCEEDED(hr))
{
DevProps = DriverNameToDeviceProperties(driverKeyName, cbDriverName);
@ -1325,7 +1326,7 @@ EnumerateHubPorts (
extHubName = GetExternalHubName(hHubDevice, index);
if (extHubName != NULL)
{
hr = StringCbLength(extHubName, MAX_DRIVER_KEY_NAME, &cbHubName);
hr = StringCbLengthA(extHubName, MAX_DRIVER_KEY_NAME, &cbHubName);
if (SUCCEEDED(hr))
{
EnumerateHub(hTreeParent, //hPortItem,
@ -1383,10 +1384,10 @@ EnumerateHubPorts (
info->UsbDeviceProperties = DevProps;
info->DeviceInfoNode = pNode;
StringCchPrintf(leafName, sizeof(leafName), "[Port%d] ", index);
StringCchPrintfA(leafName, sizeof(leafName), "[Port%d] ", index);
// Add error description if ConnectionStatus is other than NoDeviceConnected / DeviceConnected
StringCchCat(leafName,
StringCchCatA(leafName,
sizeof(leafName),
ConnectionStatuses[connectionInfoEx->ConnectionStatus]);
@ -1394,17 +1395,17 @@ EnumerateHubPorts (
{
size_t cchDeviceDesc = 0;
hr = StringCbLength(DevProps->DeviceDesc, MAX_DEVICE_PROP, &cchDeviceDesc);
hr = StringCbLengthA(DevProps->DeviceDesc, MAX_DEVICE_PROP, &cchDeviceDesc);
if (FAILED(hr))
{
OOPS();
}
dwSizeOfLeafName = sizeof(leafName);
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName - 1,
" : ",
sizeof(" : "));
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName - 1,
DevProps->DeviceDesc,
cchDeviceDesc );
@ -3593,7 +3594,7 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
{
size_t cbDriverName = 0;
hr = StringCbLength(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
hr = StringCbLengthA(driverKeyName, MAX_DRIVER_KEY_NAME, &cbDriverName);
if (SUCCEEDED(hr))
{
DevProps = DriverNameToDeviceProperties(driverKeyName, cbDriverName);
@ -3715,10 +3716,10 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
info->UsbDeviceProperties = DevProps;
info->DeviceInfoNode = pNode;
StringCchPrintf(leafName, sizeof(leafName), "[Port%d] ", index);
StringCchPrintfA(leafName, sizeof(leafName), "[Port%d] ", index);
// Add error description if ConnectionStatus is other than NoDeviceConnected / DeviceConnected
StringCchCat(leafName,
StringCchCatA(leafName,
sizeof(leafName),
ConnectionStatuses[connectionInfoEx->ConnectionStatus]);
@ -3726,17 +3727,17 @@ enumerate_hub_port(HANDLE hHubDevice, ULONG port_index)
{
size_t cchDeviceDesc = 0;
hr = StringCbLength(DevProps->DeviceDesc, MAX_DEVICE_PROP, &cchDeviceDesc);
hr = StringCbLengthA(DevProps->DeviceDesc, MAX_DEVICE_PROP, &cchDeviceDesc);
if (FAILED(hr))
{
OOPS();
}
dwSizeOfLeafName = sizeof(leafName);
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName - 1,
" : ",
sizeof(" : "));
StringCchCatN(leafName,
StringCchCatNA(leafName,
dwSizeOfLeafName - 1,
DevProps->DeviceDesc,
cchDeviceDesc);

View File

@ -881,7 +881,7 @@ usb_monitor::usb_monitor() : wnd_monitor_(NULL), handle_msg_id_(0), run_(true)
thread_handle_device_change_msg();
};
void(usb_monitor:: * pnp)(void) = &usb_monitor::thread_handle_device_change_msg;
handle_msg_.start(tf, "usb_monitor::thread_handle_device_change_msg", *(void**)&pnp);
handle_msg_.start(tf, 0, "usb_monitor::thread_handle_device_change_msg", *(void**)&pnp);
#else
handle_msg_.reset(new std::thread(&usb_monitor::thread_handle_device_change_msg, this));
#endif

View File

@ -977,6 +977,7 @@ void CDlgScanner::thread_fetch_image(void)
while (1)
{
SANE_Parameters sp;
bool bmp = false;
memset(&sp, 0, sizeof(sp));
scanner_->get_image_info(&sp);
@ -993,9 +994,17 @@ void CDlgScanner::thread_fetch_image(void)
wchar_t name[40] = { 0 };
FILE *dst = nullptr;
swprintf_s(name, _countof(name) - 1, L"\\scanner_%04u.bmp", img_cnt_ + 1);
if(sp.format == (SANE_Frame)SANE_FRAME_PNG)
swprintf_s(name, _countof(name) - 1, L"\\scanner_%04u.png", img_cnt_ + 1);
else if (sp.format == (SANE_Frame)SANE_FRAME_JPEG)
swprintf_s(name, _countof(name) - 1, L"\\scanner_%04u.jpg", img_cnt_ + 1);
else
{
swprintf_s(name, _countof(name) - 1, L"\\scanner_%04u.bmp", img_cnt_ + 1);
bmp = true;
}
dst = _wfopen((save_root_ + name).c_str(), L"wb");
if (dst)
if (dst && bmp)
{
fwrite(bfh.c_str(), 1, bfh.length(), dst);
fwrite(bih.c_str(), 1, bih.length(), dst);
@ -1004,7 +1013,7 @@ void CDlgScanner::thread_fetch_image(void)
{
if (dst)
{
if (line_l == sp.bytes_per_line)
if (!bmp || line_l == sp.bytes_per_line)
{
fwrite(buf, 1, rd, dst);
}
@ -1511,7 +1520,7 @@ void CDlgScanner::OnBnClickedButtonScan()
thread_fetch_image();
};
threads_.start(rcv, "thread_fetch_image");
threads_.start(rcv, 0, "thread_fetch_image");
utils::to_log(LOG_LEVEL_DEBUG, "Device configuration: %s\n", cfg.c_str());
::SetDlgItemTextW(m_hWnd, IDC_BUTTON_SCAN, L"Stop");
OnDeviceStatus(0, (LPARAM)SCANNER_ERR_DEVICE_BUSY);
@ -1548,7 +1557,7 @@ void CDlgScanner::OnBnClickedButtonSendFile()
{
thread_auto_tx_file();
};
auto_tx_file_ = threads_.start(txf, "CDlgScanner::thread_auto_tx_file", NULL);
auto_tx_file_ = threads_.start(txf, 0, "CDlgScanner::thread_auto_tx_file", NULL);
//char l[256] = { 0 },
// r[256] = { 0 };
//int err = 0;
@ -1570,7 +1579,7 @@ void CDlgScanner::OnBnClickedButtonRecvFile()
{
thread_auto_tx_file();
};
auto_tx_file_ = threads_.start(txf, "CDlgScanner::thread_auto_tx_file", NULL);
auto_tx_file_ = threads_.start(txf, 0, "CDlgScanner::thread_auto_tx_file", NULL);
//char l[256] = { 0 },
// r[256] = { 0 };
//int err = 0;
@ -1657,7 +1666,7 @@ void CDlgScanner::OnBnClickedCheckRepeat()
thread_auto_tx_file();
};
auto_tx_ = FILE_TX_RECEIVE | FILE_TX_SEND;
auto_tx_file_ = threads_.start(txf, "CDlgScanner::thread_auto_tx_file", NULL);
auto_tx_file_ = threads_.start(txf, 0, "CDlgScanner::thread_auto_tx_file", NULL);
}
else
{

View File

@ -82,29 +82,31 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\..\code_device\sdk</IncludePath>
<LibraryPath>$(SolutionDir)sdk\lib\$(Configuration);$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)sdk\lib\$(Configuration);$(LibraryPath);$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\..\code_device\sdk;$(ProjectDir)..\sdk\include;$(ProjectDir)..\..\..\sdk\include;$(ProjectDir)..\..\device;$(ProjectDir)..\..\..\code_device\hgdriver\3rdparty\opencv\include;$(ProjectDir)..\..\..\code_device\hgsane\sane_opt;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)..\sdk\lib\$(Configuration);$(LibraryPath)</LibraryPath>
<LibraryPath>$(ProjectDir)..\sdk\lib\$(Configuration);$(LibraryPath);$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)..\..\..\code_device\sdk</IncludePath>
<LibraryPath>$(SolutionDir)sdk\lib\$(Configuration);$(LibraryPath)</LibraryPath>
<LibraryPath>$(SolutionDir)sdk\lib\$(Configuration);$(LibraryPath);$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_WINDOWS;HGSCANNER_EXPORT;PRODUCT_VENDOR="HuaGo";TEST_HGSCANNER;HGSCANNER_EXPORT;PRODUCT_VENDOR="HuaGo";_DEBUG;%(PreprocessorDefinitions);CUSTOM_USBVIEW</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;HGSCANNER_EXPORT;PRODUCT_VENDOR="HuaGo";TEST_HGSCANNER;_DEBUG;%(PreprocessorDefinitions);CUSTOM_USBVIEW</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@ -128,6 +130,7 @@
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>opencv_core3416.lib;opencv_imgproc3416.lib;opencv_imgcodecs3416.lib;IlmImf.lib;ittnotify.lib;libjasper.lib;libjpeg-turbo.lib;libpng.lib;libtiff.lib;libwebp.lib;zlib.lib;user32.lib;cryptlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@ -156,6 +159,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opencv_core3416.lib;opencv_imgproc3416.lib;opencv_imgcodecs3416.lib;IlmImf.lib;ittnotify.lib;libjasper.lib;libjpeg-turbo.lib;libpng.lib;libtiff.lib;libwebp.lib;zlib.lib;user32.lib;cryptlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@ -183,6 +187,7 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opencv_core3416.lib;opencv_imgproc3416.lib;opencv_imgcodecs3416.lib;IlmImf.lib;ittnotify.lib;libjasper.lib;libjpeg-turbo.lib;libpng.lib;libtiff.lib;libwebp.lib;zlib.lib;user32.lib;cryptlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
@ -216,6 +221,13 @@
<ClInclude Include="..\..\..\code_device\sdk\sane_opt_json\base_opt.h" />
<ClInclude Include="..\..\..\code_device\sdk\sane_opt_json\device_opt.h" />
<ClInclude Include="..\..\..\code_device\sdk\sane_opt_json\simple_logic.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sane.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sanei.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sanei_backend.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sanei_debug.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sane_ex.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sane_name.h" />
<ClInclude Include="..\..\..\sdk\include\sane\sane_option_definitions.h" />
<ClInclude Include="..\..\device\win_usb\usbview\enum.h" />
<ClInclude Include="..\..\device\win_usb\usbview\usbdesc.h" />
<ClInclude Include="..\..\device\win_usb\usbview\uvcdesc.h" />

View File

@ -138,6 +138,27 @@
<ClInclude Include="..\..\..\code_device\sdk\base\words.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sane.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sane_ex.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sane_name.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sane_option_definitions.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sanei.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sanei_backend.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\..\sdk\include\sane\sanei_debug.h">
<Filter>Imports\sdk</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="usb_tools.cpp">