Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / September 2005

Tip: Looking for answers? Try searching our database.

Passing Structures to Unmanged Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lee - 20 Sep 2005 22:53 GMT
I am trying to work with the RasDialA function that takes a structure which
contains several string, but cannot get it to work.

In VB6 the structure called RASDIALPARAMS is as so...
'Type declaration for RASDIALPARAM structure
Public Type RasDialParams
   dwSize As Long
   szEntryName(MaxEntryName) As Byte
   szPhoneNumber(RAS_MaxPhoneNumber) As Byte
   szCallbackNumber(MaxCallbackNumber) As Byte
   szUserName(UNLEN) As Byte
   szPassword(PWLEN) As Byte
   szDomain(DNLEN) As Byte
End Type

My .NET Version Is as so...
   Public Structure RASDIALPARAMS
       Public iSize As Int32
       Public sEntryName() As Byte
       Public sPhoneNumber() As Byte
       Public sCallbackNumber() As Byte
       Public sUserName() As Byte
       Public sPassword() As Byte
       Public sDomain() As Byte
       Public iSubEntry As Int32
       Public iCallbackVal As Int32
   End Structure
Since I cannot create arrays with dimension I do that when the structure is
created locally with a procedure.

The size of the 2 structures are not equivelent the vb6 structure is 1052
bytes, while the .NET structure is 36. Which means to me that the array
definitions are merely place holders for the array. How can I get my
structures to work properly?
Mattias Sjögren - 21 Sep 2005 20:47 GMT
>The size of the 2 structures are not equivelent the vb6 structure is 1052
>bytes, while the .NET structure is 36. Which means to me that the array
>definitions are merely place holders for the array. How can I get my
>structures to work properly?

Add the attribute

<MarshalAs(UnmanagedType.ByValArray, SizeConst:=123)>

before each array member (and replace 123 with the actual array size).

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.