namllat

As most of the devices in the market, there is a "IRDA" option in "File"->"Send to" to do the file transmission via IRDA. Here is two questions:

  1. How to add the "IRDA" option in the menu bar in source code
  2. How to do the file transmission via IRDA any sample code

Thanks for replies~~~~~~~~~~~~~~~~~~~~~~~~~~~




Re: Smart Devices General IRDA send file option in Menu bar

Christopher Fairbairn

Hi,

If you want to use IRDA natively (in C++ etc) then you should look at the Winsock documentation. IRDA is exposed as a different class of socket so typically uses the standard socket APIs.

If you want to use IRDA within the Compact Framework you should look at the following resources:

If this doesn't implement what you need you could also take a look at third party libraries such as Peter Foot's 32Feet package available from http://32feet.net/.

Hope this helps,

Christopher Fairbairn






Re: Smart Devices General IRDA send file option in Menu bar

namllat

Thanks for your information, those links are helpful!!!!

One minor problem, to add a column in the folder menu bar, I try to edit the .rc file in \WINCE500\public\shell\oak\hpc\ceshell\ui. It seems that it doesnt take any effect even I the option name, like "Properties" to "Test". I am wondering whether I can edit those words or not.

BEGIN
MENUITEM "Open", IDC_FILE_OPEN // USER_INSERT_OFFSET-1
MENUITEM SEPARATOR
MENUITEM "Cut", IDC_EDIT_CUT
MENUITEM "Copy", IDC_EDIT_COPY
MENUITEM SEPARATOR
MENUITEM "Delete", IDC_FILE_DELETE
MENUITEM "Rename", IDC_FILE_RENAME
MENUITEM SEPARATOR
MENUITEM "Test", IDC_FILE_PROPERTIES original==>"Properties"
END






Re: Smart Devices General IRDA send file option in Menu bar

namllat

sorry...i have solved the problem!! Thank you very much!!!!!




Re: Smart Devices General IRDA send file option in Menu bar

namllat

To Christopher,

Sorry, I still have no clude how to make the file transmission via IRDA after reading the linking. Also, there is slightly difference from what I want.

I am developing a wince5.0. I need to implement a button "send to IRDA" in the menu bar. That is, once I select the file and click the button, the file is beamed to the device nearby via IRDA. A window box is poped up in the receipt side and ask whether accept or not. Then the file is transmitted if "accept" is chosen.

My device can detect other device's beam and receive files successfully, but can't originate. Is there any .c or .cpp sample code for doing so

Thank you very much!!






Re: Smart Devices General IRDA send file option in Menu bar

Christopher Fairbairn

Hi,

Sorry about that. The protocol you are mentioning is called OBEX. It is a higher level protocol which sits on top of the basic IRDA sockets layer I mentioned in previous replies.

Here is some articles and documentation to get you started:

More technical references of Microsoft's OBEX stack.

That first reference includes sample code to implment the OBEX protocol on top of the raw IRDA sockets layer provided by the OS.

The second and third references demonstrates how to use the built in OBEX implementation provided by the OS. This has the advantage that as well as IRDA, it will work over bluetooth connections as well.

Hope this helps,

Christopher Fairbairn






Re: Smart Devices General IRDA send file option in Menu bar

Zero Dai - MSFT

Hi namllat,

I'm not sure if this can help for your application. But, as far as the most topics in our forum, if your want to beam a file, you can use beam.exe directly. That's use CreateProcess to startup beam.exe, and transfer the file name as the parameter. I think, you can achieve it easily in this way.

You may want to read: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1427682&SiteID=1

Hope this can give you some idea,

Zero Dai - MSFT






Re: Smart Devices General IRDA send file option in Menu bar

namllat

To Zero:

But is the beam.exe already in the platform builder I just want to find it myself and read many forum. And it seems that it is common to everyone, but I cant find where it is! Would you please give me the information

Millions Thanks~

Thank you Christopher Too!!!






Re: Smart Devices General IRDA send file option in Menu bar

Christopher Fairbairn

Hi,

beam.exe should be found within the \Windows directory of your device (on older devices it may be named irsquirt.exe).

Having said that I bieleve it is probably a Windows Mobile only feature when it appears you are wanting a solution which works on Windows CE.

