Click here to Skip to main content
15,892,298 members
Home / Discussions / C#
   

C#

 
AnswerRe: help Pin
Pete O'Hanlon16-Dec-11 23:38
mvePete O'Hanlon16-Dec-11 23:38 
AnswerRe: help Pin
#realJSOP17-Dec-11 3:04
mve#realJSOP17-Dec-11 3:04 
GeneralReason for my vote of 1 Pin
Manfred Rudolf Bihy17-Dec-11 15:21
professionalManfred Rudolf Bihy17-Dec-11 15:21 
GeneralRe: Reason for my vote of 1 PinPopular
#realJSOP18-Dec-11 0:57
mve#realJSOP18-Dec-11 0:57 
AnswerRe: help Pin
AmitGajjar17-Dec-11 7:22
professionalAmitGajjar17-Dec-11 7:22 
Questionunmanaged - returning arrays Pin
Mark H Bishop16-Dec-11 12:26
Mark H Bishop16-Dec-11 12:26 
AnswerRe: unmanaged - returning arrays Pin
Luc Pattyn16-Dec-11 15:08
sitebuilderLuc Pattyn16-Dec-11 15:08 
GeneralRe: unmanaged - returning arrays Pin
Mark H Bishop17-Dec-11 4:08
Mark H Bishop17-Dec-11 4:08 
Great article (and my code does stink)

Below, for convenience, I made a copy of your code for method 1 (automatic way). I see that in the C# version an object named "pNumbers" is passed in the call rather than the "numbers" array. The VB code passes the "numbers" array itself. Is pNumbers another array or is it a pointer or is it a typo? Also, is "unsafe" required in the C# version?

C#

C#
public int ArrayAutomatic() {
    int dim=1000;
    int[] numbers=new int[dim];
    ...
    int sum=SumArray(pNumbers, dim);
    return sum;
}

[DllImport("native.dll")]
unsafe public static extern int SumArray(int[] numbers, int count);


VB

VB
Public Function ArrayAutomatic() As Integer
    Dim dime As Integer = 1000
    Dim numbers(dime) As Integer
    ...
    Dim sum As Integer = SumArray(numbers, dime)
    Return sum
End Function

Declare Auto Function SumArray Lib "NativeC.dll" (ByVal numbers As Integer(), ByVal count As Integer) As Integer



With your help I am able to get the array using C# by using a literal translation of your VB example:

C++

C++
extern "C" int __declspec(dllexport) __stdcall ret_arr(float returnArray[])
{
    returnArray[0] = 5;
    returnArray[1] =10;
    return 1;
}


C#

C#
[DllImport("CudaFft.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "ret_arr")]
public static extern int ret_arr(float[] retArray);

private void test()
{
    float[] retArray = new float[2];
    int ans = ret_arr(retArray);
}



It works but it may still stink. Am I on my way?
GeneralRe: unmanaged - returning arrays Pin
Luc Pattyn17-Dec-11 4:22
sitebuilderLuc Pattyn17-Dec-11 4:22 
GeneralRe: unmanaged - returning arrays Pin
Mark H Bishop17-Dec-11 7:22
Mark H Bishop17-Dec-11 7:22 
AnswerRe: unmanaged - returning arrays Pin
Luc Pattyn17-Dec-11 7:40
sitebuilderLuc Pattyn17-Dec-11 7:40 
GeneralRe: unmanaged - returning arrays Pin
harold aptroot17-Dec-11 5:13
harold aptroot17-Dec-11 5:13 
GeneralRe: unmanaged - returning arrays Pin
Mark H Bishop17-Dec-11 7:16
Mark H Bishop17-Dec-11 7:16 
GeneralRe: unmanaged - returning arrays Pin
Mark H Bishop17-Dec-11 7:29
Mark H Bishop17-Dec-11 7:29 
QuestionCoolest way to do this string operation? Pin
SledgeHammer0116-Dec-11 11:23
SledgeHammer0116-Dec-11 11:23 
AnswerRe: Coolest way to do this string operation? Pin
PIEBALDconsult16-Dec-11 11:34
mvePIEBALDconsult16-Dec-11 11:34 
GeneralRe: Coolest way to do this string operation? Pin
SledgeHammer0116-Dec-11 11:44
SledgeHammer0116-Dec-11 11:44 
GeneralRe: Coolest way to do this string operation? Pin
PIEBALDconsult16-Dec-11 11:52
mvePIEBALDconsult16-Dec-11 11:52 
GeneralRe: Coolest way to do this string operation? Pin
SledgeHammer0116-Dec-11 12:06
SledgeHammer0116-Dec-11 12:06 
GeneralRe: Coolest way to do this string operation? Pin
Not Active16-Dec-11 13:54
mentorNot Active16-Dec-11 13:54 
AnswerRe: Coolest way to do this string operation? Pin
AspDotNetDev16-Dec-11 11:50
protectorAspDotNetDev16-Dec-11 11:50 
GeneralRe: Coolest way to do this string operation? Pin
PIEBALDconsult16-Dec-11 11:57
mvePIEBALDconsult16-Dec-11 11:57 
AnswerRe: Coolest way to do this string operation? Pin
AspDotNetDev16-Dec-11 12:05
protectorAspDotNetDev16-Dec-11 12:05 
AnswerRe: Coolest way to do this string operation? Pin
harold aptroot16-Dec-11 12:16
harold aptroot16-Dec-11 12:16 
GeneralRe: Coolest way to do this string operation? Pin
AspDotNetDev16-Dec-11 12:25
protectorAspDotNetDev16-Dec-11 12:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.