Click here to Skip to main content
15,909,193 members
Home / Discussions / C#
   

C#

 
Questioncom interop Pin
V.23-Mar-06 22:43
professionalV.23-Mar-06 22:43 
AnswerRe: com interop Pin
mav.northwind23-Mar-06 23:16
mav.northwind23-Mar-06 23:16 
GeneralRe: com interop Pin
V.23-Mar-06 23:30
professionalV.23-Mar-06 23:30 
Questionhow to keep track of users Pin
vamsimohan2123-Mar-06 22:15
vamsimohan2123-Mar-06 22:15 
AnswerRe: how to keep track of users Pin
CWIZO23-Mar-06 23:05
CWIZO23-Mar-06 23:05 
GeneralRe: how to keep track of users Pin
vamsimohan2123-Mar-06 23:36
vamsimohan2123-Mar-06 23:36 
QuestionInvoking JavaScript Using System.Windows.Forms.WebBrowser Pin
BapiLolly23-Mar-06 22:07
BapiLolly23-Mar-06 22:07 
QuestionUsing an ATL object in C# Pin
rasmus.toftdahl.olesen23-Mar-06 21:46
rasmus.toftdahl.olesen23-Mar-06 21:46 
Hi experts!

I'm working on a project where i need to write some low-level hardware stuff in C++ and then allow access to it from the higher level C# stuff.

To test my different approaches to build a bridge from C++ to C# i also wanted to try writing a COM object, using the wizard it was almost too easy. But, alas, it didn't work.

I get an InvalidCastException in the last line of the client code:

Unable to cast COM object of type 'ATLServerTest2.DeviceClass' to interface type 'ATLServerTest2.IDevice'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{633DB896-4FA1-4E6B-85CF-C1B23BD5FE1C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I hope someone out there has tried doing the same, or at least has some suggestions as to possible faults.

Thanks in advance.
Rasmus

Client (in C# 2.0)
using ATLServerTest2;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Device device = new Device();
            IDevice idevice = device as IDevice;
            String s;

            idevice.getName(out s);
        }
    }
}


Server (in C++):
// IDevice
[
	object,
	uuid("633DB896-4FA1-4E6B-85CF-C1B23BD5FE1C"),
	helpstring("IDevice Interface")
	//pointer_default(unique)
]
__interface IDevice : IUnknown
{
	[helpstring("method getName")] HRESULT getName( [out] BSTR *name );
};


// _IDeviceEvents
[
	dispinterface,
	uuid("67C3F875-3BF5-495C-91AA-469E9EA33C46"),
	helpstring("_IDeviceEvents Interface")
]
__interface _IDeviceEvents
{
};


// Device

[
	coclass,
	//default(IDevice, _IDeviceEvents),
	default("IDevice"),
	threading(apartment),
	//support_error_info("IDevice"),
	//event_source(com),
	aggregatable(never),
	vi_progid("ATLServerTest2.Device"),
	progid("ATLServerTest2.Device.1"),
	version(1.0),
	uuid("AF76CC05-0F41-45EB-AE67-485FDD8AF343"),
	helpstring("Device Class")
]

class ATL_NO_VTABLE Device :
	public IDevice
{
public:
	Device()
	{
	}

	//__event __interface _IDeviceEvents;


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	STDMETHODIMP getName ( BSTR *name ) {
		CComBSTR _name ( "test name" );
		*name = _name.Detach();
		return S_OK;
	}
};

QuestionInserting Shapes into Excel from Clipbord Pin
Gokulan Venattil23-Mar-06 21:36
Gokulan Venattil23-Mar-06 21:36 
QuestionTaskBar Toolbar and Shell32.dll Pin
sherwani23-Mar-06 20:34
sherwani23-Mar-06 20:34 
QuestionUsing Internet Explorer DLL file Pin
Areff23-Mar-06 20:24
Areff23-Mar-06 20:24 
AnswerRe: Using Internet Explorer DLL file Pin
oykica23-Mar-06 20:59
oykica23-Mar-06 20:59 
QuestionEnterprise Library 2006 Pin
Brendan Vogt23-Mar-06 20:01
Brendan Vogt23-Mar-06 20:01 
AnswerRe: Enterprise Library 2006 Pin
oykica23-Mar-06 20:20
oykica23-Mar-06 20:20 
GeneralRe: Enterprise Library 2006 Pin
Brendan Vogt23-Mar-06 20:46
Brendan Vogt23-Mar-06 20:46 
Questionweb part manager not working with passport 3.1 Pin
samasavinirs23-Mar-06 19:25
samasavinirs23-Mar-06 19:25 
Question[Message Deleted] Pin
Jijo BP23-Mar-06 19:10
Jijo BP23-Mar-06 19:10 
AnswerRe: Check Connection Status Pin
deepthi wilson23-Mar-06 19:18
deepthi wilson23-Mar-06 19:18 
GeneralRe: Check Connection Status Pin
Jijo BP23-Mar-06 19:27
Jijo BP23-Mar-06 19:27 
AnswerRe: Check Connection Status Pin
deepthi wilson23-Mar-06 20:25
deepthi wilson23-Mar-06 20:25 
GeneralRe: Check Connection Status Pin
deepthi wilson23-Mar-06 20:31
deepthi wilson23-Mar-06 20:31 
AnswerRe: Check Connection Status Pin
deepthi wilson23-Mar-06 20:34
deepthi wilson23-Mar-06 20:34 
AnswerRe: Check Connection Status Pin
oykica23-Mar-06 20:35
oykica23-Mar-06 20:35 
GeneralRe: Check Connection Status Pin
Jijo BP23-Mar-06 21:10
Jijo BP23-Mar-06 21:10 
Questioninstalling .net 2.0 Pin
Mridang Agarwalla23-Mar-06 18:08
Mridang Agarwalla23-Mar-06 18:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.