473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling C# from VB.Net with arguments by reference

Hi

Hi

I am trying to call a C# function where I pass an argument by argument by
reference.

Here is the C#
using System;

namespace TheCSharpBit
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
unsafe public string CSharpFunction(int *myArg)
{
int i;
string s;

i = *myArg;

s = i.ToString() ;

*myArg=5;

return "From CSharpFunction " + s;
}

}
}

Here is a VB code snippet.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As New TheCSharpBit.Class1
Dim i As Integer

i = 3

Label1.Text = obj.CSharpFunction(i)

Console.WriteLine(i)

obj = Nothing
End Sub

Whan I complie I get the following error:
'CSharpFunction' has a return type that is not supported or parameter types
that are not supported.

I know the problem is with the parameter, so how do I pass the address of I
to the C# function CsharpFunction.

Thanks for your help

Chris

Aug 10 '05 #1
1 1245
>I know the problem is with the parameter, so how do I pass the address of I
to the C# function CsharpFunction.


Unless you have a good reason for using pointers, change the C# method
signature to
public string CSharpFunction(ref int myArg)


Mattias

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Shailan | last post by:
Hi Im having trouble with the following code that seems to be behave differently when called from the browser as opposed to the command line. The calling script is a cgi that forks, with the...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
11
by: JS | last post by:
I have made a function createFirstMenu where I call "resetMenu" in a JavaScript. But nothing happens when I call resetMenu. function createFirstMenu(sel){ sel = document.getElementById('sel1');...
5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
5
by: jodyblau | last post by:
I have a form with a subform. The form has a button which opens a dialogbox. I would like the dialog box to call a sub in the subform. I know how I would do this in C++, but I can't seem to...
1
by: mayur_hirpara | last post by:
Hi, I am looking to call a javascript function using variable number of parameters. Suppose I have a function foo(param) { ..... } I want it to be called unpredictebly when certain action...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
3
by: duzhidian | last post by:
Hello: When I need a function to generate a string, I have two methods: 1. pass by reference: mystring = ""; myfunction( mystring ); // prototype of myfunction( &anystring );
15
by: J. Peng | last post by:
Hello, I saw this statement in Core Python Programming book, All arguments of function calls are made by reference, meaning that any changes to these parameters within the function affect the...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.