If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Types registered successfully
Type library exporter warning processing 'POAHandler.POA_serviceref.POAServiceCl
ient, POAHandler'. Warning: Type library exporter encountered a type that derive
s from a generic class and is not marked as [ClassInterface(ClassInterfaceType.N
one)]. Class interfaces cannot be exposed for such types. Consider marking the t
ype with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit inte
rface as the default interface to COM using the ComDefaultInterface attribute.
Assembly exported to 'C:\SSRoot\FaellesIndbetaling\Common\POAHandler\POAHandler\
poahandler.tlb', and the type library was registered successfully

And when I try to import things in my c++ project, it claims that it knows nothing about my class or interface.

I had a webservice that I call from Csharp, and I would then make the Csharp code into something that can (also) be accessed using COM. Since I can see, that calling Csharp code from C++ can be a pain, I made a C++ class (also COM) that all the C++ projects can use.

Re: Accessing managed dll from c++

I've tested a little more, and found that the problem isn't only with the C# code.
I removed the call to the webservice, and just let my function return true all the time. I recompiled, and this time it appeared that there was no problems when registering. However, when I tried to compile in C++, it kept claiming that the namespace for my C# doesn't exist...

Re: Accessing managed dll from c++

Ah...it seems that what it is really nagging about is that it doesn't like the service reference in the Csharp project, apparently because it doesn't have [ClassInterface(ClassInterfaceType.None)]

I see. So, using COM as such is not the problem. BTW, I started writing post #6 before your post #4 arrived, so I hadn't already seen it at that point.

Except for the using declaration right at the top of your C# snippet, I don't see any reference to POA_serviceref in the code you posted at all, so I have no idea what its signature is. Is there any concrete need to expose it to COM at all? The usual reason why you get that warning from tlbexp is that the offending type simply can't be represented in terms of COM, so exposing it as-is probably is not of much use anyway. If you simply applied [ComVisible(true)] at assembly scope and POA_serviceref (which I assume is a class) just inherited that, then explicitly applying [ComVisible(false)] to it would be the simple natural solution.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Re: Accessing managed dll from c++

Originally Posted by Lars_V_J

I've tested a little more, and found that the problem isn't only with the C# code.
I removed the call to the webservice, and just let my function return true all the time. I recompiled, and this time it appeared that there was no problems when registering. However, when I tried to compile in C++, it kept claiming that the namespace for my C# doesn't exist...

Well, it's all C# whatever you think of the situation. Once C++ claims there's no namespace, regasm has registered your dll without any COM compatible types. Please inspect the .tlh file that .tlb ultimately compiles to (or open the .tlb with oleview and see if the library entry is really there, i.e. TLB is not void). In case the header contains no namespace named by assembly name at all, the problem is C#. In case it does have the namespace (and the content is essentially what you need), please make sure your C++ sources reference proper namespace.

Re: Accessing managed dll from c++

I've checked the generated tlh file, and it does include the correct namespace. (Starts out with namespace PoaHandler {)
I start the cpp file with
#import "..\poahandler\poahandler\poahandler.tlb" raw_interfaces_only

Re: Accessing managed dll from c++

Doh...upper/lower case problem.

Now I get a number of other errors. The mentioned line 107 is:
IPOA_Handler pPOA(__uuidof(POA_Handler));

I dont have a problem later in the code, when I try to make a call to one of the member functions.
pPOA.CreatePoaJob((unsigned short*)"DTPFIR", (unsigned short*)"FBA siger Hello World CPR, CVR, ForsNr", (unsigned short*)"Test Opgave fra FBA", (unsigned short*)"1504650258",
(unsigned short*)"12121212",(unsigned short*)"94-123456", (short*)&lResult);
That line is okay.