我正在尝试编写与以下内容等效的C#:
typedef struct BATT_ID
{
UINT8 nBattID[8];
} BATT_ID, *PBATT_ID;
HANDLE g_hDevice;
// Connect to the driver
g_hDevice = CreateFile(L"BAT1:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
void GetBattID(PBATT_ID pBattId)
{
// ... snipped code to check g_hDevice is valid ...
DeviceIoControl(g_hDevice, SOMO650_PWR_GET_BATT_ID, NULL, 0, pBattId, sizeof(BATT_ID), dwByteReturn, NULL))
}
// once BATT_ID has been filled it can be formatted as follows
wsprintf(strInfo, TEXT("%02X:%02X:%02X:%02X:%02X:%02X"), BattID.nBattID[6], BattID.nBattID[5], BattID.nBattID[4], BattID.nBattID[3], BattID.nBattID[2], BattID.nBattID[1]);
Run Code Online (Sandbox Code Playgroud)
代码连接到Windows Mobile设备的电源驱动程序并尝试检索电池ID.
这是针对SoMo650和Socket的最新ROM版本,只能在C中提供示例代码.
除了调用DeviceIoControl,我可以成功地完成所有事情(尽我所知),因为我不知道如何将BATT_ID结构转换为C#.
我猜这是因为它是一个结构,而DeviceIoControl期望一个指针我应该看着Marshal.PtrToStructure(),但我的C经验非常少,感觉非常深刻.
任何协助将不胜感激.
我是Windows Phone 7的新手.我正在编写一个示例游戏,我想随机移动Image.
在与我的一位朋友讨论时,他告诉我要使用Bezier路径.我在网上搜索了解Bezier路径概念.看起来它适合我的解决方案.但我没有找到任何可以执行此操作的示例代码.
请帮我找样品.
在被指示之后:http: //msdn.microsoft.com/en-us/library/microsoft.phone.info.userextendedproperties.getvalue%28v=VS.92%29.aspx
我在我的sideloaded应用程序上尝试了以下代码.所有写出的都是000001值.
我知道在模拟器中会出现这种情况,但我希望能在手机上获得真正的价值.有任何想法吗?
int ANIDLength = 32;
int ANIDOffset = 2;
string result = string.Empty;
object anid;
if (UserExtendedProperties.TryGetValue("ANID", out anid))
{
if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
{
result = anid.ToString().Substring(ANIDOffset, ANIDLength);
}
else
{
result = "000001";
}
}
Run Code Online (Sandbox Code Playgroud) 如何将相同的文本发送到Wp7中的多个联系人?我将所有联系人移动到列表中.如果用户在循环中发送过程中意外按回键按钮,会出现任何问题吗?
SmsComposeTask sms = new SmsComposeTask();
sms.To = "0123456789";
sms.Body = "Some prefilled text...";
sms.Show();
Run Code Online (Sandbox Code Playgroud)
谢谢
我在引发事件的 Windows 运行时组件(用 C# 编写)中有一个类。
我无法弄清楚如何在引用该组件的 C++/CX 应用程序中订阅这些事件。
C# 代码(在 Windows 运行时组件中):
public sealed class Messenger {
private EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>> messageReceivedTokenTable;
public event EventHandler<MessageReceivedEventArgs> MessageReceived
{
add
{
return EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.AddEventHandler(value);
}
remove
{
EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.RemoveEventHandler(value);
}
}
internal void OnMessageReceived(string message, string location)
{
EventHandler<MessageReceivedEventArgs> temp =
EventRegistrationTokenTable<EventHandler<MessageReceivedEventArgs>>
.GetOrCreateEventRegistrationTokenTable(ref this.messageReceivedTokenTable)
.InvocationList;
temp(this, new MessageReceivedEventArgs(message, location));
}
}
Run Code Online (Sandbox Code Playgroud)
MessageReceivedEventArgs 是:
public sealed class MessageReceivedEventArgs : object
{
public MessageReceivedEventArgs(string message, string location)
{
this.Message = message;
this.SenderLocation …Run Code Online (Sandbox Code Playgroud) 我想将像"19.11.2009 14:00"这样的日期字符串转换为现在的年龄,如"2分钟"或"1周"或"2天"
是否有一些代码?
我正在使用适用于 Windows Phone 的 Visual Studio 2010 Express。我已经使用它几个月了,没有任何问题。大约一周前,当我关闭 Visual Studio 时,它停止保存我打开的选项卡。下次打开该解决方案时,它不会自动打开我上次关闭该解决方案时打开的文件。我不确定它为什么停止工作,而且我找不到控制它的设置。还有其他人遇到过这个吗?如果是这样,您如何让它再次记住您打开的选项卡?
我有这个问题.我无法退出MainPage中的应用程序.
我开始从MainPage导航 - >第2页--->第3页.
在Page3中,我使用navigationService转到MainPage.有人可以帮我吗?
另外,我对这个术语e.cancel = true或false在重写BackKeyPress事件时感到困惑.
1.)e.Cancel = true表示取消后退?或者取消什么?2)e.cancel = false ,?
3)我是否需要在MainPage中覆盖backKey按?
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
try
{
base.OnBackKeyPress(e);
if (NavigationService.CanGoBack)
{
e.Cancel = true; // yes cancel the default behavior ??
NavigationService.GoBack();
}
}
catch (Exception ex)
{
// MessageBox.Show("Error : " + ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
3)针对此探针的任何解决方案?
谢谢
我正在使用C#.net.
我有两个文本框(textbox1/textbox2).如果两者都为空,则需要显示错误消息.
我尝试了一个CustomValidator控件并让它在textbox2上进行验证.在我的代码后面,我检查两者是否为空,如果是这样,它返回false(args = false).但是,当我构建应用程序时,它甚至没有访问按钮事件.我可以不用吗?
这是我尝试过的:
<asp:CustomValidator ID="customValidator" runat="server"
ErrorMessage="You must provide either a phone number or email address."
ControlToValidate="textbox2"
OnServerValidate="PhoneEmailCustomValidator_ServerValidate" />
protected void PhoneEmailCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (string.IsNullOrEmpty(texbox1.Text) && string.IsNullOrEmpty(textbox2.Text))
{
Debug.Write("Within if statement");
args.IsValid = false;
}
}
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
克莱尔
我想用bitly来缩短我的url,但是当我想在我的文本块中设置字符串时会发生异常
private void button1_Click(object sender, RoutedEventArgs e)
{
ShortenUrl(textBox1.Text);
}
enum Format
{
XML,
JSON,
TXT
}
enum Domain
{
BITLY,
JMP
}
void ShortenUrl(string longURL)
{
Format format = Format.XML;
Domain domain = Domain.BITLY;
string _domain;
//string output;
// Build the domain string depending on the selected domain type
if (domain == Domain.BITLY)
_domain = "bit.ly";
else
_domain = "j.mp";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
string.Format(@"http://api.bit.ly/v3/shorten?login={0}&apiKey={1}&longUrl={2}&format={3}&domain={4}",
"username", "appkey", HttpUtility.UrlEncode(longURL), format.ToString().ToLower(), _domain));
request.BeginGetResponse(new AsyncCallback(GetResponse), request);
}
void GetResponse(IAsyncResult result)
{
XDocument …Run Code Online (Sandbox Code Playgroud) c# ×2
asp.net ×1
c++ ×1
datetime ×1
marshalling ×1
php ×1
pinvoke ×1
validation ×1
windows-8 ×1
xna ×1