Reputation: 19
I want to pass a one dimensional array vb.net to vc++ managed DLL,in visual studio 2008.Dll is created.In VB.net, During building time it's give one error.
//ERROR
error BC30657: 'abc' has a return type that is not supported or parameter
type that are not supported .
//My Dll code // MyCDll.h
#pragma once
using namespace System;
#include "stdafx.h"
namespace MyCDll
{
public ref class Class1
{
public:
static int abc(int nu[])
{
int i,value=0;
for (i=1;i<5;i++)
{
if(nu[i])
{
value=i+1;
}
}
//Return the position of the number in the array.
return value;
}
};
}
The vb.net code:
Imports System.IO
Imports System.Runtime.InteropServices
Module Module1
'Dim result As Integer
Sub Main()
Dim nums() As Integer = New Integer() {1, 2, 3, 4, 5, 6}
'Dim nums() As Integer = {1, 2, 3, 4, 5, 6}
Dim obj As New MyCDll.Class1
Console.WriteLine(obj.abc(ByVal nums() As Integer)As Integer)
'result = obj.abc(ByVal nums()As Integer)
Console.ReadLine()
End Sub
End Module
Upvotes: 1
Views: 385
Reputation: 19
Arrays in managed C++ need to use the managed syntax.
static int abc(array<int>^ nu)
Upvotes: 1
Reputation: 3310
You are not calling the dll function correctly. The way you have it coded will give you compilation errors. You need to pass the parameter (array of integers) like this:
obj.abc(nums())
This will return a value. Therefore you need to get that value and convert it to string, like below, and then print it:
Console.WriteLine(CStr(obj.abc(nums())))
Try this
Dim intArray As New List(Of Integer)
intArray.Add(1)
intArray.Add(2)
Dim sResult as string
sResult = obj.abc(intArray.ToArray())
Upvotes: 0