Have you tried working through the article available at http://www.developer.com/ws/article.php/10927_3573636_1

Within your platform builder installation have a look at the following folder - C:\WINCE500\PUBLIC\SERVERS\SDK\SAMPLES\OBEX. This folder should contain some interesting things for you. Mainly the subfolder "Contacts" which includes source code for a sample plugin to Pocket Outlook which allows beaming of contacts, and the subfolder "ObexFTP" which should contain something fairly close to what you want within a function called SendFile.

Hope it helps,

Christopher Fairbairn






Re: Smart Devices General IRDA send file option in Menu bar

namllat

Dear Christopher,

It seems that there is really no beam.exe nor irsquirt.exe in WCE5.0. I am now trying to make use of the FileBrowser.cpp in OBEXTOOL to do the Initialization, choosing connection point....Shut down etc (the procedure as what the link mention).

hr = m_pObex->EnumDevices(&pDeviceEnum, CLSID_IrdaTransport); ==> to enable IRDA communication only

Is the way I proposed to do correct

Since it is my first time to do wireless communication stuff, many questions are raised. Sorry for keep asking and Thank you very much!







Re: Smart Devices General IRDA send file option in Menu bar

namllat

Here is the code I wrote to do the IRDA File Exchange. I tried my best to follow this to implememnt. However, I encountered some problem.

  1. The Function CoInitialize doesnt return and cant move forward to run the code.
  2. I dont understand what means by create collection of headers and how to add the file I want to send to the pHeaderCollection.

#include <obex.h>


IObexDevice *g_pObexDevice = 0;
IObex *g_pObex = 0;
IStream *myStream = 0;
IHeaderCollection *pHeaderCollection = 0;
IDeviceEnum *pDeviceEnum = 0;

//initialize COM
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);


hr = CoCreateInstance(CLSID_Obex, NULL, CLSCTX_INPROC_SERVER, IID_IObex, (void **)&g_pObex);

if((FAILED(hr)) || (!g_pObex) || (FAILED( g_pObex->Initialize())))
{
RETAILMSG(DEBUGGER, (TEXT("Error getting IObex object")));
CoUninitialize();
break;
}
// Enable IRDA connection only
hr = g_pObex->EnumDevices(&pDeviceEnum, CLSID_IrdaTransport);

// Build the collection of headers
hr = CoCreateInstance(CLSID_HeaderCollection, NULL, CLSCTX_INPROC_SERVER, IID_IHeaderCollection, (void **)&pHeaderCollection);

ASSERT(pHeaderCollection && g_pObexDevice);

if(SUCCEEDED(hr)){
hr = g_pObexDevice->Connect(NULL,0,pHeaderCollection);
}

/////////////////////////////////////////////////
////How to put the file i want to send to collection header

////////////////////////////////////////////////

if(SUCCEEDED(hr))
hr = g_pObexDevice->Put(pHeaderCollection, &myStream);

if(myStream)
myStream->Release();


if(SUCCEEDED(hr))
hr = g_pObexDevice->Disconnect(pHeaderCollection);

if(SUCCEEDED(hr))
hr = g_pObex->Shutdown();

Thank you very much~~~~~~~~~







Re: Smart Devices General IRDA send file option in Menu bar

Christopher Fairbairn

Hi,

I am not aware of reasons why CoInitializeEx would block forever.

Try the following example which I have tested on both Windows Mobile 5.0 Pocket PC and Smartphone platforms on real devices. This is based upon the ObexFTP example I mentioned in a previous posting which is available with Platform Builder.

Sorry about the word wrapping... hopefully the source code will survive posting onto the forumn reasonably ok...

Code Snippet

//

// Copyright (c) Microsoft Corporation. All rights reserved.

//

//

// Use of this source code is subject to the terms of the Microsoft end-user

// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.

// If you did not accept the terms of the EULA, you are not authorized to use

// this source code. For a copy of the EULA, please see the LICENSE.RTF on your

// install media.

//

#include <windows.h>

#include <stdio.h>

#include <obex.h>

#define OBFTP_MAX_STRING 256

#define OBEX_TYPE_UNICODE 0x00

#define OBEX_TYPE_BYTESEQ 0x40

#define OBEX_TYPE_BYTE 0x80

