Win32::API - how to pass a wchar_t to it 
Author Message
 Win32::API - how to pass a wchar_t to it

I wonder if someone can help me on how to pass a wchar_t to an
API?  Here is some background info:

In the xxx.h file, there is this line:

#define  FILE_OPEN_RO  L'r'/* Read-only Access.*/

In the documentation, there is an example (in C):

int      cHandle = 0;
wchar_t  openMode = FILE_OPEN_RO;
cHandle = FileOpen( openMode );

My Perl script is like this:

$OpenMode = 'FILE_OPEN_RO';
$FileOpen = new Win32::API("theAPI", "FileOpen", ['N'], 'I');
$handleOpen = $FileOpen->Call($OpenMode);
print "return code = $handleOpen\n";

According to the manual, the return code that I am getting
means "bad open mode".  So, I must have not supplied the right
value to the API.  I have tried various values in $OpenMode:

pack("L",unpack("C",'r'))
pack("L",unpack("C","r"))
pack("L", 114)  # ASCII code for letter r

etc. and they all resulted in bad open mode.

Thanks in advance!

-----------------------------------------------------------

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.*-*-*.com/



Sun, 22 Dec 2002 03:00:00 GMT  
 Win32::API - how to pass a wchar_t to it
)
) #define  FILE_OPEN_RO  L'r'/* Read-only Access.*/
[...]
) wchar_t  openMode = FILE_OPEN_RO;
) cHandle = FileOpen( openMode );

Since you are passing a C<L'r'> by value, the C calling convention
[at least on Win32] automatically promotes the value to a 4-byte
value so the C<L> in C<L'r'> and the C<wchar_t> only make a
difference as far as the compiler's type checking mechanism is
concerned.  What gets pushed onto the stack is the integer value
of C<L'r'> which is the same as the integer value of C<'r'>,
which is C<unpack "C", "r">.

) $OpenMode = 'FILE_OPEN_RO';

$OpenMode = unpack "C", "r";

) $FileOpen = new Win32::API("theAPI", "FileOpen", ['N'], 'I');
) $handleOpen = $FileOpen->Call($OpenMode);
[...]
) pack("L",unpack("C",'r'))
) pack("L",unpack("C","r"))
) pack("L", 114)  # ASCII code for letter r

You only use C<pack> with Win32::API if the parameter type is
C<"P">.
--
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)



Sun, 22 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing NULL pointers to Win32::API function

2. Passing File Handles when using Win32::API

3. Win32::API - passing unicode string?

4. Passing NULL pointer to Win32::API function

5. WIN32::API - how to pass char * const

6. Win32::API passing type LPCSTR?

7. Passing NULL pointer to Win32::API function

8. Problem Passing Handles using Win32::API module (A.Calpini)

9. Newbie: passing a null string to a Win32 api call

10. win32::api and win32::gui

11. xs trouble on Win32 (building Win32::API)

12. Win32::OLE and Win32::API programming

 

 
Powered by phpBB® Forum Software