Solved

Calling a Delphi COM object from ASP?

Posted on 2003-11-18
14
594 Views
Last Modified: 2013-11-23
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
Comment
Question by:Greystoke
  • 4
  • 3
  • 3
  • +3
14 Comments
 
LVL 3

Expert Comment

by:Peter_
Comment Utility
Unless getting good answer, try posting to:
http://www.experts-exchange.com/Web/Web_Languages/ASP/
0
 
LVL 1

Expert Comment

by:TomBig
Comment Utility
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
 
LVL 12

Accepted Solution

by:
andrewjb earned 100 total points
Comment Utility
You'll need to derive from IDispatch instead of just IUnknown in your COM objects..
0
 

Author Comment

by:Greystoke
Comment Utility
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
 

Author Comment

by:Greystoke
Comment Utility
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
 
LVL 5

Expert Comment

by:DeerBear
Comment Utility
Hi,

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

HTH,

Andrew
0
 
LVL 1

Assisted Solution

by:TomBig
TomBig earned 75 total points
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Greystoke
Comment Utility
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
 
LVL 5

Assisted Solution

by:DeerBear
DeerBear earned 75 total points
Comment Utility
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
 
LVL 1

Expert Comment

by:wedgepilot
Comment Utility
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
 

Author Comment

by:Greystoke
Comment Utility
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
 
LVL 1

Expert Comment

by:TomBig
Comment Utility
Thats fine with me.
0
 
LVL 5

Expert Comment

by:DeerBear
Comment Utility
Ditto.

Andrew
0
 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
ok
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now