473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4394
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
3188
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
5969
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
2
336
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
27921
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
2517
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
2216
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
2520
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
13525
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
1602
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
7265
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
7388
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,...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.