Ok I found what my mistake was, problem was that I forgot to place the CharSet, property to auto when I created the struct.
I had:
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
public UInt32 cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DevicePath;
}
When It should have been
[StructLayout(LayoutKind.Sequential), CharSet = CharSet.Auto]
public struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
public UInt32 cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DevicePath;
}
Hope this can help someone in the future.