all groups > vb.net upgrade > october 2006 >
You're in the

vb.net upgrade

group:

How to change type to structure?



How to change type to structure? vb newbie
10/9/2006 9:23:05 AM
vb.net upgrade: I'm trying to figure out how to use the FastFind API call w/in VP.NET.
One of the parameters passed to the API is (in part) something like the
type listed below. How would you convert this into a Structure?

Private Type WIN32_FIND_DATA
cFileName As String * MAX_PATH
Alternate As String * 14
End Type

The problem as I understand it is that you can't define a fixed-length
character buffer within a structure. You could do something like this:

Private Structure WIN32_FIND_DATA
dim cFileName As String
dim Alternate As String
End Structure

But if you pass this to the API call, things don't work right.

I also tried:

Private Structure WIN32_FIND_DATA
dim cFileName() as Byte
dim Alternate() as Byte
End Structure

along with redim's of cFileName and Alternate, but that doesn't really
work either.


Any ideas on how to convert the data structure?
Re: How to change type to structure? Mattias Sjögren
10/9/2006 8:51:05 PM
[quoted text, click to view]

Add the attribute <MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> to cFileName (when it's typed As String). The
attribute is located in the System.Runtime.InteropServices namespace.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Re: How to change type to structure? vb newbie
10/10/2006 6:33:45 AM
Thanks!
[quoted text, click to view]
AddThis Social Bookmark Button