Solved

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

Posted on 2004-04-12
4
666 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 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

17 Experts available now in Live!

Get 1:1 Help Now