Click here to Skip to main content
15,914,074 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: explain the arcticle Pin
virgo*11-Jul-05 8:27
virgo*11-Jul-05 8:27 
GeneralRe: explain the arcticle Pin
Dan Neely11-Jul-05 8:54
Dan Neely11-Jul-05 8:54 
GeneralRe: explain the arcticle Pin
Christian Graus11-Jul-05 13:11
protectorChristian Graus11-Jul-05 13:11 
GeneralGDIplus and text formatting Pin
ozuser7-Jul-05 2:58
ozuser7-Jul-05 2:58 
GeneralMail Server Project Pin
saood swar6-Jul-05 15:20
saood swar6-Jul-05 15:20 
GeneralRe: Mail Server Project Pin
Christian Graus6-Jul-05 17:00
protectorChristian Graus6-Jul-05 17:00 
Generalresgen.exe Pin
pcxboy6-Jul-05 14:08
pcxboy6-Jul-05 14:08 
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
Christian Graus6-Jul-05 11:35
protectorChristian Graus6-Jul-05 11:35 
GeneralRe: Please help - COM Interop Pin
metal_rob7-Jul-05 2:13
metal_rob7-Jul-05 2:13 
GeneralRe: Please help - COM Interop Pin
Christian Graus7-Jul-05 2:21
protectorChristian Graus7-Jul-05 2:21 
GeneralRe: Please help - COM Interop Pin
metal_rob7-Jul-05 2:51
metal_rob7-Jul-05 2:51 
GeneralRe: Please help - COM Interop Pin
Christian Graus7-Jul-05 13:11
protectorChristian Graus7-Jul-05 13:11 
GeneralRe: Please help - COM Interop Pin
Alomgir Miah11-Jul-05 8:29
Alomgir Miah11-Jul-05 8:29 
GeneralC1083 Error: Including .h files Pin
Anonymous6-Jul-05 7:53
Anonymous6-Jul-05 7:53 
GeneralRe: C1083 Error: Including .h files - Nevermind Pin
Anonymous6-Jul-05 8:12
Anonymous6-Jul-05 8:12 
Generalstandalone manifest Pin
CoolAmir5-Jul-05 21:26
CoolAmir5-Jul-05 21:26 
GeneralRe: standalone manifest Pin
MoustafaS7-Jul-05 2:50
MoustafaS7-Jul-05 2:50 
General.Net Memory Management Issue Pin
ge_anand5-Jul-05 7:49
ge_anand5-Jul-05 7:49 
GeneralRe: .Net Memory Management Issue Pin
Dave Kreskowiak5-Jul-05 9:35
mveDave Kreskowiak5-Jul-05 9:35 
GeneralRe: .Net Memory Management Issue Pin
[Marc]5-Jul-05 11:10
[Marc]5-Jul-05 11:10 
GeneralRe: .Net Memory Management Issue Pin
S. Senthil Kumar6-Jul-05 6:57
S. Senthil Kumar6-Jul-05 6:57 
GeneralRe: .Net Memory Management Issue Pin
[Marc]6-Jul-05 10:15
[Marc]6-Jul-05 10:15 
GeneralRe: .Net Memory Management Issue Pin
ge_anand6-Jul-05 20:26
ge_anand6-Jul-05 20:26 
GeneralSetup Issue Pin
waffleman5-Jul-05 0:07
waffleman5-Jul-05 0:07 

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.