Solved

C++ COM Method with Optional Arguments

Posted on 2004-10-14
8
448 Views
Last Modified: 2013-11-25
Hi,

I am trying to produce a COM object in Visual C++, where one of the methods accepts optional arguments. Below are the interface declaration, the class implementing the interface, and the implementation of the method taking an optional argument. As it stands, it compiles. But when I try to call the function from an ASP page using VBS with the supposedly optional parameter missing, I get the following error


Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'CopyFile'


So the optional attribute seems to be completely ignored.

Any help would be much appreciated.

Here is the code

[uuid("0ab5a3d0-e5b6-11d0-abf5-00a0c90fffc0"),dual]
__interface IFileSystem : IDispatch
{
      [id(0x4b2)] HRESULT __stdcall CopyFile (
        [in] BSTR Source,
        [in] BSTR Destination,
        [in, optional] VARIANT OverWriteFiles );
};



[
  coclass,
  threading("apartment"),
  vi_progid("Scripting.FileSystemObject"),
  progid("Scripting.FileSystemObject.1"),
  version(1.0),
  uuid("4FC4AA66-B04C-406A-B319-3F946FE491B1"),
  helpstring("FileSystemObject Class")
]
class ATL_NO_VTABLE CFileSystemObject :
  public IFileSystem, // Interface to original FileSystemObject
  public IObjectControl
{
public:
  CFileSystemObject() : m_piFSO(NULL), m_bIsAdmin(false), m_bsCurrentPath(NULL), m_hrSave(-1)
  {}

  DECLARE_PROTECT_FINAL_CONSTRUCT()

  HRESULT FinalConstruct()
  {
    return S_OK;
  }

  void FinalRelease()
  {
  }

  // IObjectControl Methods
public:
  STDMETHOD(Activate)();
  STDMETHOD_(void, Deactivate)();
  STDMETHOD_(BOOL, CanBePooled)();

  // Implementation of IFileSystem

  virtual HRESULT __stdcall CopyFile (
    /*[in]*/ BSTR Source,
    /*[in]*/ BSTR Destination,
    /*[in]*/ VARIANT OverWriteFiles );

};




HRESULT __stdcall CFileSystemObject::CopyFile (
/*[in]*/ BSTR Source,
/*[in]*/ BSTR Destination,
/*[in]*/ [in, optional] VARIANT OverWriteFiles )
{
  return S_OK;
}
0
Comment
Question by:snp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 12306273
I think your problem is related to this: http://support.microsoft.com/default.aspx?scid=kb;en-us;269035 and is a MS bug
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12306279
But if you'll call that method from C++ it will work without the optional parameter.
0
 

Author Comment

by:snp
ID: 12307535
Thanks, that sounds like it is the problem. Trouble here is that I am trying to create a security wrapper around the FileSystemObject, which must be undetectable to the caller. That means that any parameters that are optional on the original FileSystemObject must also be optional on the wrapper. If this bug still has not been fixed after two years I suppose the chances are it will never be fixed. I am not sure that the description in the article is completely accurate, though. It suggests that the calling environment is responsible (here ASP) for not having access to the type info. However, I have written a similar COM component in VB6, with a method having an optional parameter, and in this case calls from ASP work with or without the optional parameter.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 16

Expert Comment

by:nonubik
ID: 12307598
Yes, I think too the calling environment is responsible for not having access to the type info.
0
 

Author Comment

by:snp
ID: 12316443
Its possible, I suppose. But if so, I don't know why optional parameters should work on a COM component written in VB6 when it is called from the same ASP page as the C++ com component.
0
 

Author Comment

by:snp
ID: 12337243
using VARIANT * as the optional parameter type seems to work.
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 12389175
The question has been PAQ'd and the 100 points have been refunded.
RomMod
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

628 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