#define OBEX_TYPE_DWORD 0xc0

#define OBEX_HID_CONNECTIONID (0x0b | OBEX_TYPE_DWORD)

IObexDevice *FindDevice (IObex *pObex, int deviceIndex) {

IDeviceEnum *pDeviceEnum = 0;

HRESULT hRes = E_FAIL;

if (ERROR_SUCCESS == pObex->StartDeviceEnum())

{

DEBUGMSG(1,(L"[OBEXSTRESSTEST] Device enumeration started\n"));

Sleep(15000);

//enumerate through the devices

pObex->StopDeviceEnum();

DEBUGMSG(1,(L"[OBEXSTRESSTEST] Device enumeration stopped"));

DEBUGMSG(1,(L"[OBEXSTRESSTEST] Enumerating devices...\n"));

hRes = pObex->EnumDevices(&pDeviceEnum, __uuidof(IrdaTransport));

}

if(! (SUCCEEDED(hRes) && pDeviceEnum))

return NULL;

IObexDevice *pDeviceArray[100];

DWORD num = 0;

//release the device (if it exists)

hRes = pDeviceEnum->Next(sizeof(pDeviceArray) / sizeof(pDeviceArray[0]), pDeviceArray, &num);

pDeviceEnum->Release ();

if(! SUCCEEDED(hRes)) {

wprintf (L"No devices found!\n");

return NULL;

}

IPropertyBag *propBag;

for (int i = 0; i < (int)num; i++) {

if (SUCCEEDED(pDeviceArray[i]->EnumProperties (IID_IPropertyBag, (LPVOID *)&propBag))) {

//print the name out

VARIANT v;

VariantInit(&v);

if(SUCCEEDED(propBag->Read(L"Name", &v, NULL)))

wprintf (L"%d. %s\n", i + 1, v.bstrVal);

VariantClear(&v);

propBag->Release();

}

}

wprintf (L"Selecting device %d: ", deviceIndex);

--deviceIndex;

for (int i = 0 ; i < (int)num ; ++i) {

if (i != deviceIndex)

pDeviceArray[i]->Release ();

}

return ((deviceIndex >= 0) && (deviceIndex < (int)num)) pDeviceArray[deviceIndex] : NULL;

}

IObexDevice *DoConnect (IObex *pObex) {

// Hard code this to decide to beam to the first device found

IObexDevice *pObexDevice = FindDevice (pObex, 1);

if (! pObexDevice)

return NULL;

IHeaderCollection *pHeaderCollection = 0;

//get a header collection

HRESULT hr = CoCreateInstance(__uuidof(HeaderCollection), NULL, CLSCTX_INPROC_SERVER,

__uuidof(IHeaderCollection), (void **)&pHeaderCollection);

if (FAILED(hr) || (! pHeaderCollection)) {

wprintf (L"Out of memory...\n");

pObexDevice->Release ();

return NULL;

}

//now, using the object, connect up

hr = pObexDevice->Connect(0,0,pHeaderCollection);

//loop through the headers looking for info

if(SUCCEEDED(hr)) {

IHeaderEnum *pHeaderEnum = 0;

hr = pHeaderCollection->EnumHeaders(&pHeaderEnum);

if(SUCCEEDED(hr)) {

ULONG ulHeadersFetched = 0;

do {

OBEX_HEADER *obHeader;

hr = pHeaderEnum->Next(1, &obHeader, &ulHeadersFetched);

if(SUCCEEDED(hr)) {

if(obHeader->bId == OBEX_HID_CONNECTIONID) {

hr = S_OK;

break;

}

}

} while(SUCCEEDED(hr) && ulHeadersFetched);

pHeaderEnum->Release();

}

}

pHeaderCollection->Release ();

if(FAILED(hr)) {

wprintf (L"Could not connect!\n");

pObexDevice->Release();

return NULL;

}

return pObexDevice;

}

