I tried to modify the Wiimote Whiteboard app for my final project. but my experience in the programming language C # is very little. in fact I learn C # just a few months.
I do not know what is the meaning of lines of code below. can anyone help me? I've written a few comments to the parts that I do not understand in this code. Please guided me in understanding it. I guess this code to connect the Wiimote device.
private void Connect(bool DisconnectOld)
{
//TODO: honour disconnectold parameter
BLUETOOTH_DEVICE_INFO device = new BLUETOOTH_DEVICE_INFO();
device.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO));
device.szName = "";
//whether the 9 lines of code below to create a parameter to search the bluetooth device?
BLUETOOTH_DEVICE_SEARCH_PARAMS searchparams = new BLUETOOTH_DEVICE_SEARCH_PARAMS();
//what the purpose of one line of code below?
searchparams.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_SEARCH_PARAMS));
searchparams.fIssueInquiry = true;
searchparams.fReturnAuthenticated = true;
searchparams.fReturnConnected = true;
searchparams.fReturnRemembered = true;
searchparams.fReturnUnknown = true;
searchparams.hRadio = IntPtr.Zero;
searchparams.cTimeoutMultiplier = 1;
bool connected = false;
//what the purpose of one line of code below?
IntPtr handle = BluetoothFindFirstDevice(ref searchparams, ref device);
//what the meaning of what IntPtr.Zero?
if (handle == IntPtr.Zero)
{
int lasterror = Marshal.GetLastWin32Error();
if (lasterror != 0)
LogError("Bluetooth API returned: " + lasterror.ToString());
}
else
{
while (true)
{
if (Cancel)
break;
if (device.szName.StartsWith("Nintendo RVL"))
{
//whether the function "if" below state that the device once connected?
if (device.fRemembered)
{
BluetoothRemoveDevice(ref device.Address);
}
else
{
//what the purpose line of code below?
if (BluetoothSetServiceState(IntPtr.Zero, ref device, ref HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE) != 0)
LogError("Failed to connect to wiimote controller");
else
connected = true;
}
break;
}
//why the divice.szName set to null again?
device.szName = "";
if (!BluetoothFindNextDevice(handle, ref device))
break;
}
}
//what the purpose of line of code below?
BluetoothFindDeviceClose(handle);
if (connected && Connected != null)
Connected(this, EventArgs.Empty);
else if (ConnectionFailed != null)
ConnectionFailed(this, EventArgs.Empty);
}
i'am sorry that my english is very week.