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.