Solved

C# Class subroutines, How to pass the eqivilant of VB's byRef

Posted on 2010-09-24
4
543 Views
Last Modified: 2013-12-16
I have some C subroutines in DLL's that I want to convert to C#. They basically have parms:

Input buffer (bytes)
Input length (int32)
Outbut buffer (bytes)
Output length (int32)

In VB.net, we simply define a subroutine with parameters defined as byRef, for example:

Sub MySub(..., byRef OutBuff() as Byte, byRef outLen as Int32)
        ' Do something
End Sub

This passes the data's pointers to the subroutine (and the length attribute as part of the byte array object). Thus the subroutine does not have any size limit/wasted memory tradeoffs. How do I do this in C#? In my attempts I keep getting "unsafe code", which VB will not allow me to call.

Thank you.
0
Comment
Question by:MikeBroderick
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Umar Topia
ID: 33754221
function MySub(ref bytes[] byInput)
{}
0
 
LVL 10

Accepted Solution

by:
Umar Topia earned 500 total points
ID: 33754229
Sry abt the typo:

void MySub(ref bytes[] byInput)
{}
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 33754303
Hi MikeBroderick;

When calling the method MySub in umartopia example you also need to have the ref key word.

// Calling MySub method:
MySub ( ... ref myByteArray, ... );

Fernando
0
 

Author Closing Comment

by:MikeBroderick
ID: 33754339
Thanks. I'm putting it in now.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now