Is there anything special I need to do in c# to make my code com compatible

H

Hasani

The reason I ask this is because I'm having problems accessing an array of
type TrackSelection in a VBS script I'm using to test my code.

item.AdditionalInformation returns an array of type TrackSelection. I don't
know what I'm doing wrong. All the classes (that I need for COM) seem to
follow the requirements for COM interop.

Code for Item -> http://www.skidmore.edu/~h_blackw/Item.cs
Code for TrackSelection ->
http://www.skidmore.edu/~h_blackw/TrackSelection.cs

******CODE******

Set comObj = CreateObject("iCode.Interop.ComInterop")
Set item = comObj.ItemFromItemCode("KV35S42")
Set tracks = item.AdditionalInformation

******Error*****

Windows Script Host
Line: 3
Char: 1
Error: Object required
Code: 800A01A8
Source: Microsoft VBScript runtime error


I've been fooling around with this for the last 5 hrs or so, any help will
be appreciated!!!!
 
D

Daniel Bass

a good read would be MSDN's c# tutorials. There's two there to do with
interop that'll solve what you're trying to do.

vbscript is trying to access an unmanaged COM object, but your c#
compilation is .NET...
you need to use the regasm command line tool (with .net) to create a bridge
layer, allowing "unsafe" clients to communicate with the .net DLL.

good luck!
Dan.

The reason I ask this is because I'm having problems accessing an array of
type TrackSelection in a VBS script I'm using to test my code.

item.AdditionalInformation returns an array of type TrackSelection. I don't
know what I'm doing wrong. All the classes (that I need for COM) seem to
follow the requirements for COM interop.

Code for Item -> http://www.skidmore.edu/~h_blackw/Item.cs
Code for TrackSelection ->
http://www.skidmore.edu/~h_blackw/TrackSelection.cs

******CODE******

Set comObj = CreateObject("iCode.Interop.ComInterop")
Set item = comObj.ItemFromItemCode("KV35S42")
Set tracks = item.AdditionalInformation

******Error*****

Windows Script Host
Line: 3
Char: 1
Error: Object required
Code: 800A01A8
Source: Microsoft VBScript runtime error


I've been fooling around with this for the last 5 hrs or so, any help will
be appreciated!!!!
 
H

Hasani

well, while I read the stuff in the link (which is a lot)
can you at least tell me how I can return objects derived from System.Array
to COM or how to return an ArrayList to COM?
 
D

Daniel Bass

That there is I suppose, but the question you posed doesn't warrant a short
solution, from the stand point it would be more beneficial to understand
more about what you're trying to do.

With regards your arraylist question, I'm unaware of an ArrayList structure
existing outside the .Net framework? This means what would be required is a
conversion to a more generic (or unmanaged) state. Rather than passing out a
defined .Net structure. So ArrayList myArray would be better as Int[1024]
aryintMyArray.

I don't really understand all the in's and out's of it all, but found the
submitted articule useful in providing the info required to accomplish what
you were trying to do, fulfilling your "any help will be appreciated!!!!"
request.

i recommend email Jon Skeet, ( http://www.pobox.com/~skeet ) who is on this
forums a lot, and seems to know a lot, more, if you require more assitance.

best of luck.
Dan.

well, while I read the stuff in the link (which is a lot)
can you at least tell me how I can return objects derived from System.Array
to COM or how to return an ArrayList to COM?
 
J

Jon Skeet [C# MVP]

i recommend email Jon Skeet, ( http://www.pobox.com/~skeet ) who is on this
forums a lot, and seems to know a lot, more, if you require more assitance.

Unfortunately I know precious little about COM - I know basically the
*exact* amount I've absolutely *had* to learn in order to do what I've
needed to do.

Asking a question in the microsoft.public.dotnet.framework.interop
newsgroup is *much* more likely to get a satisfactory response, however
:)
 
D

Daniel Bass

and I thought you knew everything!?!?

I'm busy trying to write the COM.Interop way for instantiating an MMC
Snap-In, it's luvly. ;op

Dan.


i recommend email Jon Skeet, ( http://www.pobox.com/~skeet ) who is on this
forums a lot, and seems to know a lot, more, if you require more
assitance.

Unfortunately I know precious little about COM - I know basically the
*exact* amount I've absolutely *had* to learn in order to do what I've
needed to do.

Asking a question in the microsoft.public.dotnet.framework.interop
newsgroup is *much* more likely to get a satisfactory response, however
:)
 
H

Hasani

Yesterday, I did come across (How Do I...Pass an Array From .NET Code to VB6
Code)
http://samples.gotdotnet.com/quickstart/howto/doc/Interop/TestServer_2.aspx
Now, I just copied and pasted it as:

public interface ITest
{
Int32[] GetArray();
}

public class Test : ITest
{
public Test()
{
}

public Int32[] GetArray()
{
Int32[] int32Array = {0,1,2,3,4,5,6,7,8,9};
return int32Array;
}
}

and the vbs code looks like

Set tst = CreateObject("iCode.Test")
Dim teh
teh = tst.GetArray()
Dim mer
mer = IsArray(teh)
MsgBox mer, , "VBS test"

I get a message box with saying "TRUE" which means that GetArray succesfully
returned an array. At this point, I have not clue how to access it
I tried doing teh(1) and I get "Type mismatch" error when I add the lines

Dim valz
valz = teh(1)

to the end.

Man, all I wanna do is access my .net library code from asp. =(


Daniel Bass said:
That there is I suppose, but the question you posed doesn't warrant a short
solution, from the stand point it would be more beneficial to understand
more about what you're trying to do.

With regards your arraylist question, I'm unaware of an ArrayList structure
existing outside the .Net framework? This means what would be required is a
conversion to a more generic (or unmanaged) state. Rather than passing out a
defined .Net structure. So ArrayList myArray would be better as Int[1024]
aryintMyArray.

I don't really understand all the in's and out's of it all, but found the
submitted articule useful in providing the info required to accomplish what
you were trying to do, fulfilling your "any help will be appreciated!!!!"
request.

i recommend email Jon Skeet, ( http://www.pobox.com/~skeet ) who is on this
forums a lot, and seems to know a lot, more, if you require more assitance.

best of luck.
Dan.

well, while I read the stuff in the link (which is a lot)
can you at least tell me how I can return objects derived from System.Array
to COM or how to return an ArrayList to COM?
Daniel Bass said:
check out the Interop tutorials on this page.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcoriCSharpTutorials.asp
 
H

Hasani

OK, I think I got it to work by making my methods that return arrays return
object[] instead of whatever derived class they were originally returning.
Gonna be a suck though because I gotta modify like 30 classes =/
I got some insight in a reply from Alex @ msft.pub.scripting.vbscript
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top