Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6 C# PInvoke DLL
I want to PInvoke a function written in VB6 from C#. The VB6 code that calls the DLL is declared like this:
Declare Function ApplyNNet Lib " location of the DLL file" (MyNNetType As String, MyAddress As String, MyInput() As Double) As Variant
 
My C# version looks like this:*
[DllImport("NNetApply.dll")] 
public static extern object ApplyNNet(string type, string add, double[] data);
I call the function like this:
object P_ = ApplyNNet("Back Prop", address,data);
With this declaration I receive a PInvoke error:
PInvoke restriction: cannot return variants.
Posted 28-Jan-13 8:55am
Edited 28-Jan-13 9:00am
v2
Comments
Sergey Alexandrovich Kryukov at 28-Jan-13 14:08pm
   
Why? why?! If you are already use VB.NET, why all this trouble?
Why variants, one of the worst "inventions", ever?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First, if you've got the VB6 code calling this .DLL, why are you calling the VB6 code from C#?? Just bypass the VB6 code and go straight to the .DLL!
 
Second, You can't call a VB6 function that returns Variant. There is no equivilent type in .NET. You have to declare the actual type being returned.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 28-Jan-13 16:47pm
   
Of course, a 5. Pointless question and artificial problem, "I cannot use VB6 but I want"...
—SA
Fiona.fj at 29-Jan-13 11:56am
   
I dont know how to program with vb6, so i prefer to write my project in c#.net. and now this problem occurs and i dont know what should i do!
Dave Kreskowiak at 29-Jan-13 12:57pm
   
You said your VB6 code is calling a .DLL. I take it you're trying to call this very same .DLL with your C# code?? It's not very clear what you're doing.
 
Is this other .DLL also a VB6 .DLL?? Does the function you're trying to call return a Variant?? If so, you're screwed.
Fiona.fj at 29-Jan-13 13:03pm
   
No, I said my code is in C#, and I wrote a declaration of the function in vb6 that was in my dll's tutorial. this function returns Variant, yeah. so you mean I cannot do any thing?
Dave Kreskowiak at 29-Jan-13 13:25pm
   
If the function you're calling returns a Variant, you're screwed. You cannot call that function from managed code (C#, VB.NET, any other managed language).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 400
1 Maciej Los 222
2 OriginalGriff 213
3 Zoltán Zörgő 135
4 BillWoodruff 130
0 OriginalGriff 7,969
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,309
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100