473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Handling System._ComObject -- using CCW

Hi

I am calling .NET components from my Classical ASPs.
For this I strong named my assemblies, then registered them in the resistry
( using RegAsm), and put them in GAC (using GacUtil) .
Everything worked fine and my ASPs were able to call and use them.

The problem comes when my ASP code assigns an ASP object variable to a
property of a class in the assembly like:
oDotNetObject("Name") = Request("Name")
( where oDotNetObject is a class in my registered assembly )

The COM Callable Wrapper sends it as System._ComObject to .NET Runtime which
then throws exception as nothing is allowed on System._ComObject. On the
other hand, passing it as Variant solves the problem.
Dim varName = Request("Name")
oDotNetObject("Name") = varName

But this would require a significant change in my ASP pages. I want to
modify only my .NET components. Is there any way I can use this
System._ComObject in my managed code or any way I can make CCW to handle it.
I was trying to use System.Runtime.InteropServices.Marshal namespace to use
the System._ComObject I have not been able to do it.

Thanks in anticipation
Varun
Jul 19 '05 #1
2 4384
Thanks Oisin

But here my problem is that I am working on a huge application and I cant
change this usage in ASP files.
So I have to find a solution in .Net component -- as you said -- i will have
to marshal a com object
Any ideas about that!

Thanks
Varun

"Oisin Grehan" <oi****@nospam.iol.ie.> wrote in message
news:OF**************@tk2msftngp13.phx.gbl...
By assigning Request("Name") to the property, you are using a bad habit most of us have by relying on default properties. Take a look at this:

<%
Dim strName
strName = Request("Name")
%>

The ASP engine will assigning the default property (which happens to be
"Item") to the variable and everything will be fine. However, when you use:
oDotNetObject("Name") = Request("Name")

You are relying on the DotNet class to retrieve the default property from
the COM object "Request". If you use:

oDotNetObject("Name") = Request("Name").Item

Everything should be mostl likely be fine as you are not longer marshalling a COM object, but rather a simple string.

Hope this helps,

- Oisin

"Varun Singal" <va**********@induslogic.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
Hi

I am calling .NET components from my Classical ASPs.
For this I strong named my assemblies, then registered them in the

resistry
( using RegAsm), and put them in GAC (using GacUtil) .
Everything worked fine and my ASPs were able to call and use them.

The problem comes when my ASP code assigns an ASP object variable to a
property of a class in the assembly like:
oDotNetObject("Name") = Request("Name")
( where oDotNetObject is a class in my registered assembly )

The COM Callable Wrapper sends it as System._ComObject to .NET Runtime

which
then throws exception as nothing is allowed on System._ComObject. On the
other hand, passing it as Variant solves the problem.
Dim varName = Request("Name")
oDotNetObject("Name") = varName

But this would require a significant change in my ASP pages. I want to
modify only my .NET components. Is there any way I can use this
System._ComObject in my managed code or any way I can make CCW to handle

it.
I was trying to use System.Runtime.InteropServices.Marshal namespace to

use
the System._ComObject I have not been able to do it.

Thanks in anticipation
Varun


Jul 19 '05 #2
Varun, surely it is more work to facilitate this than to spend a while with
global find/replace with regex on those ASP files? Marshalling COM objects
instead of strings is hugely inefficient, incredibly lazy as well as just
plain wrong. But, if you really are a masochist (or an assembly
programmer -- same thing), keep reading:

First of all, I hope you're comfortable with COM interop, IDL, type
libraries and other such nasties. I'm not an interop specialist nor a COM
guru by any means, so I can only try to direct you. Right, since you're
passing in a System._ComObject object, I believe you'll need to use the
MarshalAs attribute to tell .NET that you're expecting
UnmanagedType.IDispatch. "Request" is an IDispatch object. If we inspect the
IDL with OleView (tool included with VS) by pointing it at the ASP type
library available at C:\Program Files\Microsoft Visual
Studio\Common\IDE\IDE98\asp.tlb assuming you've got Vstudio 6.0 installed in
the default location, you can see the following info (trimmed down for
brevity) for IRequest:

[odl, uuid(D97A6DA0-A861-11CF-93AE-00A0C90C2BD8), hidden, dual,
oleautomation]
interface IRequest : IDispatch {
[id(00000000), propget]
HRESULT Item([in] BSTR bstrVar, [out, retval] IDispatch** ppObjReturn);

HRESULT QueryString([out, retval] IRequestDictionary** ppDictReturn);
HRESULT Form([out, retval] IRequestDictionary** ppDictReturn);
};

You'll see that Item is the default property (IDL id of 0), it returns an
IDispatch interface, most likely this one in your case:

[odl, uuid(D97A6DA0-A85F-11DF-83AE-00A0C90C2BD8), helpstring("Dictionary for
Request collections"), hidden, dual, oleautomation]
interface IRequestDictionary : IDispatch {
[id(00000000), propget]
HRESULT Item([in, optional] VARIANT Var, [out, retval] VARIANT*
pVariantReturn);
};

Again, you can see the default property for the IRequestDictionary is Item
also, which returns a variant. This is the variant you need to get your
grubby hands on. All the information you'll need to imbibe and understand is
on MSDN. A good place to start is to look up the MarshalAs attribute and
pay attention to the UnmanagedType enumeration. There's some good example
code there.

Now, if this hasn't put you off, you plainly have access to the ASP
source -- is it really that huge a task to change it? Open all ASP pages in
VS.NET, use Find/Replace with Regular Expressions. Replace .*
\=\s?Request\("{.*}\"\) with = Request("\1").Item. Bingo, assuming that
Regex expression out of my head is correct. If you have the time, sit back
and learn COM interop. If that looks like too steep a hill to climb, change
the ASP pages, or better yet, learn Regular Expressions. It'll be the best
hour you've spend in front of the computer today and it will pay you back
many times over.

Hope this helps,

- Oisin



"Varun Singal" <va**********@induslogic.com> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
Thanks Oisin

But here my problem is that I am working on a huge application and I cant
change this usage in ASP files.
So I have to find a solution in .Net component -- as you said -- i will have to marshal a com object
Any ideas about that!

Thanks
Varun

"Oisin Grehan" <oi****@nospam.iol.ie.> wrote in message
news:OF**************@tk2msftngp13.phx.gbl...
By assigning Request("Name") to the property, you are using a bad habit

most
of us have by relying on default properties. Take a look at this:

<%
Dim strName
strName = Request("Name")
%>

The ASP engine will assigning the default property (which happens to be
"Item") to the variable and everything will be fine. However, when you

use:

oDotNetObject("Name") = Request("Name")

You are relying on the DotNet class to retrieve the default property from the COM object "Request". If you use:

oDotNetObject("Name") = Request("Name").Item

Everything should be mostl likely be fine as you are not longer

marshalling
a COM object, but rather a simple string.

Hope this helps,

- Oisin

"Varun Singal" <va**********@induslogic.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
Hi

I am calling .NET components from my Classical ASPs.
For this I strong named my assemblies, then registered them in the

resistry
( using RegAsm), and put them in GAC (using GacUtil) .
Everything worked fine and my ASPs were able to call and use them.

The problem comes when my ASP code assigns an ASP object variable to a
property of a class in the assembly like:
oDotNetObject("Name") = Request("Name")
( where oDotNetObject is a class in my registered assembly )

The COM Callable Wrapper sends it as System._ComObject to .NET Runtime

which
then throws exception as nothing is allowed on System._ComObject. On the other hand, passing it as Variant solves the problem.
Dim varName = Request("Name")
oDotNetObject("Name") = varName

But this would require a significant change in my ASP pages. I want to
modify only my .NET components. Is there any way I can use this
System._ComObject in my managed code or any way I can make CCW to
handle it.
I was trying to use System.Runtime.InteropServices.Marshal namespace
to use
the System._ComObject I have not been able to do it.

Thanks in anticipation
Varun



Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
2
by: Varun Singal | last post by:
Hi I am calling .NET components from my Classical ASPs. For this I strong named my assemblies, then registered them in the resistry ( using RegAsm), and put them in GAC (using GacUtil) ....
4
by: m96 | last post by:
hi, i'm trying to make a query to a ldap server (version v2 or v3 doen't matter) with c#. the query works just fine but the problem is that i can't read the custom attributes/fields, since .net...
4
by: aaj | last post by:
Hi all I have an automated application, that runs in the middle of the night. If certain 'non system' errors occur (things like malformed files, missing files etc..), I send an automatic Email...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
16
by: Chuck Cobb | last post by:
I'm implementing a centralized exception handling routine using the Enterprise Library Exception Management Application Block. I trap all unhandled exceptions to one place using the following...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
0
by: sandy | last post by:
I have a AxWebBrowser class. I wish to locate a specific element in its HTMLDocument which has a specific 'style'. I use the following code to access the element with the specific style:- ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.