|
Hi,
Here is the question : I develop a COM component using ATL . In this component I have a method called "BeepMe", from where I want to return a BSTR message , as an out parameter :
BeepMe ([out] BSTR* pbstrMessage)
when I call it from an ASP page (written in Jscript):
var strRet;
Component.BeepMe(strRet);
the strRet is empty .
but, if I declare the pbstrMessage as retval ( BeeepMe([out,retval] BSTR* pbstrMessage) ) , and write :
var strRet = Component.BeepMe();
everithing works fine . The pbstrMessage is propertly initialized in the method ( *pbstrMessage = ::SysAllocString(L"Beep") ), so that isn't the problem.
I know that the VB script interpreter handle the deallocation of memory , and I suppose that is also the ASP case . That is the cause of this behavior ? ( the ASP interpreter free the memory of the returned value ? )
|
|
|
|
|
Hi,
First of all you should use the SysReAllocString instead of SysAllocString. It's not the source of the problem but it's a correct way of doing things. Before assigning a new value to the pointer you must free the data it's pointing to.
STDMETHODIMP CTest::get_Path(BSTR *pVal)
{
if(pVal == NULL)
return E_POINTER;
if(!SysReAllocString(pVal, m_bstrPath))
return E_OUTOFMEMORY;
return S_OK;
}
Your problem is that in VBScript and JScript cannot pass parameters by reference to automation properties or methods. Use return values of properties and methods to return a value instead of using byref parameters for this purpose. This approach limits you to one return value.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Hi
I have created a c++ dll which works great in excel 2000, as I launch it as a com add-in, and get access to the IDispatch of the calling instance of excel via OnConnection (IDTExtensibility2).
I would like to be able to launch the dll from excel 97, via an xla (or xll), which is not a problem, but I do not know how to get the IDispatch of the instance of excel that has the xla (or xll) running.
(Excel.Application is no good, as it only finds the first instance of Excel.)
If anyone knows the answer, please let me know
Thanks!
|
|
|
|
|
Hi
I have worked out how to do it from an xla , but if anyone knows how to do the same in an xll please let me know.
From Auto_Open() sub of xla, pass Application to function in DLL
i.e.
in XLA
!declaration of function in DLL
Private Declare Function InitExcel97 Lib "MyDLL.dll" (ByVal app As Object) As Long
Public Sub Auto_Open()
Result = InitExcel97(Application)
…
End Sub
in DLL
extern "C" __declspec( dllexport ) LONG WINAPI InitExcel97(LPDISPATCH Application)
{
long result;
g_pApplication = Application; //global declaration IDispatch* g_pApplication;
theApp.InitializeExcel(); //calls same code as if launched by com addin in Excel2000
….
return result;
}
|
|
|
|
|
Reference Article;- MSDN Q192348 & Q216686. This uses automation.
Regards,
K M Bansal <iclassfactory2@usa.net>
|
|
|
|
|
Hi,
Those examples do not relate to my question, for each example creates its own instance of excel, which it then uses. I want to attach to an existing instance, and using AttachDispatch with Excel.Application, is no solution as it will only find the first instance of excel.
As I mentioned in my prior message, it is easy from a xla, but I would still be curious how to find the correct IDistatch from an xll (or any c++ written application).
For your information, a much better method than proposed in Q192348 is Q186427.
The closest MSDN example to my problem is found in Q190985, but there, Excel is running as a container.
Regards
Leo
|
|
|
|
|
I have dll with two objects. One is CommBand and another is Browser Helper Object. How can i get pointer on my BHO object from my CommBand object ?
|
|
|
|
|
Hi,
The instance of the Browser Helper Object is created each time Internet Explorer starts. You can create an instance of the CommBand object while creating BHO object and then set the internal pointer.
You can also create singleton component, which will be holding the list of the interface pointers to all BHO objects. Each time the BHO object is created it adds the interface pointer to the table. You can also save any additional information you like. Then you can easily access all available interfaces.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Hello!! how can i use void pointers in a parameter in a funcion of COM class??
I try this:
..........MyFuncion([out,retval] void * pResult)
and when i compile it CRASHHHHHHHH!!!!!!!!!
please help me...
my email is jsanchez@cie.com.mx
|
|
|
|
|
Hi,
The problem with any kind of pointers is that you can't return or pass it without marshaling the data it points to. If you are using the pointer to the well-known types, such as Long, BSTR, ... the default marshaling can be used. If you use an array of objects or void pointer you must provide additional information for marshalling. Have a look at the length_is() and other array related attributes of the IDL file. You also can return an array of data using a variant with SAFEARRAY. This is the best thing you can do if you are going to use the component in VB.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Hi Jafet,
There are several techniques you can use and returning the VOID pointer is not one of them. There is a VERY nice article by Don Box in MSDN explaining your options and advantages/disadvantages.
The name of the article is "OLE Q&A". There are several articles with this name and I add the beginning of the article, so it will be easier to find.
Regards,
Alex Gorev,
Dundas Software.
------------------------------------------------------
"
OLE Q&A
Don Box
Don Box has been working in networking and distributed object systems since 1989. He is currently chronicling the COM lifestyle in book form for Addison Wesley, and gives seminars on OLE and COM across the globe. Don can be reached at dbox@braintrust.com.
QI am using dual interfaces to expose my objects to both C++ and Visual BasicТ clients. Designing the interfaces was relatively painless once I passed simple data types as method parameters. I now need to pass user-defined structures as parameters and can't get it to work. Any suggestions?
....
" -- MSDN.
------------------------------------------------------
----- Original Message -----
From: Jafet Sanchez Rodriguez <jsanchez@cie.com.mx>
To: <alexg@dundas.com>
Sent: Tuesday, July 04, 2000 11:42 AM
Subject: Re: [CodeProject] Re: void* in a parameter in COM function
> Hi Alex!!
> I want to pass a struct from vc to vb ..
>
> struct A
> {
> int a;
> int b;
> float c;
> }
>
> MYSTRUCT A;
>
|
|
|
|
|
guy's please help me with this one as i am new to COM
|
|
|
|
|
I use it:
BSTR sMyBSTR;
sMyBSTR = "Hola que onda!";
CComBSTR sCad;
sCad.Append(sMyBSTR);
|
|
|
|
|
Hi,
Variants store the strings as BSTRs. You can work with BSTR strings using the standard string functions if you convert it using the OLE2A(...) macro.
USES_CONVERSION;
char *p = strstr(OLE2A(m_bstrData), "Data=");
If you have a lot of string operations I recommend you to use the WTL's CString class. It's a light weight template, which duplicate the functionality of the popular MFC's string class.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
How to add a custom color property entry in PROP_DATA_ENTRY macro - what should be the vt value?
|
|
|
|
|
Hi,
If it possible use the wizards to add the property and specify the OLE_COLOR as a data type. When a property is declared as OLE_COLOR, the Properties window will display a color-picker dialog that allows the user to select the color for the property visually, rather than having to remember the numeric equivalent. Internally it's treated as a Long.
Regards,
Alex Gorev
Dundas Software.
|
|
|
|
|
Hi,
Thanks for replying.
The reason why I need the PROP_DATA_ENTRY is to persist the property. I have added properties using the wizard already. When I add an entry like...
PROP_DATA_ENTRY("Start Color", m_clrStartColor,VT_UI4)
the VB client gives invalid property when being persisted.
Please clarify.
Thanks & regards,
V.Lakshmi Narasimhan
|
|
|
|
|
Hi,
First of all if you have a Set/Get functions for the property and it's part of any property page it's better to use PROP_ENTRY macro. Even if you don't use the property page you can always set it to CLSID_NULL.
BEGIN_PROP_MAP(...)
PROP_ENTRY("StartColor", DISPID_START_COLOR, CLSID_NULL)
END_PROP_MAP()
The other thing I've noticed is that you use a space in the name of the property. Never use it in the name of the properties, it can cause all kind of problems.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Hi...
While developing ASP Components in VC, is there any restriction to use MFC in it? Should we use MFC or not? If answer is "Yes" then explain it and if answer is "No" then explain it also
Thanks!
|
|
|
|
|
Hi,
There are no any restrictions... but ASP components do not have any GUI, so there is no any reason to use MFC. If you need a good string class use WTL instead.
So my answer is NO. Because you don't need MFC and it will affect the size and performance of the component comparing to ATL & WTL.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
HI HI HI
Need to now how to make com object to save an error to file so the client can't see any msgBox but i can view the errors from the file any time i want.
|
|
|
|
|
Hi,
I don't think it's possible to do... If the component shows the dialog on error there is no way ho hide this dialog and to get the error text, except if there are special methods/properties for that. Only if the standard IErrorInfo interface is used than you can change the component container behavior.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
Hi again
How about just make a com object to save the errors that comes up to file??
regard
Bjarni
|
|
|
|
|
Hi,
Is it a third party COM object, or you designed it by yourself? If you don't have the source code just the DLL file I don't see any ways to MAKE the COM object to write the error messages in the file.
Regards,
Alex Gorev,
Dundas Software.
|
|
|
|
|
And how Visual Basic ActiveX DLLs get the reference to Component Manager
which implemented by client in order to display modeless forms in the
ActiveX DLL.
Thanks for any suggestion?
|
|
|
|