DLL Problems
-
Hi, I am just trying to create a DLL in VB.NET and use it in my console application, I know its not worth doing that, but I did. Here's the code for Dll:
Imports System Imports System.Threading Imports Microsoft.VisualBasic Imports System.Runtime.InteropServices _ Public Class Class1 Public Shared Function Main(ByVal iBigNum As Integer) As Integer Dim iRndNum As Random Main = iRndNum.Next() Return Main End Function End Class
And here's the code for console application:Module Module1 Public Declare Unicode Function iRandom Lib "C:\Users\Parth\Documents\Visual Studio 2005\Projects\vbRndDll\vbRndDll\bin\Debug\vbRndDll.dll" Alias "Main" (ByVal iBugNum As Integer) As Integer() Sub Main() Dim i As Integer For i = 0 To 10 Console.WriteLine(iRandom(3000).ToString) Next End Sub End Module
When I run this Vista gives me error message saying program crashed. But the DOS window is still open and this is the message I get in DOSUnhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'retur
n value': Invalid managed/unmanaged type combination.
at Console_db_VB.Module1.iRandom(Int32 iBugNum)
at Console_db_VB.Module1.Main() in C:\Users\Parth\Documents\Visual Studio 2005\Projects\Console_d
b_VB\Console_db_VB\Module1.vb:line 7
Press any key to continue . . .Can anyone tell me what I'm doing wrong??! I'm thinking of using VB.NET in C++ 6.0 and I need .NET code for some of the stuff I want to do.:confused::confused: Thanks in Advance. :)
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
-
Hi, I am just trying to create a DLL in VB.NET and use it in my console application, I know its not worth doing that, but I did. Here's the code for Dll:
Imports System Imports System.Threading Imports Microsoft.VisualBasic Imports System.Runtime.InteropServices _ Public Class Class1 Public Shared Function Main(ByVal iBigNum As Integer) As Integer Dim iRndNum As Random Main = iRndNum.Next() Return Main End Function End Class
And here's the code for console application:Module Module1 Public Declare Unicode Function iRandom Lib "C:\Users\Parth\Documents\Visual Studio 2005\Projects\vbRndDll\vbRndDll\bin\Debug\vbRndDll.dll" Alias "Main" (ByVal iBugNum As Integer) As Integer() Sub Main() Dim i As Integer For i = 0 To 10 Console.WriteLine(iRandom(3000).ToString) Next End Sub End Module
When I run this Vista gives me error message saying program crashed. But the DOS window is still open and this is the message I get in DOSUnhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'retur
n value': Invalid managed/unmanaged type combination.
at Console_db_VB.Module1.iRandom(Int32 iBugNum)
at Console_db_VB.Module1.Main() in C:\Users\Parth\Documents\Visual Studio 2005\Projects\Console_d
b_VB\Console_db_VB\Module1.vb:line 7
Press any key to continue . . .Can anyone tell me what I'm doing wrong??! I'm thinking of using VB.NET in C++ 6.0 and I need .NET code for some of the stuff I want to do.:confused::confused: Thanks in Advance. :)
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
I think the problem is with:
Main = iRndNum.Next() Return Main
Instead you can directly use:Return iRndNum.Next()
"Legacy code" often differs from its suggested alternative by actually working and scaling. —Bjarne Stroustrup