사용 RAPI. Rapi.dll 및 ActiveSync에 대해 관리되는 래퍼 클래스를 제공하는 코드 플렉스 프로젝트입니다. 그것은 데스크톱 .NET 애플 리케이션이 속박 된 모바일 장치와 통신 할 수 있습니다. 래퍼는 OpenNetCF project에서 시작되었지만 이제 별도로 관리됩니다.
해당 프로젝트에서 제공되는 전체 RAPI 프로젝트 DLL을 사용하거나 필요한 코드의 서브 세트 만 사용할 수 있습니다. 연결되었을 때 장치에 파일을 만들 필요가있어서 성능 통계 항목이나 Rapi에 포함 된 장치 레지스트리 항목이 필요하지 않았습니다.
private DccMan DeviceConnectionMgr;
private int AdviceCode;
private int ConnectionStatus = 1;
private System.Threading.AutoResetEvent DeviceConnectionNotification = new System.Threading.AutoResetEvent(false);
public void OnConnectionError()
{
ConnectionStatus = -1;
DeviceConnectionNotification.Set();
}
public void OnIpAssigned(int address)
{
ConnectionStatus = 0;
DeviceConnectionNotification.Set();
}
private void btnCopyToDevice_Click(object sender, EventArgs e)
{
// copy the database (in the form of an XML file) to the connected device
Cursor.Current = Cursors.WaitCursor;
// register for events and wait.
this.DeviceConnectionMgr = new DccMan();
DccManSink deviceEvents = new DccManSink();
deviceEvents.IPChange += new IPAddrHandler(this.OnIpAssigned);
deviceEvents.Error += new ErrorHandler(this.OnConnectionError);
((IDccMan)DeviceConnectionMgr).Advise(deviceEvents, out this.AdviceCode);
// should do this asynchronously, with a timeout; too lazy.
this.statusLabel.Text = "Waiting for a Windows Mobile device to connect....";
this.Update();
Application.DoEvents(); // allow the form to update
bool exitSynchContextBeforeWait = false;
DeviceConnectionNotification.WaitOne(SECONDS_TO_WAIT_FOR_DEVICE * 1000, exitSynchContextBeforeWait);
if (ConnectionStatus == 0)
{
this.statusLabel.Text = "The Device is now connected.";
this.Update();
Application.DoEvents(); // allow the form to update
RAPI deviceConnection = new RAPI();
deviceConnection.Connect(true, 120); // wait up to 2 minutes until connected
if (deviceConnection.Connected)
{
this.statusLabel.Text = "Copying the database file to the connected Windows Mobile device.";
this.Update();
Application.DoEvents(); // allow the form to update
string destPath = "\\Storage Card\\Application Data\\MyApp\\db.xml";
deviceConnection.CopyFileToDevice(sourceFile,
destPath,
true);
this.statusLabel.Text = "Successfully copied the file to the Windows Mobile device....";
}
else
{
this.statusLabel.Text = "Oh, wait, it seems the Windows Mobile device isn't really connected? Sorry.";
}
}
else
{
this.statusLabel.Text = "Could not copy the file because the Device does not seem to be connected.";
}
Cursor.Current = Cursors.Default;
}
내가 필요 정확히 같은 소리! 그러나 아직 테스트 할 수 없습니다. 필자는 PDA에서 특정 디렉토리에있는 파일 만 가져올 필요가 있기 때문에 작동하는 것 같습니다. –
이 작품을 만드는 데 문제가 있습니다. 어떤 종류의 프로젝트를 사용하고 있습니까? 내가 알아야 할 코드에없는 것 ...? 저는 특히 DCCMan 또는 AdviceCode 유형의 것을 만들 수 없습니다. 감사합니다. . –
Whadaya mean? "타입의 무엇이라도 만들어라. ..". codeplex.com의 RAPI 프로젝트 코드가 필요합니다. 그거 맞지? DccManSink 및 RAPI와 같은 클래스는 해당 코드에서 정의됩니다. AdviceCode는 단지 int입니다. (예, 나는 작업 프로젝트에서이 코드를 발췌 할 때 실수로 그것을 버렸습니다) – Cheeso