0

I found some sample code for device manager information, I try to write on txt file but there will stop working.

I don't know what is the root cause for this problem.

below link is the original sample code. http://white5168.blogspot.com/2013/05/drivercmgetdevnodestatus.html#.W1FLpdIzaM9

below code is where I added. Please help to check.

                while (!SetupDiGetDeviceRegistryProperty(hDevInfo,
                    &DeviceInfoData,
                    ucSPDRP[j],
                    &DataType,
                    (PBYTE)Buffer,
                    BufferSize,
                    &BufferSize)) {
                    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
                    {
                        // Change the buffer size.
                        if (Buffer) LocalFree(Buffer);
                        Buffer = (LPSTR)LocalAlloc(LPTR, BufferSize * 2);
                    }
                    else
                        break;// Insert error handling here.
                }


                    file << cStatus[j];
                    file << (const char *)Buffer << "\n";
                    file.flush();

                }
                printf("%s : %s\n", cStatus[j], (const char *)Buffer);
                if (Buffer) LocalFree(Buffer);

0 Answers0