Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > GetOpenFileNameW API


Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2004, 05:01 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Question GetOpenFileNameW API


Hi Everyone,


I'm trying to find details on the GetOpenFileNameW (Unicode version of GetOpenFileNameA) API, but can't seem to find any anything solid on the net. I'd be very grateful if anyone who has examples could post them for me.

I've tried changing my own code, but the boxes come out as gibberish (obviously the change from ANSI to Unicode), so I must be missing something somewhere.


Thanks in advance,
Paul.
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #2  
Old 10-19-2004, 06:40 AM
avinash avinash is offline
Centurion
 
Join Date: Sep 2004
Posts: 111
Default Post the code using GetOpenFileNameA

Please post some code that you have written using GetOpenFileNameA. I will try changing it so that it uses GetOpenFileNameW.
Reply With Quote
  #3  
Old 10-19-2004, 07:19 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Do you have the actual structures required to use this API? That's basically all I need. If you could post this for me, I would be really grateful.


TIA,
Paul.
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #4  
Old 10-19-2004, 08:09 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

The difference is the OPENFILENAMEW structure used by GetOpenFileNameW. Since VB will attempt to convert the strings to ansi, you should use As Long instead of As String for all the string fields. Call lstrLenW on the returned pointer and RtlMoveMemory into a string.

When passing unicode strings TO the function you can simply pass StrPtr(myString) for the long field.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 10-19-2004, 08:31 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Excellent!

Thanks, OnErr0r - that answers the question perfectly.

I did actually see code elsewhere, written as C++, but using longs, and I couldn't understand why.

I'll take a look at that and post the resultant code.
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #6  
Old 10-19-2004, 08:35 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Just one last question - I take it the integers (nFileOffset and nFileExtension) are retained as integers?
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #7  
Old 10-19-2004, 08:37 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Yes.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #8  
Old 10-19-2004, 09:11 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Thanks for all your help, guys
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #9  
Old 10-19-2004, 09:39 AM
avinash avinash is offline
Centurion
 
Join Date: Sep 2004
Posts: 111
Default Buffer

If a datamember of the structure is a string buffer, which is filled by the API, then in UNICODE, change the datatype to Byte. I have tried that for some other APIs, e.g., FindFirstFile, which takes Win32_Find_Data as parameter. If, in Ascii, the string buffer has some maximum size, then in Unicode make the size as double of that. Example: In Ascii, if it is a string buffer of 255 characters, in Unicode make it a byte array of 255 * 2 bytes.

There is one thing that surprises me regarding OpenFileName. One member of the structure is lpStrFile. Its type is String. But it is filled up by the API. Then, why is it not a buffer. e.g. lpStrFile As String * 255? Any clue?
Thanks
Reply With Quote
  #10  
Old 10-19-2004, 09:44 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Ahhhh! I've just seen where the code's actually going wrong! The author of the code I've got has only defined a buffer size of 256 characters (lpStrFile). I'll increase this a little, and that should solve my problems without having to resort to memory management!

<Mandelbrot slaps forehead>

Avinash - thanks for that little nudge there! LOL!
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
  #11  
Old 10-19-2004, 10:48 AM
avinash avinash is offline
Centurion
 
Join Date: Sep 2004
Posts: 111
Default Internationalization?

Are you developing some Internationalization software?
Reply With Quote
  #12  
Old 10-20-2004, 03:09 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

No, Avinash - all of the previous apps I've developed have only ever required a single filename, in which case I've never noticed the size of the buffer. When I started using OFN_ALLOWMULTISELECT I hit the problem that the string wasn't long enough (i.e. the common dialog was feeding back a buffer overflow). I decided to look into it, and found that the GetOpenFileNameW had a huge string space without actually checking why the buffer was overflowing in the first place...
__________________
Flapped my arms in IT and there was a storm in finance - As promoted by AtmaWeapon!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->