Solved

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

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

773 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