Re: using structs like BROWSEINFO and OPENFILENAME (string members
- From: "nebbish" <nebbish@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jan 2006 12:52:04 -0800
first of all.....thanks for the detailed reply. your discussion of unicode
vs ansi reminded me to recheck my typelib and found a couple of errors. i
should explain a couple of things though: PTR is ultimately typedef'd to
long (and i *think* the 'const' keyword that gets applied to LP'C'XSTR types
is valuable only for compile time checking of callee attempted
modifications), and second my VB code does not use a UNICODE #define - the
typelib does so the #if's are in the typelib source.
so here's the first error i found:
[
usesgetlasterror,
#ifdef UNICODE
entry("SHBrowseForFolderW"),
#else
entry("SHBrowseForFolder"),
#endif
helpstring("Displays a dialog that allows selection of shell folders"),
]
LPITEMIDLIST WINAPI SHBrowseForFolder(LPBROWSEINFO lpbi);
i had to do was change the second entry parameter to:
entry("SHBrowseForFolderA"),
the second error was so blatent i'm shocked at myself, i had to fix the
order of structure members as you mentioned.....(doh!).
And as far as maintaining an additional application entity, the typelib, it
is not a problem since our product already has a companion installer that
installs other secondary application components.
Thanks again for the feedback
--nebbish
"Thorsten Albers" wrote:
> nebbish <nebbish@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb im Beitrag
> <F9610152-553C-4D43-97D1-95A167F2B9BE@xxxxxxxxxxxxx>...
> > PTR /* LPCTSTR */ lpszTitle; // text to go in the banner over the
> tree.
> > PTR /* LPTSTR */ pszDisplayName;// Return display name of item
> selected.
>
> a) Whatever type definition for 'PTR' you are using - it doesn't make much
> sense since the one is LPCTSTR and the other is LPTSTR, i.e. they both are
> different types (even if the difference is a very small one...). Why don't
> you use the 'orginal' types?
>
> b) 'LPCTSTR'/'LPTSTR' to my opinion doesn't make sense for a type library
> to be used in Visual Basic, since you can't set the define UNICODE when
> compiling you VB project (UNICODE defined: LPCTSTR/LPTSTR ->
> LPCWSTR/LPWSTR; UNICODE not defined -> LPCSTR/LPSTR);
> If in your type library you are referring to SHBrowseForFolderA() you
> should use
> LPCSTR lpszTitle;
> LPSTR lpszDisplayName;
> If in your type library you are referring to SHBrowseForFolderW() you
> should use
> LPCWSTR lpszTitle;
> LPWSTR lpszDisplayName;
>
> c) The reason that setting 'lpszTitle' doesn't work presumably is, that you
> have changed the order of the structure members 'lpszTitle' and
> 'lpszDisplayName'; this is the correct structure definition according to
> the PSDK:
>
> typedef struct _browseinfoA {
> HWND hwndOwner;
> LPCITEMIDLIST pidlRoot;
> LPSTR pszDisplayName; // Return display name of item
> selected.
> LPCSTR lpszTitle; // text to go in the banner
> over the tree.
> UINT ulFlags; // Flags that control the
> return stuff
> BFFCALLBACK lpfn;
> LPARAM lParam; // extra info that's passed
> back in callbacks
> int iImage; // output var: where to
> return the Image index.
> } BROWSEINFOA, *PBROWSEINFOA, *LPBROWSEINFOA;
>
> typedef struct _browseinfoW {
> HWND hwndOwner;
> LPCITEMIDLIST pidlRoot;
> LPWSTR pszDisplayName; // Return display name of item
> selected.
> LPCWSTR lpszTitle; // text to go in the banner
> over the tree.
> UINT ulFlags; // Flags that control the
> return stuff
> BFFCALLBACK lpfn;
> LPARAM lParam; // extra info that's passed
> back in callbacks
> int iImage; // output var: where to
> return the Image index.
> } BROWSEINFOW, *PBROWSEINFOW, *LPBROWSEINFOW;
>
>
> > i even tried some other memory allocation api funcs like GlobalAlloc and
> > CoTaskMemAlloc. still no joy. (i think they all use the same heap
> anyway -
> > i'm 70% confident about that)
>
> There is no difference between LocalAlloc(), GlobalAlloc() and, e.g., Dim
> abData(0 to 9) As Byte. You shouldn't use CoTaskMemAlloc().
>
> > *but* this requires
> > api declarations which i am trying to eliminate by using the typelibrary.
>
> Why? What is better in using a type library then using Declare statements?
> Using a type library makes it necessary to take care of at least one more
> additional file. When transferring you VB project to another computer you
> have to take care that the type library is transferred as well - also it is
> not part of the VB project. This external dependency IMHO should be
> avoided.
>
> > i am intensly curious about the details
> > of passing memory pointers back and forth between VB & the API and why
> the
> > two members of the struct seem to behave differently.
>
> The different behaviour results from the different data type: While the one
> is declared as string, the other is declared as long. While the one holds a
> real string pointer which for VB indeed is a string pointer, the other
> holds a long value which in fact is a pointer to memory where string data
> have been stored. VB doesn't anything about the latter, for VB it always is
> just a long value, nothing more.
> Strings in VB are handled a bit different than the other data types in that
> they may be internally converted from Unicode to ANSI or vice-versa. I.e.
> when a string parameter is passed to an external function in a non-VB
> library, the original OLE unicode string (VB uses OLE Unicode strings) is
> converted internally to an ANSI string. If an external function in a non-VB
> library etc. passes a string parameter to VB, the string is assumed to be
> an ANSI string and is converted internally by VB to an OLE Unicode string.
> This only happens if VB knows that the passed parameter is a string, i.e.
> if it is declared "As String".
> This is due to the fact, that VB 32 bit originally was designed for
> platforms with no or with very restricted Unicode support, i.e. where the
> Windows API uses ANSI strings and doesn't provide function ("W") versions
> which are able to handle Unicode strings.
>
> --
> Thorsten Albers
> Albert-Ludwigs-Universität Freiburg
> albers@
> uni-freiburg.de
>
.
- References:
- Re: using structs like BROWSEINFO and OPENFILENAME (string members)
- From: Thorsten Albers
- Re: using structs like BROWSEINFO and OPENFILENAME (string members)
- Prev by Date: Re: Is there something better than EnumPrinters?
- Next by Date: shlwapi.dll
- Previous by thread: Re: using structs like BROWSEINFO and OPENFILENAME (string members)
- Next by thread: Re: GetPrivateProfileStringW
- Index(es):
Relevant Pages
|