Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. DLL Problems

DLL Problems

Scheduled Pinned Locked Moved Visual Basic
csharpc++visual-studiodebugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    parth p
    wrote on last edited by
    #1

    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 DOS

    Unhandled 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 -

    N 1 Reply Last reply
    0
    • P parth p

      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 DOS

      Unhandled 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 -

      N Offline
      N Offline
      Nilesh Hapse
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups