Re: Trying to use unmanaged with C#




"Patrick Steele" <patrick@xxxxxxxx> wrote in message
news:MPG.20354b8b5589ecee9896ee@xxxxxxxxxxxxxxxxxxxxxxx
In article <uLirTZ5SHHA.3592@xxxxxxxxxxxxxxxxxxxx>,
EdisonCPP@xxxxxxxxxxxxxxxxx says...
Looking back, I probably didn't clarify very well that
the origianl COM obj is unmanaged, and I'm trying
to use it in a managed environment.

Sorry Steve. Looking back at your original post, I do see that you're
consuming a COM object, not trying to create one in .NET. Sorry about
that.

However, as part of the COM interface, do you need to pass a reference
of a .NET object to COM? And you're doing this from an ASP.NET app?


It only became the need to be a .NET object when I "imported" it into my
managed app. Originally it was a pointer to an IUnknown implemented
class instance that would be a callback. Yes, it is ASP.NET.
The actual object is a front end for communications with a server app.
The object houses all the protocol for clients. So instead of sending
all the socket protocol to login you can simply:
pObj->Authenticate(name, pword);
And then ask questions of the server app:
pObj->GiveMeAllTheseItems((IUnkwown*)pWhereToSendResults,
PassThruPointer/*so you can do something with results*/);

The new site needs talk to this server, and the historical way we've talked
to it through numberous apps, is this COM object. The methods house
very lengthy protocol and error checking, that are proven and solid.

First off, I'm no ASP.NET expert, but I think you might have some
security issues running a COM object from inside ASP.NET since COM is
unmanaged. I think the default security for ASP.NET is to not allow
unmanaged execution of code.

Would you think this still be an issue since when I referenced it - it
created a
managed dll like: bin/Interop.MyLib.dll?
BTW, it seems up until this callback the COM object is operating correctly.
I can:
pObject.Connect(IP, port);
pObject.Authenticate(name, pword);
//etc..
It's just when the COM object tries to QueryInterface() internally on
the class instance I created within C# that it throws an exception.


Second, if you *do* need to pass a reference of some .NET class to a COM
object, then you'll need to make sure your assembly which contains this
class is marked as COM visible. It looked like you made your class COM
Visible via the ComVisible attribute, but the assembly (the "parent" in
the hierarchy defined in the error message) defaults to COM visible
false.

How can I make it be ComVisible(true) when it converts it to a managed
assembly?


What I would do is create a class library that does what you need
(interact with the COM object) and get that debugged and working outside
ASP.NET. Then just add a reference to that class library inside your
ASP.NET application once everything is working.


I'll give this a try. Create a managed class library assembly that
references
the comm object? Then reference this new assembly in a test app, but
eventually
in the ASP.NET pages? It would strike me that very quickly I will run into
the
same Query problems with the callback implementation.

The end goal is to ask an unmanged C++ Windows Service questions, get
answers,
and have it do things. The unmanaged COM object can do this now, wrapping
all the lengthy protocol and error checking.

--
Patrick Steele
http://weblogs.asp.net/psteele


.



Relevant Pages

  • Re: How do I find the Path for Win.Word?
    ... For example, Bryan's reply to your original message was bottom-posted, meaning he quoted your message and wrote his reply UNDER what he quoted. ... You *should* be OK with a reference to Word 10 and your app being run on a system with Word 11 installed. ... I've written many little apps and even quite large apps that use Automation with various Office products and I've had VERY few problems with those apps working when a different version of Office is installed. ... However, in almost all of these, it's because they've developed using a later version of Office and uses features specific to that version, and then the app doesn't work with an earlier version of Office. ...
    (microsoft.public.vb.general.discussion)
  • Re: Visual Basic Ver 6.0 - Word 2003
    ... able to reference the 9.0 object library (on your dev PC if it has Word 2000 ... installed) and your app should work on a target PC even if Office 2003 is ... installed on the target PC. ... I think you need to pinpoint the line of code causing the error. ...
    (microsoft.public.vb.general.discussion)
  • Re: Access 2000 Find Inbox at Runtime
    ... We have the Access 2000 developers edition and have distributed a few ... The PDM that is supplied with ODE is NOT a great piece of Kit. ... >up the app and not allowing the users in the app at all. ... >You'll want to install the reference if you are programming or debugging and want to ...
    (microsoft.public.outlook.general)
  • Re: Access 2000 Find Inbox at Runtime
    ... We have the Access 2000 developers edition and have distributed a few ... The PDM that is supplied with ODE is NOT a great piece of Kit. ... >up the app and not allowing the users in the app at all. ... >You'll want to install the reference if you are programming or debugging and want to ...
    (microsoft.public.outlook.program_vba)
  • Re: Access 2000 Find Inbox at Runtime
    ... We have the Access 2000 developers edition and have distributed a few ... The PDM that is supplied with ODE is NOT a great piece of Kit. ... >up the app and not allowing the users in the app at all. ... >You'll want to install the reference if you are programming or debugging and want to ...
    (microsoft.public.outlook.interop)