我想在Visual Studio 2008中将一维数组vb.net传递给vc ++托管的DLL.Dll已创建。在VB.net中,在构建时间内会出现一个错误。
//错误
error BC30657: 'abc' has a return type that is not supported or parameter
type that are not supported .
//我的Dll代码 // 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;
}
};
}
vb.net代码:
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
答案 0 :(得分:1)
托管C ++中的数组需要使用托管语法。
static int abc(array<int>^ nu)
答案 1 :(得分:0)
您没有正确调用dll函数。编码的方式会给你编译错误。 您需要传递参数(整数数组),如下所示:
obj.abc(nums())
这将返回一个值。因此,您需要获取该值并将其转换为字符串,如下所示,然后打印它:
Console.WriteLine(CStr(obj.abc(nums())))
试试这个
Dim intArray As New List(Of Integer)
intArray.Add(1)
intArray.Add(2)
Dim sResult as string
sResult = obj.abc(intArray.ToArray())