Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

13 Experts available now in Live!

Get 1:1 Help Now