Import C dll methods to C# app

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi this is my first post on this newsgroup!! Excited.

My question has to do with importing a dll that was written in C into c#. I
have been able to import it using DLLImport but the issue is the following.
The function call returns the result by reference, but c# does not allow that
so how can I get my result from the function call? here is an example of a
call from the dll.

myAddMethod(double a, double b, double answer)

the result is returned as the variable answer.

How can I get the value of answer in my app?

Thanks.
 
kapsolas said:
Hi this is my first post on this newsgroup!! Excited.

My question has to do with importing a dll that was written in C into c#.
I
have been able to import it using DLLImport but the issue is the
following.
The function call returns the result by reference, but c# does not allow
that
so how can I get my result from the function call? here is an example of a
call from the dll.

myAddMethod(double a, double b, double answer)

the result is returned as the variable answer.

How can I get the value of answer in my app?

Thanks.

.... ,ref double answer)

Willy.
 
The type double method signature parameter "answer" should hold the result
after the method call is made. You may need to prepend the ref keyword before
the parameter. All you need to do is make the method call and then use the
value in "answer".

Peter
 
That didnt do it for me.

When I import this dll into a vb6 project I can do this:
Dim ans as Integer
Dim a as Integer
Dim b as Integer

myAddMethod(a, b, ans)

MsgBox("Your answer is: " + ans)

and this works fine.

when trying this in a c# ans has no value. here is some sample code

int a;
int b;
int answer;


myAddMethod(a, b, ref answer);

MessageBox.Show("Your answer is: " + answer.toString());


answer is always equal to ""

txtANS.Text = answer;
 
What type of DLL is it , you said "when I import into a VB6" project, is
this a COM library.

Willy.
 
If the third arg. of the COM method is DOUBLE*, then you need to call it
like this:

out double answer;
myAddMethod(double a, double b, out double answer);

Willy.
 
I had tried the ref and out keywords before posting on the discussion board.
Those both did not work.

I'll keep hunting around. maybe I can get the dll source and modifyit to
have the function return the resulting value.
 
Back
Top