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 / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

MarshalDirectiveException - Array size control parameter must be an integral type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tyler - 23 Sep 2003 15:09 GMT
I get the following exception when my unmanaged code attempts to invoke the
delegate that follows:

Delegate Declaration:

  protected delegate uint
     ReadProc(
              [MarshalAsUnmanagedType.LPArray,
ArraySubType=UnmanagedType.U1, SizeConst=12)] byte [] fvData,
              UIntPtr pfvuiSize,
              Object fvContext);

Exception:
  An unhandled exception of type
'System.Runtime.InteropServices.MarshalDirectiveException' occurred in
system.windows.forms.dll
  Additional information: Array size control parameter must be an integral
type.

I don't understand why the exception is occurring as I have specified an
integral SizeConst.

Background to the problem is as follows:
- allocate array in C# and pass it to P/Invoke worker function along with a
delegate
- worker invokes delegate to populate the array and specify # of bytes
copied into the array
- object is just a parameter passed to the worker function that the worker
passes to the delegate (not important)
- I know how big the array is, because I allocated it - however, I've found
that I need to specify that size when marshalling, otherwise it will think
the array is only 1 byte long in the method passed as the delegate
- when I specify the size, however, I get the exception noted above

I would greatly appreciate any insight into this issue.

Thanks, Tyler
Ying-Shen Yu[MSFT] - 24 Sep 2003 11:23 GMT
Hi Tyler,
     I can reproduce your problem, but haven't got a work around. I'm
doing some research on it and will give you some update soon, thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "Tyler" <Tyler@work.com>
| Subject: MarshalDirectiveException - Array size control parameter must be
an integral type
| Date: Tue, 23 Sep 2003 10:09:22 -0400
| Lines: 40
[quoted text clipped - 46 lines]
|
| Thanks, Tyler
Ying-Shen Yu[MSFT] - 25 Sep 2003 02:33 GMT
Hello Tyler,
    We already noticed that there is no good way to only specify a
sizeconst for a native array parameter. We are trying to fix this in the
next release. For now, as a work around, could you add a parameter for
passing the size of the array in your delegate signature? If yes you may
rewrite it like this
protected delegate uint ReadProc(
             
[MarshalAsUnmanagedType.LPArray,ArraySubType=UnmanagedType.U1,
SizeParamIndex =1 )]
              byte [] fvData,
              int dataSize,
              UIntPtr pfvuiSize, Object fvContext);
also, you need to change your unmanaged function signature accordingly, and
pass the size in dataSize param.

SizeParamIndex above indicates that the size of the array will be given by
the parameter at index 1 (with the array parameter at index 0 for a
signature that is not marked with PreserveSig=true ?if the sig is marked
with PreserveSig then the indexing is 1 based).  

If you still have problem , please let me know.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| X-Tomcat-ID: 330961814
| References: <usvzMxdgDHA.1764@TK2MSFTNGP09.phx.gbl>
[quoted text clipped - 5 lines]
| Date: Wed, 24 Sep 2003 10:23:01 GMT
| Subject: RE: MarshalDirectiveException - Array size control parameter
must be an integral type
| X-Tomcat-NG: microsoft.public.dotnet.framework.interop
| Message-ID: <#CedRXogDHA.2624@cpmsftngxa06.phx.gbl>
[quoted text clipped - 76 lines]
| |
| | Thanks, Tyler
Tyler - 26 Sep 2003 19:46 GMT
Unfortunately, the code that invoked the delegate was not mine, so I was not
able to modify it.  To work around the issue I wrote a wrapper in C++ that
modifies the parameters and then the interop works successfully.  I had
really wanted to do everything in C#/managed code ... but I guess I'll have
to wait.

Thank-you very much for your help,
Tyler

> Hello Tyler,
>      We already noticed that there is no good way to only specify a
[quoted text clipped - 127 lines]
> | |
> | | Thanks, Tyler

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.