小编Jar*_*ran的帖子

在C#中枚举Windows便携设备

我试图使用Windows Portable Devices API和此API提供的PortableDeviceManager在Windows上枚举连接的便携式设备.

我已经在MSDN文档链接和各种博客链接之后实现了设备ID的枚举,但它们都导致了同样的问题 - 我只能在有几个连接的时候给我一个设备的ID .

这是我正在使用的C#代码片段:

PortableDeviceManagerClass deviceManager = new PortableDeviceManagerClass();
deviceManager.RefreshDeviceList();  

uint numberOfDevices = 1;            
deviceManager.GetDevices(null, ref numberOfDevices);

if (numberOfDevices == 0)
{
    return new string[0];
}

string [] deviceIds = new string[numberOfDevices];
deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices);

return deviceIds;
Run Code Online (Sandbox Code Playgroud)

我有两台设备连接到我的电脑,一台可拆卸USB记忆棒和一台数码相机.当两者都处于活动状态时,将仅返回我的相机的设备ID.当我关闭相机时,将返回可移动USB记忆棒的设备ID.

是否有任何有此API经验的人可以指出我做错的方向?

.net c# wpd

13
推荐指数
1
解决办法
2万
查看次数

Pebble应用程序中的静态与非静态功能

刚刚开始为Pebble应用程序开发 - 并且还回到我已经多年未维护的基本C技能,我试图了解这些Pebble应用程序的基本结构.

我确实知道静态和非静态之间的区别,但是如果有人能帮助解释在这种情况下对我的应用程序的影响,那将非常高兴.我在下面粘贴了最小化的示例代码,其中显示了Pebble应用程序在两种情况下的结构.

静态版

#include <pebble.h>

static Window *window;

static void handle_init(void) {
    window = window_create();
    window_stack_push(window, true);

}

static void handle_deinit(void) {
    window_destroy(window);
}

int main(void) {
    handle_init();
    app_event_loop();
    handle_deinit();
}
Run Code Online (Sandbox Code Playgroud)

非静态版本

#include <pebble.h>

Window *window;

void handle_init(void) {
    window = window_create();
    window_stack_push(window, true);

}

void handle_deinit(void) {
    window_destroy(window);
}

int main(void) {
    handle_init();
    app_event_loop();
    handle_deinit();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

使用非静态变量和静态变量和函数的含义是什么?

我试图在Pebble开发者网站上找到信息,但静态和非静态的例子似乎没有太多的一致性使用,我找不到一个好的官方指南.

c pebble-watch

3
推荐指数
1
解决办法
336
查看次数

标签 统计

.net ×1

c ×1

c# ×1

pebble-watch ×1

wpd ×1