int SendFile(IObexDevice *pObexDevice, WCHAR *pszFileName) {

WCHAR *name = wcsrchr (pszFileName, '\\');

if (! name)

name = pszFileName;

else

++name;

HANDLE hFile = CreateFile (pszFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

if (hFile == INVALID_HANDLE_VALUE) {

wprintf (L"Can't open %s\n", pszFileName);

return FALSE;

}

BY_HANDLE_FILE_INFORMATION fileInfo;

GetFileInformationByHandle(hFile, &fileInfo);

DWORD dwBytesTotal = fileInfo.nFileSizeLow;

DWORD dwBytesSent = 0;

IStream *myStream = 0;

IHeaderCollection *pHeaderCollection = 0;

//get a header collection

HRESULT hr = CoCreateInstance(__uuidof(HeaderCollection), NULL, CLSCTX_INPROC_SERVER,

__uuidof(IHeaderCollection), (void **)&pHeaderCollection);

if(SUCCEEDED(hr))

hr = pHeaderCollection->AddName(name);

if(SUCCEEDED(hr))

hr = pObexDevice->Put(pHeaderCollection, &myStream);

if (SUCCEEDED(hr)) {

char inBuf[5000];

DWORD written;

ULONG cbJustRead;

do {

if(!ReadFile(hFile, inBuf, sizeof(inBuf), &cbJustRead, 0))

break;

hr = myStream->Write(inBuf, cbJustRead, &written);

dwBytesSent += written;

fputws (L".", stdout);

} while (SUCCEEDED(hr) && (cbJustRead == sizeof(inBuf)));

hr = S_OK;

}

fputws (L"\n", stdout);

if (myStream)

myStream->Release();

CloseHandle(hFile);

if(pHeaderCollection)

pHeaderCollection->Release();

return 0;

}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {

CoInitializeEx (NULL, COINIT_MULTITHREADED);

IObex *pObex = NULL;

HRESULT hr = CoCreateInstance(__uuidof(Obex), NULL, CLSCTX_INPROC_SERVER, __uuidof(IObex), (void **)&pObex);

if(FAILED(hr)) {

fputws (L"Obex initialization failed!\n", stdout);

exit (1);

}

if (pObex != NULL)

pObex->Initialize ();

else

{

fputws (L"pObex->Initialize failed!\n", stdout);

exit (1);

}

IObexDevice *pObexDevice = NULL;

// Connect

pObexDevice = DoConnect (pObex);

// Send a file

SendFile (pObexDevice, L"\\test.txt");

// Disconnect

if (pObexDevice) {

pObexDevice->Release ();

pObexDevice = NULL;

fputws (L"Successfull...\n", stdout);

}

pObex->Shutdown ();

CoUninitialize ();

return 0;

}

This sample should connect to the first IRDA device it finds and send a file called test.txt via OBEX. Hopefully it is reasonably straight forward to see how it could be changed to allow the user to specify which device to send the file to etc.

All I have done is taken the sample from platform builder and altered it automatically send a file without needing to be driven by the keyboard (since a Windows Mobile device does not have a console by default). To use this code you should be able to create a blank C++ Win32 Smart device project within Visual studio 2005 and include the above source code.

Hope this helps you,

Christopher Fairbairn






Re: Smart Devices General IRDA send file option in Menu bar

namllat

Thank you very much~

I am still working and testing on it. Maybe mine is WCE5.0, the beaming cant trigger the receiver side. I am checking the driver, and super thanks for your code. I think it will work properly soon.

THANK YOU VERY MCUH~~






Re: Smart Devices General IRDA send file option in Menu bar

namllat

Dear Christopher,

I finally can send the file via IRDA, so cool~~~~~~~~~~~

However, to make it success, I've made some change on the code where I am not very sure why to do so! I just post it here for reference if anyone would like to do the same development in the future.

In DoConnect function, add the follow code before "hr = pObexDevice->Connect(0,0,pHeaderCollection); "

GUID CLSID_FileExchange_NetOrder = { 0xc47becf9, 0x3c95, 0xd211, {0x98, 0x4e, 0x52, 0x54, 0x00, 0xdc, 0x9e, 0x09}};

pHeaderCollection->AddTarget(sizeof (CLSID_FileExchange_NetOrder),(UCHAR *)&CLSID_FileExchange_NetOrder);

So that to make the Connect function return a success hr.

Besides, comment out the "if(obHeader->bId == OBEX_HID_CONNECTIONID)" to force it to return hr = S_OK. Maybe it is due to only one device found, no need to check!

Thank you very much!

P.S. anyone can explain to me the concept of GUID