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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. wrapping .TLB to .DLL for .NET

wrapping .TLB to .DLL for .NET

Scheduled Pinned Locked Moved C#
comcsharpsysadminperformance
4 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.
  • N Offline
    N Offline
    normanordas
    wrote on last edited by
    #1

    I have a .tlb file(neteng.tlb) that works on a vb 6 program. This library has module-based methods that i can call anywhere and it works fine. Next I wrapped this module-based DLL(neteng.tlb) to another VB 6 COM as you have said. I did that by adding a referenced first to "neteng.tlb" library then adding the following code to the class (NETENGAPI is a module inside "neteng.tlb"): '------------------------------------ Option Explicit Public Function NE_IsNetwork1(name As String) As Boolean NE_IsNetwork1 = NETENGAPI.NE_IsNetwork(name) End Function Public Function NE_OpenNetwork1(name As String, mode As AccessModeEnum) As Long NE_OpenNetwork1 = NETENGAPI.NE_OpenNetwork(name, mode) End Function Public Sub NE_InitNetworkEngine1() Call NETENGAPI.NE_InitNetworkEngine End Sub Public Sub NE_ExitNetworkEngine1() Call NETENGAPI.NE_ExitNetworkEngine End Sub '------------------------------------ Then save the file as Netengs.DLL (class name is NetEngEng) ===>>> Process Flow: neteng.tlb wrapped inside ->netengs.dll Note: Netengs.dll purpose was to call those module-based methods inside neteng.tlb thru the class NetEngEng so we can expose them when we migrate it to .NET assembly code. I created another VB6 Prog to test netengs.dll if its gonna work (i add a referenced first to netengs.dll). See code below:. Option Explicit Dim shp As String Dim net As NetEngs.NetEngEng Private Sub Form_Load() Set net = New NetEngEng Call net.NE_InitNetworkEngine1 shp = "d:\tracking\shapes\roadcenter_mkt_only.nws" 'Dim net As New NetEngs.NetEngEng Dim bool As Boolean 'bool = net.NE_IsNetwork1(shp) bool = net.NE_IsNetwork1(shp) If bool Then MsgBox ("Is network") Else MsgBox ("Is not network") End If Dim ne As Long ne = net.NE_OpenNetwork1(shp, 1) If (ne = 0) Then MsgBox "Network " + shp + " not found.", vbCritical Exit Sub End If Call net.NE_ExitNetworkEngine1 End Sub '----------- but when i run the prog and it step into the code Call net.NE_InitNetworkEngine1 it raises this error: The instruction at "0x00001de2" referenced at "0x00001de2". The memory could not be "read." My neteng.dll that wraps neteng.tlb don't even work inside another vb 6 prog. Whats wrong with neteng.dll here? Am i missing something? It would be more disaster if i import this to interop assembly. Tnx!

    H 1 Reply Last reply
    0
    • N normanordas

      I have a .tlb file(neteng.tlb) that works on a vb 6 program. This library has module-based methods that i can call anywhere and it works fine. Next I wrapped this module-based DLL(neteng.tlb) to another VB 6 COM as you have said. I did that by adding a referenced first to "neteng.tlb" library then adding the following code to the class (NETENGAPI is a module inside "neteng.tlb"): '------------------------------------ Option Explicit Public Function NE_IsNetwork1(name As String) As Boolean NE_IsNetwork1 = NETENGAPI.NE_IsNetwork(name) End Function Public Function NE_OpenNetwork1(name As String, mode As AccessModeEnum) As Long NE_OpenNetwork1 = NETENGAPI.NE_OpenNetwork(name, mode) End Function Public Sub NE_InitNetworkEngine1() Call NETENGAPI.NE_InitNetworkEngine End Sub Public Sub NE_ExitNetworkEngine1() Call NETENGAPI.NE_ExitNetworkEngine End Sub '------------------------------------ Then save the file as Netengs.DLL (class name is NetEngEng) ===>>> Process Flow: neteng.tlb wrapped inside ->netengs.dll Note: Netengs.dll purpose was to call those module-based methods inside neteng.tlb thru the class NetEngEng so we can expose them when we migrate it to .NET assembly code. I created another VB6 Prog to test netengs.dll if its gonna work (i add a referenced first to netengs.dll). See code below:. Option Explicit Dim shp As String Dim net As NetEngs.NetEngEng Private Sub Form_Load() Set net = New NetEngEng Call net.NE_InitNetworkEngine1 shp = "d:\tracking\shapes\roadcenter_mkt_only.nws" 'Dim net As New NetEngs.NetEngEng Dim bool As Boolean 'bool = net.NE_IsNetwork1(shp) bool = net.NE_IsNetwork1(shp) If bool Then MsgBox ("Is network") Else MsgBox ("Is not network") End If Dim ne As Long ne = net.NE_OpenNetwork1(shp, 1) If (ne = 0) Then MsgBox "Network " + shp + " not found.", vbCritical Exit Sub End If Call net.NE_ExitNetworkEngine1 End Sub '----------- but when i run the prog and it step into the code Call net.NE_InitNetworkEngine1 it raises this error: The instruction at "0x00001de2" referenced at "0x00001de2". The memory could not be "read." My neteng.dll that wraps neteng.tlb don't even work inside another vb 6 prog. Whats wrong with neteng.dll here? Am i missing something? It would be more disaster if i import this to interop assembly. Tnx!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You have a method trying to access the address of itself, where it won't find any data obviously.

      Microsoft MVP, Visual C# My Articles

      N 1 Reply Last reply
      0
      • H Heath Stewart

        You have a method trying to access the address of itself, where it won't find any data obviously.

        Microsoft MVP, Visual C# My Articles

        N Offline
        N Offline
        normanordas
        wrote on last edited by
        #3

        This is content my my type-library when i open it thru OLE Viewer: // typelib filename: neteng.tlb [ uuid(281078B0-B4B9-11D2-92C7-0000F878079B), version(1.2), helpstring("Library Neteng"), helpfile("NetEngine.HLP"), helpcontext(00000000) ] library NETENG { // TLib : // Forward declare all types defined in this typelib typedef enum { NE_READWRITE = 0, NE_READONLY = 1 } AccessModeEnum; typedef enum { NE_SIMPLE = 0, NE_FASTINDEX = 1 } IndexTypeEnum; [ dllname("neteng.dll") ] module NETENGAPI { [entry(0x60000000), helpstring("Initialize the network engine."), helpcontext(0x0000756f)] void _stdcall NE_InitNetworkEngine(); [entry(0x60000001), helpstring("Exit from the network engine."), helpcontext(0x00007570)] void _stdcall NE_ExitNetworkEngine(); [entry(0x60000002), helpstring("Takes in the public attribute record for the Network and creates a Network. This results in a directory whose name is part of the Network attribute record. The Network remains until deleted. A NULL pointer is returned if the Network could not be created."), helpcontext(0x00007573)] ------------------------------------------------------------- as you can see my neteng.tlb file has a module NETENGAPI but what i don't understand is the inclusion of [dllname("neteng.dll")]. Does it mean that the functionality of the NETENGAPI module resides in another file and that is neteng.dll? Indeed there's another fle associated with it but i can't open it by OLE Viewer it says its not a valid type lib. How i can i use NETENGAPI then in my VB.Net app?Adding reference to neteng.tlb only shows the enumeration members but the module methods can't be called nor recognized(NETENG.NETENGAPI.NE_InitNetworkEngine() is not a member the editor says). Tnx a lot!

        H 1 Reply Last reply
        0
        • N normanordas

          This is content my my type-library when i open it thru OLE Viewer: // typelib filename: neteng.tlb [ uuid(281078B0-B4B9-11D2-92C7-0000F878079B), version(1.2), helpstring("Library Neteng"), helpfile("NetEngine.HLP"), helpcontext(00000000) ] library NETENG { // TLib : // Forward declare all types defined in this typelib typedef enum { NE_READWRITE = 0, NE_READONLY = 1 } AccessModeEnum; typedef enum { NE_SIMPLE = 0, NE_FASTINDEX = 1 } IndexTypeEnum; [ dllname("neteng.dll") ] module NETENGAPI { [entry(0x60000000), helpstring("Initialize the network engine."), helpcontext(0x0000756f)] void _stdcall NE_InitNetworkEngine(); [entry(0x60000001), helpstring("Exit from the network engine."), helpcontext(0x00007570)] void _stdcall NE_ExitNetworkEngine(); [entry(0x60000002), helpstring("Takes in the public attribute record for the Network and creates a Network. This results in a directory whose name is part of the Network attribute record. The Network remains until deleted. A NULL pointer is returned if the Network could not be created."), helpcontext(0x00007573)] ------------------------------------------------------------- as you can see my neteng.tlb file has a module NETENGAPI but what i don't understand is the inclusion of [dllname("neteng.dll")]. Does it mean that the functionality of the NETENGAPI module resides in another file and that is neteng.dll? Indeed there's another fle associated with it but i can't open it by OLE Viewer it says its not a valid type lib. How i can i use NETENGAPI then in my VB.Net app?Adding reference to neteng.tlb only shows the enumeration members but the module methods can't be called nor recognized(NETENG.NETENGAPI.NE_InitNetworkEngine() is not a member the editor says). Tnx a lot!

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          They aren't methods - they're functions. You need to P/Invoke these from the neteng.dll like so:

          [DllImport("neteng.dll")]
          private static extern void NE_InitNetworkEngine();
           
          [DllImport("neteng.dll")]
          private static extern void NE_ExitNetworkEngine();

          Microsoft MVP, Visual C# My Articles

          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