Click here to Skip to main content
12,559,281 members (47,137 online)
Rate this:
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:*
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 7:55am
Updated 28-Jan-13 8:00am
Sergey Alexandrovich Kryukov 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?

1 solution

Rate this: bad
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.
Sergey Alexandrovich Kryukov 28-Jan-13 16:47pm
Of course, a 5. Pointless question and artificial problem, "I cannot use VB6 but I want"...
—SA 29-Jan-13 11:56am
I dont know how to program with vb6, so i prefer to write my project in and now this problem occurs and i dont know what should i do!
Dave Kreskowiak 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. 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2016
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