Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-12
4
Medium Priority
?
678 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 300 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

704 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