Solved

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

Posted on 2010-09-24
4
550 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 63

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Send SMS from VB via Sierra Wireless Modem 2 23
What Does This C# Code Block Do? 5 54
JSON  parse help 7 40
VS2013 publish C# application Created folder -- where is it??? 10 27
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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