locked
COM Interop RRS feed

  • Question

  • hi! I am trying to Interop between VB and Managed C++ dll. In the DLL i wish to call the VB methods and then to expose the same to C# (windows form application), but for now COM interop is my concern. I have an Interop.dll provided with the VB project which i have referenced to the managed C++ project.

    (A).I know that C++/CLI needs the MSIL files. For which i also know i need to uses "tlbimp" to convert/generate the MSIL files for the C++/CLI to access the same.

    question 1:Are my presumptions right with respect to (A), if so, I tried to use the "tlbimp" , in the C++/CLI project. But i got errors lie C2143,C2146,C4430,C2086,C2447. Does the use of "tlbimp" require initiation of regasm.exe? 

    (B). I get an error when i try the following: using System.Runtime.InteropServices; errors: C2143,C2873,C2059 WHY?

    I am new to wrappers, so if any ambiguity, please let me know.

    Thanks in advance.

    Monday, June 18, 2012 11:11 AM

Answers

  • There's not enough info here, so I'll guess:

    1. The VB thing is a VB6 Dll, COM, therefore it's Win32 COM and needs registering before it can be called.

    2. You should be able to create an interop dll by doing an Add Reference and browsing to the Dll (there are some details here I'm skipping) because the interop needs access to the type library that's usually embedded in a COM Dll.

    3. Once you have a managed interop Dll, you do not need to register it at all. All that's happening is that it's a mapping thing to call into the COM Dll. The interop Dll itself is not a COM Dll, it's just a wrapper that maps from managed code to unmanaged COM.


    Phil Wilson

    Wednesday, June 20, 2012 7:23 PM
  • Hi Sheetansh,

    Please take a look at this thread: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/de001f70-604a-4eef-815a-c526f2bd2264/#de001f70-604a-4eef-815a-c526f2bd2264

    I have post my opinion in that thread.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 25, 2012 11:48 AM

All replies

  • Yes. You need to create Runtime Callable Wrapper for your VB dll using tlbimp.

    Coming to errors - Have you registered your VB dll using RegSvr32? If not, register the VB dll first, then create the interop.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, June 18, 2012 11:47 AM
  • Adavesh, thanks for the reply.

    I will try and register it with Regsvr32. As far as i understand i will only be able to use "tlbimp" after the registeration, rite?

    thanks again!

    Monday, June 18, 2012 1:22 PM
  • Hi! Adavesh, i just tried to use regsvr32 and got an error saying <"c:\....file.dll" was loaded but the entry point DLL register server was not found.>

    What do i do now? I cant find any satisfactory answers anywhere else(actually no answers at all) can you help?

    The software to which this DLL belongs is already installed.

    Thanks in advance.

    Monday, June 18, 2012 2:35 PM
  • Hi! Adavesh please consider the following code:

    //#include <iostream>
    //using namespace std;
    using namespace System;
    using System.Runtime.InteropServices; //error C2143,C2873,C2059
    namespace
    {
    	ref class Spoton
    	{
    	};
    }
    int main()
    {
    	return 0;
    }

    question 1:Basically it doesnt recognise this line as a namespace like namespace system. why?

    i know the code is empty, could that be the reason?

    question 2: I registered the DLL using regasm. is that OK? or am i supposed to do it specifically using regsvr32?

    thanks in advance!!

    Monday, June 18, 2012 2:42 PM
  • There's not enough info here, so I'll guess:

    1. The VB thing is a VB6 Dll, COM, therefore it's Win32 COM and needs registering before it can be called.

    2. You should be able to create an interop dll by doing an Add Reference and browsing to the Dll (there are some details here I'm skipping) because the interop needs access to the type library that's usually embedded in a COM Dll.

    3. Once you have a managed interop Dll, you do not need to register it at all. All that's happening is that it's a mapping thing to call into the COM Dll. The interop Dll itself is not a COM Dll, it's just a wrapper that maps from managed code to unmanaged COM.


    Phil Wilson

    Wednesday, June 20, 2012 7:23 PM
  • Phil!! i need your help...

    I am trying to Interop Between Managed C++ and VB6(COM).

    I understand i need RCW for tat.

    The VB6 project has been provided with a .DLL file for Interop. **

    Now my questions:

    1. If i have the Interop DLL (as per **) which i am able to Add as a reference to in the Managed C++(RCW), DO I STILL NEED TO REGISTER IT USING "REGSVR32"?

    2. As i have the DLL (as per **), Do i still need to use Regasm?

    3. And why am i getting the following syntax error:

      

    1>------ Build started: Project: Spotoncall, Configuration: Debug Win32 ------
    1>Build started 21.06.2012 18:09:45.
    1>InitializeBuildStatus:
    1>  Touching "Debug\Spotoncall.unsuccessfulbuild".
    1>GenerateTargetFrameworkMonikerAttribute:
    1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
    1>ClCompile:
    1>  Spotoncall.cpp
    1>Spotoncall.cpp(5): error C2143: syntax error : missing ';' before '.'
    1>Spotoncall.cpp(5): error C2059: syntax error : '.'
    1>
    1>Build FAILED.
    1>
    1>Time Elapsed 00:00:01.47
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    for:

    using System.Runtime.InteropServices;
    Thanks in advance!!
    Friday, June 22, 2012 2:19 PM
  • Hi Sheetansh,

    Please take a look at this thread: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/de001f70-604a-4eef-815a-c526f2bd2264/#de001f70-604a-4eef-815a-c526f2bd2264

    I have post my opinion in that thread.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 25, 2012 11:48 AM
  • Thanks again mike!!

    Monday, June 25, 2012 1:11 PM