Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

COM INTEROP: using a c# dll in vc++ 6.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
quintesv@cqs.co.za - 14 Dec 2004 14:36 GMT
Hi all, I need some assistance,

Im creating a basic c# dll in VS.Net 2003 which looks as follows:

//begin c#
namespace test
{
    [Guid("0CACD496-1E76-4703-9950-EEAB28117EA3"),
    InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface ITest
    {
        string Hello();
        string GoodBye();
        int MyInt();
    }       
   
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    [Guid("D9F20F93-95A8-43a8-B89F-375D123338AA")]
    [ClassInterface(ClassInterfaceType.None)]
    public class Class1 : ITest
    {

        public Class1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        string ITest.Hello()
        {
            return MyHello();
        }

        string ITest.GoodBye()
        {   
            string s = MyHello();
            return  s +  "bye bye and bye bye";
        }

        private string MyHello()
        {
            return "from MyHello.net";
        }
        int MyInt()
        {
            return 0;
        }
    }
}

//end c#

I have then run the following as per documentation:

1.sn -q -k test.sn
 added to assembly..
2.tlbexp test.dll /out:test.tlb
3.regasm test.dll /tlb:test.tlb /codebase

Then Im trying to create the object and call the methods from vc++ 6.0 as follows:
//BEGIN CPP

/*#include "stdafx.h"
#include "comdef.h"
#include <windows.h>

#include <stdlib.h>
//
#include "tchar.h"
//

#import "..\test.tlb" raw_interfaces_only
using namespace test;

int main ()
{

    HRESULT hResCom;
    HRESULT hr;
    CLSID clsid;
   unsigned short *retval;

    hResCom =CoInitialize(NULL);
   

    if (SUCCEEDED(hResCom))
    {

            try
            {
               //hr=CLSIDFromProgID(OLESTR("Test.Class1"),&clsid);
                ITestPtr pITest( __uuidof(Class1));
            //
            pITest->GoodBye(&retval);
            }
            catch(_com_error &e)
            {
               
                _bstr_t bstrdescription( e.Description());
                MessageBox(NULL,(LPCTSTR)bstrdescription,"HELLO",MB_OK);
                //(TRACE("Error %s", (LPCTSTR)bstrdescription);
               
           
           
            }
           
            try
            {
            ITestPtr ptrITest;
            ptrITest.CreateInstance("Test.Class1");
            _variant_t vResult;
            //vResult=
            unsigned short *s1;
            _bstr_t *sb;
            ptrITest->GoodBye(&retval);
            ptrITest->Release();
            //string s ="";//= (_bstr_t)vResult;
            }
            catch(_com_error &e)
            {               
                _bstr_t bstrdescription( e.Description());
                MessageBox(NULL,(LPCTSTR)bstrdescription,"HELLO",MB_OK);
            }
           
            //MessageBox(NULL,r_t)ptrITest->GoodBye,L"HELLO",MB_OK);       
       CoUninitialize();
   
    }
    else
    {
        return FALSE;
    }
   
    return 0;
}
//END CPP

//AS you can see I have tried 2 methods, and neither works. The Cpp debug window says im getting a first class exception in the test.

What am i doing wrong? Ignore all the unreferenced vars :)

Thanks in advance,
Quintes
quintesv@cqs.co.za - 15 Dec 2004 07:25 GMT
Well... Nevermind...

All you have to do is copy the assembly into the GAC

Q.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.