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. Calling COM methods from a module NOT ALLOWED?

Calling COM methods from a module NOT ALLOWED?

Scheduled Pinned Locked Moved C#
csharpquestionasp-netcom
6 Posts 3 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

    Hi guys! Im using a third party external type library (C API) currently running in VB6. This is a low-level COM so it can't be converted to MSIL code nor it can be reference as COM inside a C# app. What I did is call this as an unmanaged code thru Platform Invoke. Most of the methods/functions were working fine except for some where it returns an exception of System.NullReferenceException. I found out that the method i called calls another method (with parameters) from a Module. However VB.Net and C# doesn't support this upgrade? Is this true? Then how do i go around with this? What other options can I resort to? I really have to CALL those methods/functions in my project because its the main core of my app logic process. Pls advise. Tnx!

    M H 2 Replies Last reply
    0
    • N normanordas

      Hi guys! Im using a third party external type library (C API) currently running in VB6. This is a low-level COM so it can't be converted to MSIL code nor it can be reference as COM inside a C# app. What I did is call this as an unmanaged code thru Platform Invoke. Most of the methods/functions were working fine except for some where it returns an exception of System.NullReferenceException. I found out that the method i called calls another method (with parameters) from a Module. However VB.Net and C# doesn't support this upgrade? Is this true? Then how do i go around with this? What other options can I resort to? I really have to CALL those methods/functions in my project because its the main core of my app logic process. Pls advise. Tnx!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Can I clarify? You're using a DLL with flat exports from VB6 using the Declare statement, and it calls back into your VB program (you pass function pointers into the DLL using the VB AddressOf syntax)? You're probably getting access violations (the CLR converts an access violation SEH exception into a System.NullReferenceException managed exception) because you haven't initialised the callback function pointers. To get a callback from unmanaged into managed code, you need to use a delegate. See MSDN: Implementing Callback Functions[^]. Stability. What an interesting concept. -- Chris Maunder

      N 1 Reply Last reply
      0
      • M Mike Dimmick

        Can I clarify? You're using a DLL with flat exports from VB6 using the Declare statement, and it calls back into your VB program (you pass function pointers into the DLL using the VB AddressOf syntax)? You're probably getting access violations (the CLR converts an access violation SEH exception into a System.NullReferenceException managed exception) because you haven't initialised the callback function pointers. To get a callback from unmanaged into managed code, you need to use a delegate. See MSDN: Implementing Callback Functions[^]. Stability. What an interesting concept. -- Chris Maunder

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

        No. I have a third party COM API(Neteng.tlb file) which is full COM compliant. I used this COM object in my VB 6 programs by adding a reference to it. When i browse its library thru Object Browser i noticed it has a lot of enumerations(enum in c#) and types(struct in c#) defined. It also exposes one method (NE_AddElement) but this is a MEMBER of a Module. ----------------------------------------------------------------- It says in Object Browser like... Sub NE_AddElement(netedit As Long, elatt As ElementAttRec) Member of NETENG.NETENGAPI Add the given element using the specified element record. WHERE NETENGAPI IS... Module NETENGAPI Member of NETENG ----------------------------------------------------------------- That means that this method belongs to the Module not to the class so after i made a reference to the COM i can automatically used the NE_AddElement method defined there and it works fine. My VB 6 program can recognized the method. Now i tried using the same COM API (Neteng.tlb) inside a VB.Net/C#. I made a reference to that COM API (as a COM object) inside my VS.NET IDE using the COM portion and it goes fine. I was successful at doing that but when i compile the code it RETURNED a compilation error saying: ---------- The name 'NE_AddElement' does not exist in the class "myclass name here"(CS0103) ---------- Why is that it can't recognized the NE_AddElement method though i have successfully Add a Reference to its COM? When i checked the equivalent InterOp assembly created after making the referencing i noticed it only exposes the class level enumerations and class level structs. Members of NETENGAPI (a Module) like the method NE_AddElement were not exposed. In VB 6 it can recognized the method as member of the NETENGAPI module. Can someone tell me how My VB.NET/C# program can fully recognized and in doing so used the NE_AddElement method!!!! Tnx in advanced!!!

        1 Reply Last reply
        0
        • N normanordas

          Hi guys! Im using a third party external type library (C API) currently running in VB6. This is a low-level COM so it can't be converted to MSIL code nor it can be reference as COM inside a C# app. What I did is call this as an unmanaged code thru Platform Invoke. Most of the methods/functions were working fine except for some where it returns an exception of System.NullReferenceException. I found out that the method i called calls another method (with parameters) from a Module. However VB.Net and C# doesn't support this upgrade? Is this true? Then how do i go around with this? What other options can I resort to? I really have to CALL those methods/functions in my project because its the main core of my app logic process. Pls advise. Tnx!

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

          Have you opened your library (which, btw, isn't the TLB file - that's only the typelib which contains information about the COM objects in your library) in depends.exe to find the exported function? It may be mangled using C++ decoration. I'm curious why you can't create an RCW, though. If it is a COM control and contains a typelib (either as an external file or embedded in the .rsrc section of the executable) you can run tlbimp.exe on it (or the external .tlb file). If that doesn't seem to work, you should open the DLL in VS.NET to view the resources and see if the typelib uses an ID other than 0, which using tlbimp.exe you can specify the name of the DLL along with the ID for the embedded typelib like so:

          tlbimp.exe MyLib.dll/1

          If this also contains an ActiveX control, you can use aximp.exe to create an interop assembly that contains a control/controls that derive from AxHost, which derives from Control an can be used in a container control.

          Microsoft MVP, Visual C# My Articles

          N 1 Reply Last reply
          0
          • H Heath Stewart

            Have you opened your library (which, btw, isn't the TLB file - that's only the typelib which contains information about the COM objects in your library) in depends.exe to find the exported function? It may be mangled using C++ decoration. I'm curious why you can't create an RCW, though. If it is a COM control and contains a typelib (either as an external file or embedded in the .rsrc section of the executable) you can run tlbimp.exe on it (or the external .tlb file). If that doesn't seem to work, you should open the DLL in VS.NET to view the resources and see if the typelib uses an ID other than 0, which using tlbimp.exe you can specify the name of the DLL along with the ID for the embedded typelib like so:

            tlbimp.exe MyLib.dll/1

            If this also contains an ActiveX control, you can use aximp.exe to create an interop assembly that contains a control/controls that derive from AxHost, which derives from Control an can be used in a container control.

            Microsoft MVP, Visual C# My Articles

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

            Its not a COM control its just a COM file(neteng.tlb). I noticed there's two other file in the same installation directory of that DLL (neteng.lib and neteng_CB.lib). How are this files related to neteng.tlb COM file?Which file should i import using tlbimp.exe?Importing neteng.lib or neteng_CB.lib via tlbimp says its not a valid type library. But i can import neteng.tlb and and it can create an assembly. This is exactly the same COM i used in my vb 6 program. I noticed also that the interop assembly created for the COM doesnt show any existence of a class. Only the namespace name, structs and enums are shown. The module and its methods were not exposed. So how would i be able to call the methods of the module as part of the created interop assembly if in the first place i can't see them present in the created assembly? Many Thanx!

            H 1 Reply Last reply
            0
            • N normanordas

              Its not a COM control its just a COM file(neteng.tlb). I noticed there's two other file in the same installation directory of that DLL (neteng.lib and neteng_CB.lib). How are this files related to neteng.tlb COM file?Which file should i import using tlbimp.exe?Importing neteng.lib or neteng_CB.lib via tlbimp says its not a valid type library. But i can import neteng.tlb and and it can create an assembly. This is exactly the same COM i used in my vb 6 program. I noticed also that the interop assembly created for the COM doesnt show any existence of a class. Only the namespace name, structs and enums are shown. The module and its methods were not exposed. So how would i be able to call the methods of the module as part of the created interop assembly if in the first place i can't see them present in the created assembly? Many Thanx!

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

              As I said in my reply, you use tlbimp.exe on the typelib - either an external .tlb or a typelib as a resource in an execute. A typelib, BTW, contains no executable code. There is still a COM server somewhere on your server that implements the interfaces that the typelib describes. That's all typelibs are - information about COM objects implemented in an executable (the COM server) that languages and frameworks can use to discover type information at design-time and compile-time. Even VB only uses the typelib for type information. At runtime, the CLSIDs (class IDs) are used to find the executed and its class factory creates an instance of the COM object with that CLSID (this is a very basic overview). If tlbimp.exe doesn't see a certain object or method, it's probably because it violates some rules of COM and cannot be imported. You should familiarize yourself with COM since VB hides all that from you, and run oleview.exe (part of the Platform SDK tools, which is installed by default with Visual Studio) passing the path to your typelib as the sole parameter. This will show you the IDL. Take a look at the method and, if you want, post back the method signature in this thread.

              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