[.net] Error accessing C# app from VBScript

Started by
4 comments, last by adammil2000 18 years, 7 months ago
Hi all, I am experimenting with scripting a .NET Game using external VBScripts. However, when I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set o=getobject(,"ConsoleApplication2.Program") msgbox o.TestString And here's my C# application that's running when I try to access it from VbScript: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication2 { public class Program { public string TestString = "testing 123"; static void Main(string[] args) { Console.ReadLine(); } } }
Advertisement
Your C# program needs to be registered for COM Interop in order to do what you are trying to do.

Why would you want to "script a .NET game" in this way? If you are interested in games built on top of scripting, and want to use .NET, there are some articles around on how to use C# as the scripting language for a game engine.

Thanks for the info.

I want any script like Python, VbScript, Java, etc. to be able to control the game engine. .NET is not the core focus, it just happens to be that I like to write the core code in C#, then let other folks extend and control the engine with whatever script they want.

I personally wanted to start working with VBScript and go from there.
One additional question: I searched the Web based on your feedback and found more info about regasm, but it seems to only want DLLs to register. My program has no DLLs, it's just an EXE. What would the process be to register it for COM interop?

Please pardon my ignorance here.

Thanks!

Well, the obvious thing to do is split the application into an executable part and a dll...

Cheers
I now have it working, partially.

I can use CreateObject and create and then control the new instance of the C# game engine with VBScript. However, I cannot use an already running instance of the game engine using GetObject.

What I am trying to do is the same as when you control an instance of MS Word with VBScript using GetObject(,"Word.Application"). This command doesn't actually start Word, but instead uses the instance that's already open and running.

What I changed to get it working this far was to use the System.Runtime.InteropServices namspace, the [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] and [ClassInterface(ClassInterfaceType.None)] tags, and created a new interface with the same name as the class and that begins with an underscore (class interface) and did the regasm /tlb option.

This is the last obstacle for me and I assume I am still doing something wrong.

Thanks in advance for any ideas.

[Edited by - adammil2000 on August 29, 2005 2:31:23 AM]

This topic is closed to new replies.

Advertisement