Solved

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

Posted on 2004-04-12
4
675 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 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