Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2003

Tip: Looking for answers? Try searching our database.

how do you allow VB6 to call .NET DLL using vb6 DECLARE?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ray - 30 Sep 2003 23:01 GMT
I want to call a method in my.dll thats called test and has no parameters
but returns an int. I don't want to modify this VB program, but I want to
replace the DLL it calls with a C# DLL.  The VB declare in the program is
simple like this:

Declare Function test Lib _
   "C:\my.dll" () As Integer

What do I need to do to the C# code to get it to be visible by VB as if it
was the old library?

[ComVisible(true)]
public static int test(){ return 198;}

is what I currently have in the program, but that is after a whole bunch of
other pokes and prods....I saw something about

InterfaceTypeAttribute but am a little vague on whether creating an
interface for my class would help me in any way shape or form.

Any help would be appreciated.

Ray
Ray - 30 Sep 2003 23:59 GMT
okay, after more looking around i've got this

    [Guid("a1a1a1a1-a2a2-a3a3-a4a4-1234567890ABCDEF") ]
    //[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
    public interface IMINE     {
         int test();

    }

    [Guid("b1b1b1b1-b2b2-b3b3-b4b4-1234567890ABCDEF") ]
    public class myclass : IMINE     {
         public myclass()
         {
         }
         public int test(){ return 198;}

> I want to call a method in my.dll thats called test and has no parameters
> but returns an int. I don't want to modify this VB program, but I want to
[quoted text clipped - 19 lines]
>
> Ray
Ray - 01 Oct 2003 00:24 GMT
so I was saying...  okay, after more looking around i've got this

    [Guid("a1a1a1a1-a2a2-a3a3-a4a4-1234567890ABCDEF") ]
    //[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)]
    public interface IMINE     {
         int test();

    }

    [Guid("b1b1b1b1-b2b2-b3b3-b4b4-1234567890ABCDEF") ]
    public class myclass : IMINE     {
         public myclass()
         {
         }
         public int test(){ return 198;}

But to this point it still won't work, it gives me a "Can't find DLL entry
point test" error in VB.....So again I plea (I'll keep plugging away though
while you all ponder on the various realities and meanings of life in each,
and whether we exist because we code, or we code because we exist....  I
expect a report on my desk by begining of class today.)
Ray - 01 Oct 2003 01:42 GMT
currently, as near as I can figure, the library is exporting but the methods
aren't .

> I want to call a method in my.dll thats called test and has no parameters
> but returns an int. I don't want to modify this VB program, but I want to
[quoted text clipped - 19 lines]
>
> Ray
Ray - 01 Oct 2003 03:38 GMT
Okay I figured out how to at least get the call to show up in the type
library, but it still can't find it when I try to call it from the VB
program.....  HELP PLEEEEEEEEEEEEASE!??

> I want to call a method in my.dll thats called test and has no parameters
> but returns an int. I don't want to modify this VB program, but I want to
[quoted text clipped - 19 lines]
>
> Ray
Mattias Sj?gren - 02 Oct 2003 00:18 GMT
Ray,

There's no way to do what you want in pure C#.

Among the .NET languages, only VC++ and IL Assembler lets you export
functions in the way necessary to call it with a VB Declare statement.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

BP - 08 Oct 2003 23:57 GMT
Hi Ray,

VB.NET and C# does not allow you to "export" functions in your DLL that
other languages can call via the traditional API way. Other than using C++,
you can take a look at Desaware's SpyWorks www.desaware.com which allows you
to export functions in C# that VB6 applications can declare and call.

BP

> I want to call a method in my.dll thats called test and has no parameters
> but returns an int. I don't want to modify this VB program, but I want to
[quoted text clipped - 19 lines]
>
> Ray
Ray - 10 Oct 2003 11:39 GMT
Thanks anyway, I just decided to go ahead and write it in VC6 until I had
more time to play around with the can's and can not's.  I must say I was
surprised that MS's pride & joy couldn't export functions (who knows, maybe
they're working on it as I sleep????  THAT IS PURE WISHFUL THINKING!  don't
wanna start any rumors)

Ray.
----------------------------------------------------------------------------
------------
VB.NET and C# does not allow you to "export" functions in your DLL that
other languages can call via the traditional API way. Other than using C++,
you can take a look at Desaware's SpyWorks www.desaware.com which allows you
to export functions in C# that VB6 applications can declare and call.

BP

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.