Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

Calling a Delphi COM object from ASP?

I have the following ASP code to create my COM object:

    Dim objPal
    Dim aKey
    Response.Write("<p>")
    Set objPal = Server.CreateObject("VCTypeLib.VCAM")
    Response.Write("ok")
    aKey = objPal.LogOn("USER1", "PASSWORD")
    Response.Write(aKey)
    Response.Write("</p>")

This creates the COM object no problems, but I cannot then call any functions without getting the following error:

Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method

My thinking is that the VCTypeLib.VCAM relates to the Class GUID for my COM object, yet the interface with the functions on has a different GUID - so this could be why it cannot use the functions.

This is the first time I have tried to call a Delphi COM object from ASP, so any help would be most appreciated.
0
Greystoke
Asked:
Greystoke
  • 4
  • 3
  • 3
  • +3
3 Solutions
 
Peter_Commented:
Unless getting good answer, try posting to:
http://www.experts-exchange.com/Web/Web_Languages/ASP/ 
0
 
TomBigCommented:
hi greystoke

some more information about your delphi class would sure be helpful.

what class does it inherit from, did you use the delphi typelib editor, what does the _TLB file look like etc.

isn't the logon method implemented on your class ?

cheers
TomBig
0
 
andrewjbCommented:
You'll need to derive from IDispatch instead of just IUnknown in your COM objects..
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GreystokeAuthor Commented:
Hi there,

Thanks for the tips; here is the type library....

//******************************************************************************************************//

// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                      
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
  IID_IVCAM: TGUID = '{2684E893-409A-4C89-9AB3-927F4FAF7CD9}';
  IID_IVCAMInt: TGUID = '{7E3FC5F2-A2C7-41EE-88DD-EA631D40E875}';
  CLASS_VCAM: TGUID = '{153DF1C1-85D6-4F06-B5FB-D495AF1173AC}';


// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  IVCAM = interface;
  IVCAMDisp = dispinterface;
  IVCAMInt = interface;
  IVCAMIntDisp = dispinterface;



// *********************************************************************//
// Declaration of CoClasses defined in Type Library                      
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  VCAM = IVCAM;


// *********************************************************************//
// Interface: IVCAM
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {2684E893-409A-4C89-9AB3-927F4FAF7CD9}
// *********************************************************************//
  IVCAM = interface(IDispatch)
    ['{2684E893-409A-4C89-9AB3-927F4FAF7CD9}']
  end;

// *********************************************************************//
// DispIntf:  IVCAMDisp
// Flags:     (4416) Dual OleAutomation Dispatchable
// GUID:      {2684E893-409A-4C89-9AB3-927F4FAF7CD9}
// *********************************************************************//
  IVCAMDisp = dispinterface
    ['{2684E893-409A-4C89-9AB3-927F4FAF7CD9}']
  end;

// *********************************************************************//
// Interface: IVCAMInt
// Flags:     (320) Dual OleAutomation
// GUID:      {7E3FC5F2-A2C7-41EE-88DD-EA631D40E875}
// *********************************************************************//
  IVCAMInt = interface(IUnknown)
    ['{7E3FC5F2-A2C7-41EE-88DD-EA631D40E875}']
    function LogOn(const aUser: WideString; const aPass: WideString): WordBool; safecall;
  end;

// *********************************************************************//
// DispIntf:  IVCAMIntDisp
// Flags:     (320) Dual OleAutomation
// GUID:      {7E3FC5F2-A2C7-41EE-88DD-EA631D40E875}
// *********************************************************************//
  IVCAMIntDisp = dispinterface
    ['{7E3FC5F2-A2C7-41EE-88DD-EA631D40E875}']
    function LogOn(const aUser: WideString; const aPass: WideString): WordBool; dispid 201;
  end;

// *********************************************************************//
// The Class CoVCAM provides a Create and CreateRemote method to          
// create instances of the default interface IVCAM exposed by              
// the CoClass VCAM. The functions are intended to be used by            
// clients wishing to automate the CoClass objects exposed by the        
// server of this typelibrary.                                            
// *********************************************************************//
  CoVCAM = class
    class function Create: IVCAM;
    class function CreateRemote(const MachineName: string): IVCAM;
  end;

class function CoVCAM.Create: IVCAM;
begin
  Result := CreateComObject(CLASS_VCAM) as IVCAM;
end;

class function CoVCAM.CreateRemote(const MachineName: string): IVCAM;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_VCAM) as IVCAM;
end;

//******************************************************************************************************//

0
 
GreystokeAuthor Commented:
As you can see the COM class is derived from IDispatch but the interface from IUnknown and the methods are declared on the interface.

Is there any other info you require for a clearer picture?
0
 
DeerBearCommented:
Hi,

You can't - to my knowledge - derive an interface from IUnknown and dispatch it.
It MUST derive from IDispatch.

HTH,

Andrew
0
 
TomBigCommented:
hi greystoke

i'm a little bit confused here. the comments of DeerBear and andrewjb are of course correct. the interface you want to use from vb must ne dispatchable. but you got two interfaces: IVCAM and IVCAMInt. IVCAM is derived from IDispatch and IVCAMInt from IUnknown. But your LogOn method is declared on IVCAMInt and not on IVCAM.

so in my opinion, if your class implements IVCAM it should be creatable from VB, but not if it implements IVCAMInt. but then on IVCAM there is not a single method declared. so indeed, from vb's point of view the object does not support the method.

and if i'm rightt then

 Set objPal = Server.CreateObject("VCTypeLib.VCAM")

creates a object that implements IVCAM (with no method declared). What is IVCAMInt anyway ?

cheers
0
 
GreystokeAuthor Commented:
Hmm, ok so in VBScript you can only connect to interfaces derived from IDispatch - can you then not cast them??  

I don't think so, as I read somewhere that VBScript cannot read IUnknown interfaces - but if someone could confirm this I'd be grateful.


I'm guessing then, that if I place my functions on the IDispatch interface then these can be accessed no problem?
0
 
DeerBearCommented:
Hi,

VB can only see ONE specific IUnknown descendant, and that's IEnumVariant, for collection purpouses.

All the others can't be accessed, in VB you can't even "implements" them, because they're not listed.
HTH,

Andrew

P.S. I've been struggling with this for a month or so before understanding the
problem.
0
 
wedgepilotCommented:
VBScript is late binding, so you must use Dispatch interfaces. Like others have said, implement the functions in IVCAM instead of IVCAMInt and all should be well.
0
 
GreystokeAuthor Commented:
Hi,

Thanks for all the info - I have made up a mock COM object with methods on the IDispatch interface and it all works fine.

Now for the points allocation...

Although andrewjb gave the right answer initially, TomBig and DeerBear have helped more by providing more verbose comments.

I propose

andrewjb - 100
TomBig - 75
DeerBear - 75

How does that sound?
0
 
TomBigCommented:
Thats fine with me.
0
 
DeerBearCommented:
Ditto.

Andrew
0
 
andrewjbCommented:
ok
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now