Solved

'unsigned short [260]' to 'char *' (Using Windows Mobile RAPI)

Posted on 2004-04-12
4
663 Views
Last Modified: 2007-12-19
Hi, I am currently working on an app that talks to a PocketPC using RAPI. I am at VERY begginer level in C++ and am still working through types and pointers.

The code below connects to a Pocket PC and tries to retrieve a directory listing. My issue is with the "wfd.cFileName" which reports as bing a 'unsigned short [260]', I need it as a string/char to populate a list in a window.
-----------------------------------------------------------------------------------------------
HANDLE hFind;
CE_FIND_DATA wfd;
HRESULT hRapiResult;
wcscpy( wszDirectory , L"\\*");
hRapiResult = CeRapiInit();

if (FAILED(hRapiResult)) //Do something if connection failed

hFind = CeFindFirstFile( wszDirectory, &wfd);
if (INVALID_HANDLE_VALUE == hFind) // Do somthing as Directory does not exist    

do {

      if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            wfd.cFileName <-(This is what I need as a string)
      else          
      {
            wfd.cFileName <-(This is what I need as a string)
      }
} while ( CeFindNextFile( hFind, &wfd));
CeFindClose( hFind);
CeRapiUninit();
-----------------------------------------------------------------------------------------------
Thanks,

Pete.
0
Comment
Question by:Peter-Pan
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10807303
cFileName  is WCHAR array .... use WideCharToMultiByte to convert from WCHAR to regular string
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp
0
 
LVL 1

Author Comment

by:Peter-Pan
ID: 10808311
Could you give an example using the above code? Again as I mentioned my C++ skills are very basic.

Thanks.
0
 
LVL 4

Accepted Solution

by:
bkfirebird earned 75 total points
ID: 10808361
try
char filename [256];
WideCharToMultiByte( CP_ACP, 0, (LPCWSTR) wfd.cFileName , -1, filename, 200, NULL, NULL );
0
 
LVL 1

Author Comment

by:Peter-Pan
ID: 10808719
I had just figured out an example too :)

Many thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now