VB script and COM - com

I want to call certain functions of a COM component from ASP. I would like to know
How can I create a COM object?.
How can I use VARIANTS to pass to the COM object?
Can I pass reference parameters from ASP to COM object?
What are the limitations of passing reference objects to COM?
Where would I get more information about this?

How can I create a COM object?.
Use the CreateObject function
Set Obj = CreateObject("COMProgID")
How can I use VARIANTS to pass to the COM object?
VBScript has only one data type called a Variant.
Can I pass reference parameters from ASP to COM object?
Yes.
What are the limitations of passing reference objects to COM?
I got lost with this one...

Related

COM-class without being able to instantiate

MSDN:
"You implement an IClassFactory interface for each (COM) class of object that you offer to be instantiated."
Is it useful to create COM class without Class Factory?
The IClassFactory is provided for objects which are instantiated directly by the caller, for example using CreateObject or CoCreateInstance, or GetObject.
Other objects can be obtained by getting them indirectly from objects that are created.
For example, the Scripting.FileSystemObject in VB or VBScript is created directly. You can use the methods to obtain File or Folder objects, which cannot be directly created. Instead these are created by the FileSystemObject and returned from FileSystemObject methods.
Is it useful to create COM class without Class Factory?
Yes, why not? It can still be fully featured COM class, just except that you cannot launch it via CoCreateInstance API. For some reason you might want to make it available otherwise, e.g. as a returned [out] parameter on a method of another interface/class, or via GetActiveObject API.
Class factories let you expose your class for direct instantiation.
I'm not entirely sure the wording is quite correct here. You almost always implement IClassFactory once for all COM classes of objects that your host will instantiate. In particular, your implementation of IClassFactory is what gets returned from DllGetClassObject.
In particular, when someone calls CoCreateInstance(CLSID_foo, pUnkOuter, CLSCTX_INPROC, IID_IFoo, (void **) &pFoo), the following things happen (assuming you're not doing remoting):
COM looks up CLSID_foo in the registry. (In particular, HKEY_CLASSES_ROOT\CLSID\\InprocServer32).
COM loads that DLL and calls DllGetClassObject with IID_IClassFactory.
Your DLL returns a function pointer to the implementation of IClassFactory.
COM calls your implementation of IClassFactory::CreateInstance with pUnkOuter, IID_IFoo, and pFoo.
There are many other situations where you would have COM objects that aren't directly creatable, as #Ben mentioned. There are even other standard factory interfaces, like IServiceProvider, that exist so that classes can expose a dynamic set of interfaces.

COM Object vs Automation Object

I am creating a COM Object in Delphi XE2. I am trying to create the methods using safecall, but the default is stdcall.
When i use Automation Object is possible to use safecall.
For performance questions, i am using COM Object. Is it possible to use safecall on it?
Thanks
Yes, you can use safecall convention.
The only difference between safecall and stdcall is that safecall is suitable for exception-driven flow. That is, if your Delphi function is safecall, it can raise an exception, which will be catched internally and translated to the proper HRESULT.
By the way, there's no performance benefit with COM Object vs Automation object: although an Automation object supports the slower "late binding" via IDispatch interface, its clients are not obliged to use it. Clients, which are able to use "early binding", can use it with Automation objects as well.

Which DLL do I need to reference for an LDAP COM object?

I know it's a bit old school, but I have to translate an LDAP function written in VB (Visual Basic not .net). And using managed code I can't produce the same result.
To solve the problem quickly I would like to use COM (Component Object Model) exactly as the Visual Basic function is doing like this:
set dso=GetObject("LDAP:")
I'm completely out of practice with COM, what DLL would I need to include as a reference to make it work?
I believe Marshal.GetActiveObject is the equivalent to the VB GetObject call you are used to using.
This will return you the object, you then need to either:
Reference an interop assembly with the type definitions for your LDAP object
Make the calls to the object using reflection invoke
Use the dynamic keyword in C# 4.0 to make the calls to the object using a late bound mechanism, similar to what VB did
I recommend using option 3 if you are using .Net 4.0

Use a COM object in .NET 2.0 CF without calling CreateObject

I need to use a COM object in my .NET 2.0 compact framework project, but I can't use the CreateObject function. Is there any other way to call a COM object that will work in my environment?
You'll need to call CoCreateInstance(). You can find a P/Invoke declaration for it here. If you only have a ProgID then you need to call CLSIDFromProgID() first. Make sure you've exhausted all possibilities of finding a type library for the COM server (Tlbimp.exe), this kind of code isn't easy to get right.

how to use a method inside a com dll into C#?

how to use a method inside a com dll into C# ?
Best way to access COM objects from C#
Add a reference to the com dll and .net will automatically give a wrapper class and by using that you can call functions inside the dll.