无法将数组引用从c ++ / cli传递回vb.net(Trouble passing array reference back from c++/cli to vb.net)
我试图将一个对象数组从c ++ / cli方法传回给调用的VB.NET例程。 函数调用返回bool以指示成功或失败,并且通过参数调用在对象数组中返回扩展信息。
我已将代码剥离为两个示例代码单元以演示问题。
应在调用TestReplaceArray之后填写TSAResult数组。 例如:
Dim TSAResult() As TestStruct = Nothing Dim MTCP As New TestCppPart() MTCP.TestReplaceArray(TSAResult)
我没有回到我的期望,这可能是我愚蠢的事情,这会让回报变得渺茫。
为了获得更多诊断信息以查看事物分离的地方,我创建了这个调用例程,它填充TestStructureArray只是为了查看调用方法中出现的内容:
'This is the VB.Net caller routine Dim TestStructArray() As TestStruct = Nothing TestStructArray = New TestStruct(1) {} Dim TSAResult() As TestStruct = Nothing Dim TS As New TestStruct 'put some junk in it TS.somevar = 10 TestStructArray(0) = TS TS = New TestStruct TS.somevar = 11 TestStructArray(1) = TS Dim MTCP As New TestCppPart() MTCP.TestReplaceArray(TestStructArray) 'Call the cpp/cli routine TSAResult = TestStructArray 'take a gander and what came back
调用的C ++ / CLI例程是:
// compiled with /clr public ref struct TestStruct { int somevar; }; public ref class TestCppPart { public: void TestReplaceArray(array<TestStruct ^>^ IPInfoArray) { IPInfoArray = gcnew array<TestStruct ^>(5); } };
我可以看到传递给对象数组的(仅用于测试)就是我传递的内容。 我还可以看到我可以用“IPInfoArray = gcnew array(5);”替换数组。 线。 它在元素中没有任何内容,但IPInfoArray现在引用了一个5元素数组。
返回到VB.Net代码时,原始(仅测试)数组仍然存在并填充。
我无法弄清楚的是如何告诉c ++ / cli我想要更新对数组的引用(如果你愿意的话,ByRef),所以它将使用新数组返回VB.Net。
谢谢,我觉得这应该是显而易见的,但我被困住了!
I am trying to pass an array of objects back from a c++/cli method back to the calling VB.NET routine. The function call returns a bool to indicate success or fail and extended information is returned in an Array of Objects via a parameter to the call.
I have stripped the code down to two example code units for demonstration of the problem.
The TSAResult Array should be filled in after the call to TestReplaceArray. e.g.:
Dim TSAResult() As TestStruct = Nothing Dim MTCP As New TestCppPart() MTCP.TestReplaceArray(TSAResult)
I'm not getting back what I expect and it's probably something dumb on my part that's fouling the return.
To get more diagnostic inforamtion to see where things were going apart, I created this calling routine which populates the TestStructureArray just to see what showed up in the called method:
'This is the VB.Net caller routine Dim TestStructArray() As TestStruct = Nothing TestStructArray = New TestStruct(1) {} Dim TSAResult() As TestStruct = Nothing Dim TS As New TestStruct 'put some junk in it TS.somevar = 10 TestStructArray(0) = TS TS = New TestStruct TS.somevar = 11 TestStructArray(1) = TS Dim MTCP As New TestCppPart() MTCP.TestReplaceArray(TestStructArray) 'Call the cpp/cli routine TSAResult = TestStructArray 'take a gander and what came back
The C++/CLI routine which is called is:
// compiled with /clr public ref struct TestStruct { int somevar; }; public ref class TestCppPart { public: void TestReplaceArray(array<TestStruct ^>^ IPInfoArray) { IPInfoArray = gcnew array<TestStruct ^>(5); } };
I can see that the (for testing only) passed in array of objects is what I passed. I can also see that I can replace the array with the "IPInfoArray = gcnew array(5);" line. It doesn't have anything in the elements, but a 5 element array is now referenced by IPInfoArray.
On return to the VB.Net code, the original (testing only) array is still present and populated.
What I can't figure out is how to tell the c++/cli that I want to update the reference to the array (ByRef if you will) so it will go back to VB.Net with the new array.
Thanks, I feel this should be obvious, but I'm stuck!
原文:https://stackoverflow.com/questions/22851315
最满意答案
你忘了实际匹配的东西......
你的代码:
def eval(v:HashMap[Char,T]):T = {
必要的代码:
def eval(v:HashMap[Char,T]):T = v match {
You have forgotten to actually match something...
Your code:
def eval(v:HashMap[Char,T]):T = {
Necessary code:
def eval(v:HashMap[Char,T]):T = v match {
相关问答
更多-
参数类型的匿名函数(Argument type of anonymous function)[2023-08-20]
你忘了实际匹配的东西...... 你的代码: def eval(v:HashMap[Char,T]):T = { 必要的代码: def eval(v:HashMap[Char,T]):T = v match { You have forgotten to actually match something... Your code: def eval(v:HashMap[Char,T]):T = { Necessary code: def eval(v:HashMap[Char,T]):T = v ma ... -
如果你想在这里输入某种类型的信息,你可以创建一个叫做的类或结构 public class TabMasterDataInfo { public int Total {get;set;} public int Page {get;set;} public int Records {get;set;} public IEnumerable Rows {get;set;} } 接着 var jsonData = new TabMasterDataInfo() { ...
-
如果可以在那里使用,你应该在OnDataResponse中提供类型in方法或更好的方法: public
void createUser(Class type, OnDataResponse responseListener) { ... } You should provide type in method or probably better in OnDataResponse if it can be used there: public void createUser(Clas ... -
匿名类型会给你带来麻烦。 你需要一个具体的类型才能工作。 以下示例在我更改时起作用 instance.GetResultAsync(u => new {isPair = u == "something" }) 至 instance.GetResultAsync(u => (object) new {isPair = u == "something" }) Moq无法匹配匿名类型,这就是调用时得到null原因。 [TestClass] public class MoqUnitTest { [Tes ...
-
flash.utils.getQualifiedClassName()如此处引用: 获取flex中的类型 arguments数组只能从给定函数内部访问。 除非你做一些疯狂的尝试/捕捉事情,否则我认为你所要求的是可行的,但如果参数是一个自定义类,那总是会失败,所以它不是一个很好的解决方案。 另一种选择是添加一些描述函数参数的自定义元数据。 [YourMeta(arg1="String",arg2="Array")]在每个函数上方,然后使用ObjectUtil.getClassInfo(f).metadata来 ...
-
C#如何在方法参数列表中声明lambda或匿名函数类型?(C# How to declare lambda or anonymous function type in method argument list?)[2023-12-04]
然后就是Action和Func。 但即使Action采用参数,我也不需要参数。 所以行动似乎不是一个可行的候选人。 如果使用Action (而不是Action),则不使用参数。 namespace N { interface MyInterface { void doSomething(Action completionBlock); } } 这允许你写: yourInstance.doSomething(() => DoWhatever(foo)); 或者,如果DoWhat ... -
你传递给.map的函数应该接受一个布尔参数b ,并返回另一个函数(大括号中的东西)。 编译器无法猜测该内部函数的类型,因此它会抱怨参数类型未知。 这实际上是一件好事,因为这不是你真正想写的东西。 只要删除整个(b => ...)业务: clean.map { case true => Ok("success") case false => Ok("failed") }.recover { case t => Ok("error: " + t) } 此外,使clean val而不是var ...
-
匿名函数参数(Anonymous function argument)[2022-08-05]
您可以定义一个函数并将其引用作为成功回调处理程序传递 //Define the function handler function resultHandler(result) { var locations = JSON.parse(result.d); locationDefer.resolve(locations); } if (saSel.Company === -1) { fun = 'getAllLocations'; arg = null; } else { ... -
不可以。您不能影响生成的匿名类型的构造函数。 它们甚至不是你应该依赖的东西,通过反射或其他任何东西,因为匿名类型的规范中没有指定的任何东西都是一个实现细节。 这恰恰是为了防止人们将它们用于不适合的事物,而应该使用适当的类别。 No. You cannot affect the generated constructor(s) of anonymous types. They're not even something whose existence you should rely on, via refle ...
-
由于VB对泛型方法没有返回类型推断,即使没有歧义,也无法做到这一点。 您可以使用强类型函数,使用泛型返回匿名类型,但不能使用推断泛型调用它,您需要明确指定它们。 Private Function Copy(Of T)(filePath as String, prototype As T) As T Return New With { .To = … } End Function (适用于.NET的命名约定) 必须按如下方式调用: Dim nullAction As Action(Of String ...