Home All Groups Group Topic Archive Search About

Exporting a function from VB.net DLL

Author
2 Jul 2009 8:23 PM
Bhavik
Hello,

I need to develop a DLL in VB.net 2008, which exports a function.
This function can be called from another C++ DLL or Win32 application
(which is not necessarily developed in VB.net).

I have created a new Class Library project in VB.net, and added
following code in it:

Public Class Class1
    Public Function Myfunc(ByVal num As Integer) As Boolean
    // do some processing in num
    // return a Boolean flag value based on result
    End Function
End Class

Now I created a new WIn32 application in C++, and tried to call the
"Myfunc" from this DLL, but it gives error code 127 (Procedure does
not exist). So, I guess the "Myfunc" is not exported from my DLL.

Can anyone please tell me how to export a function from VB.net DLL,
and if possible, how to call it from another C++ application?

Please help me. Thanks in advance for help.

/BP

Author
2 Jul 2009 8:28 PM
mayayana
This is a VB group. VB.Net is a very different
thing, despite the confusing similarity of names.
For VB.Net you can try the groups below, or any
other group with "dotnet" or "vsnet" in the name:

microsoft.public.dotnet.general
microsoft.public.dotnet.languages.vb


Show quoteHide quote
> I need to develop a DLL in VB.net 2008, which exports a function.
> This function can be called from another C++ DLL or Win32 application
> (which is not necessarily developed in VB.net).
>
> I have created a new Class Library project in VB.net, and added
> following code in it:
>
> Public Class Class1
>     Public Function Myfunc(ByVal num As Integer) As Boolean
>     // do some processing in num
>     // return a Boolean flag value based on result
>     End Function
> End Class
>
> Now I created a new WIn32 application in C++, and tried to call the
> "Myfunc" from this DLL, but it gives error code 127 (Procedure does
> not exist). So, I guess the "Myfunc" is not exported from my DLL.
>
> Can anyone please tell me how to export a function from VB.net DLL,
> and if possible, how to call it from another C++ application?
>
> Please help me. Thanks in advance for help.
>
> /BP
Author
2 Jul 2009 9:52 PM
Tom Shelton
On 2009-07-02, Bhavik <bhavik.pa***@gmail.com> wrote:
Show quoteHide quote
> Hello,
>
> I need to develop a DLL in VB.net 2008, which exports a function.
> This function can be called from another C++ DLL or Win32 application
> (which is not necessarily developed in VB.net).
>
> I have created a new Class Library project in VB.net, and added
> following code in it:
>
> Public Class Class1
>     Public Function Myfunc(ByVal num As Integer) As Boolean
>     // do some processing in num
>     // return a Boolean flag value based on result
>     End Function
> End Class
>
> Now I created a new WIn32 application in C++, and tried to call the
> "Myfunc" from this DLL, but it gives error code 127 (Procedure does
> not exist). So, I guess the "Myfunc" is not exported from my DLL.
>
> Can anyone please tell me how to export a function from VB.net DLL,
> and if possible, how to call it from another C++ application?
>
> Please help me. Thanks in advance for help.
>
> /BP

You can't export a function from a .NET dll.  This is not supported.

If you need to expose your .NET objects to non-.NET languages, the your best
bet is to expose your classes via COM - there are lots of examples of this on
the web and in the documentation. 

If you actually need it to be a native dll function then, you can use C++/CLI
to create a native wrapper for those situations - I have an example of this on
my blog:

http://tom-shelton.net/?p=40

The above creates a standard dll wrapper around a C# class library.  The
process is identical when using VB.NET (with the caveat that VB.NET handles
namespaces a bit differently).

HTH

--
Tom Shelton
Author
2 Jul 2009 9:58 PM
Tom Shelton
On 2009-07-02, Tom Shelton <tom_shel***@comcastXXXXXXX.net> wrote:
Show quoteHide quote
> On 2009-07-02, Bhavik <bhavik.pa***@gmail.com> wrote:
>> Hello,
>>
>> I need to develop a DLL in VB.net 2008, which exports a function.
>> This function can be called from another C++ DLL or Win32 application
>> (which is not necessarily developed in VB.net).
>>
>> I have created a new Class Library project in VB.net, and added
>> following code in it:
>>
>> Public Class Class1
>>     Public Function Myfunc(ByVal num As Integer) As Boolean
>>     // do some processing in num
>>     // return a Boolean flag value based on result
>>     End Function
>> End Class
>>
>> Now I created a new WIn32 application in C++, and tried to call the
>> "Myfunc" from this DLL, but it gives error code 127 (Procedure does
>> not exist). So, I guess the "Myfunc" is not exported from my DLL.
>>
>> Can anyone please tell me how to export a function from VB.net DLL,
>> and if possible, how to call it from another C++ application?
>>
>> Please help me. Thanks in advance for help.
>>
>> /BP
>
> You can't export a function from a .NET dll.  This is not supported.
>
> If you need to expose your .NET objects to non-.NET languages, the your best
> bet is to expose your classes via COM - there are lots of examples of this on
> the web and in the documentation. 
>
> If you actually need it to be a native dll function then, you can use C++/CLI
> to create a native wrapper for those situations - I have an example of this on
> my blog:
>
> http://tom-shelton.net/?p=40
>
> The above creates a standard dll wrapper around a C# class library.  The
> process is identical when using VB.NET (with the caveat that VB.NET handles
> namespaces a bit differently).
>
> HTH
>

Crap...  Sorry - I just realized this is the VB.CLASSIC group!

To the op.  You should ask your VB.NET questions over on

microsoft.public.dotnet.languages.vb

--
Tom Shelton