Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Feedback from a form Pin
Carl-Johan Larsson6-Jul-05 18:48
Carl-Johan Larsson6-Jul-05 18:48 
GeneralPowerCollections 1.0 is released Pin
Kevin McFarlane6-Jul-05 9:53
Kevin McFarlane6-Jul-05 9:53 
GeneralRe: PowerCollections 1.0 is released Pin
Judah Gabriel Himango6-Jul-05 10:57
sponsorJudah Gabriel Himango6-Jul-05 10:57 
GeneralFind user & password in Access DB. Pin
sea#6-Jul-05 9:30
sea#6-Jul-05 9:30 
GeneralRe: Find user & password in Access DB. Pin
Guffa6-Jul-05 11:17
Guffa6-Jul-05 11:17 
GeneralRe: Find user & password in Access DB. Pin
malharone6-Jul-05 13:13
malharone6-Jul-05 13:13 
GeneralRe: Find user & password in Access DB. Pin
Matt Gerrans7-Jul-05 10:57
Matt Gerrans7-Jul-05 10:57 
GeneralPlease help - COM Interop Pin
metal_rob6-Jul-05 8:44
metal_rob6-Jul-05 8:44 
Hey everyone, a quick thanks for taking a look at this...

Basically, my problem is this... I have a "Core" library which contains a "Manager" component, and I want to use this component in C#. This component is written in C++, and here is the IDL file defining its type library.

<br />
import "unknwn.idl";<br />
<br />
[<br />
object,<br />
uuid(822A2EDE-09F1-45b8-B80E-A32F21415677),<br />
helpstring("Interface used by the Manager")<br />
]<br />
<br />
interface IManager : IUnknown<br />
{<br />
	HRESULT GetAppName([out, size_is(, *pcMax)] char **ppAppName,<br />
						   [out] long *pcMax);<br />
<br />
	HRESULT	SetStatus([in] long cLength,<br />
				   [in, size_is(cLength)] char* id,<br />
				   [in] int s);<br />
};<br />
<br />
[<br />
uuid(AE068C74-0B8B-4041-8CA9-4A590DDDC382),<br />
helpstring("Core Component Library")<br />
]<br />
library Core<br />
{<br />
	importlib("stdole32.tlb");<br />
	importlib("stdole2.tlb");<br />
	<br />
	interface IManager;<br />
}<br />



Now, if I write a C++ app to use this component, doing this, it works great...
(Keep in mind, the component is registered in the registry and the DLL creates an instance of the component by using IClassFactory)
<br />
#include "stdafx.h"<br />
#include <objbase.h><br />
#import "Core.tlb"<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
	HRESULT hr = NULL;<br />
	CLSID clsid;<br />
<br />
	::CoInitialize(NULL);<br />
<br />
	Core::IManager* pManager;<br />
	hr = CLSIDFromProgID(OLESTR("Core.1"), &clsid);<br />
<br />
	if(FAILED(hr))<br />
	{<br />
	     cout << "DLL not installed correctly" << endl;<br />
	}<br />
<br />
	hr = ::CoCreateInstance(clsid, NULL, <br />
                 CLSCTX_ALL, __uuidof(Core::IManager), (void** )&pManager);<br />
<br />
<br />
	if(SUCCEEDED(hr))<br />
	{<br />
		cout << "Found component!" << endl;<br />
<br />
        }<br />
}<br />


No problem, it executes just fine, my C++ app easily uses the component.


Now, I try importing "Core.tlb" into .NET, by using tlbimp.exe, I get a useless managed assembly... After pouring through MSDN article after MSDN article, I've come to the conclusion that its possible to create a COM class wrapper? However, I've had no luck with that as well... This is all I've been able to come up with, but I know it doesn't work...


<br />
namespace Core<br />
{<br />
	[Guid("822A2EDE-09F1-45b8-B80E-A32F21415677"),<br />
		InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]<br />
	interface IManager<br />
	{<br />
		void GetAppName(<br />
			[Out, MarshalAs(UnmanagedType.BStr)] string strAppname,<br />
			[Out] int maxSize);<br />
<br />
		void SetTestPointStatus(<br />
			[In] int MaxLength,<br />
			[In, MarshalAs(UnmanagedType.BStr)] string id,<br />
			[In] int status);<br />
	}<br />
<br />
	[ComImport, Guid("AE068C74-0B8B-4041-8CA9-4A590DDDC382")]<br />
	class CManager<br />
	{<br />
	}<br />
}<br />



Anyone have any suggestions? I've come to the conclusion that I really have no idea what I'm doing in C# as far as interop goes, I'm not a bad C# coder, but this just escapes me at the moment...


Anyway, thanks again for reading this Smile | :)
GeneralRe: Please help - COM Interop Pin
mav.northwind6-Jul-05 22:43
mav.northwind6-Jul-05 22:43 
GeneralRe: Please help - COM Interop Pin
metal_rob7-Jul-05 2:15
metal_rob7-Jul-05 2:15 
GeneralRe: Please help - COM Interop Pin
mav.northwind7-Jul-05 11:06
mav.northwind7-Jul-05 11:06 
Generalclosing the form with the [x] button Pin
marazm16-Jul-05 8:25
marazm16-Jul-05 8:25 
GeneralRe: closing the form with the [x] button Pin
LongRange.Shooter6-Jul-05 9:26
LongRange.Shooter6-Jul-05 9:26 
GeneralDatabase question Pin
Tom Wright6-Jul-05 8:20
Tom Wright6-Jul-05 8:20 
GeneralRe: Database question Pin
Anonymous6-Jul-05 8:29
Anonymous6-Jul-05 8:29 
GeneralRe: Database question Pin
Tom Wright6-Jul-05 8:46
Tom Wright6-Jul-05 8:46 
GeneralRe: Database question Pin
Luis Alonso Ramos6-Jul-05 8:54
Luis Alonso Ramos6-Jul-05 8:54 
GeneralRe: Database question Pin
Guffa6-Jul-05 9:01
Guffa6-Jul-05 9:01 
GeneralRe: Database question Pin
Tom Wright7-Jul-05 11:09
Tom Wright7-Jul-05 11:09 
GeneralRe: Database question Pin
Guffa7-Jul-05 12:29
Guffa7-Jul-05 12:29 
GeneralDelete Button in Datagrid Pin
just4ulove76-Jul-05 7:29
just4ulove76-Jul-05 7:29 
GeneralObject reference not set to an instance of an object. Pin
Member 20541716-Jul-05 6:49
Member 20541716-Jul-05 6:49 
GeneralRe: Object reference not set to an instance of an object. Pin
Guffa6-Jul-05 6:57
Guffa6-Jul-05 6:57 
GeneralRe: Object reference not set to an instance of an object. Pin
Member 20541716-Jul-05 7:13
Member 20541716-Jul-05 7:13 
GeneralRe: Object reference not set to an instance of an object. Pin
Guffa6-Jul-05 7:28
Guffa6-Jul-05 7:28 

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.