|
Q2. You can pass the IStudent interface as well as any other data from ITeacher interface.
Q1.
In IDL-file
typedef [uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX), helpstring("Help")]
struct _SomeStruct
{
int i;
BSTR str;
...
} SomeStruct;
[...,dual,...]
interface IO : IDispatch
{
[id(1)] HRESULT M1([in] SomeStruct ss);
[id(2)] HRESULT M2([in,out] SomeStruct *ss);
[id(3)] HRESULT M3([out,retval] SomeStruct* *ss);
[id(4)] HRESULT M4([in,out] SAFEARRAY(SomeStruct) * ssbs);
};
With best wishes,
Vita
|
|
|
|
|
thank you . Q1 has been resovled following your suggestion.
but Q2 remail abcuse.
I mean I can not construct the CStudent object in CTeacher.
Details as follows.
In the construction function of the CTeacher :
CTeacher()
{
IStudent * m_student =new CStudent();
return;
}
There are some compiler errors. It says that the CStudent cannot instantiate abstract class due to following members:QueryInterface,AddRef,Release.
How should I do to resolve the problem.
thx.
Regards.
|
|
|
|
|
If you are in ATL, you have several ways to do it.
1. With the class factory of CStudent.
if( FAILED(CStudent::_CreatorClass::CreateInstance(NULL,IID_IStudent, (void**)&m_student)) )
return E_FAIL;
2. With the static method of the generic ATL CComObject.
CComObject<CStudent>* pCStudent;
if( FAILED(pCStudent->CreateInstance(&pCStudent)) || FAILED(pCStudent->QueryInterface(&m_student)) )
return E_FAIL;
3. With the original COM method.
if( FAILED(CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_student)) )
return E_FAIL;
With best wishes,
Vita
|
|
|
|
|
Hi, all
Some problems about ATL Com:
1.I have create two ATL Object: CStudent and CTeacher .
The simple source code listed as follow: (some code auto generated by ATL have been skiped)
class CStudent
{
private:
long m_age;
public:
CStudent():m_age(10)
{
}
//...other code auto generated by ATL
};
class CTeacher
{
private:
IStudent* m_aStudent;
public:
CTeacher()
{
//create an instance of the com
CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_aStudent);
}
//...other code auto generated by ATL
}
2.Then I add a "IStudent * OneStudent" property for ITeacher ,to access the m_aStudent.
The implemention of the property are listed as below:
STDMETHODIMP CTeacher::get_OneStudent(IStudent *pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*pVal = * m_aStudent;
return S_OK;
}
STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*m_aStudent = *newVal ;
return S_OK;
}
3.Now I type some VB code to test the com ,but some compiler errors occurrs.
VB Code:
Dim s As Student
Dim t As New Teacher
s = t.OneStudent
the last sentence "s = t.OneStudent" have compiler errors.
Errors:function or interface marked as restricted ,or the function use an Automation type not supported in Visual Basic
I guess the errors caused by the type dismatch between IStudnet and CStudent.But I did not know how to resolve it .
So who can tell me how to return the m_aStudent that can be supproted in vb??
thx.
Regards.
|
|
|
|
|
I think that you should implement get_OneStudent that way (and the IDL updated appropriatly):
STDMETHODIMP CTeacher::get_OneStudent(IStudent **pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
*pVal = m_aStudent;
if (*pVal) {
(*pVal)->AddRef();
}
return S_OK;
}
You cannot copy the interface (nothing will be copied since the interface has no data in itself) and output parameter must be a [out]pointer to what you want to returns (you want to returns a IStudent * so you must use IStudent **).
Philippe Mori
|
|
|
|
|
I need to use activex dll created in vb in a C++ program. I use vc 6.
Here is what I do:
#import " MADLL1.dll" \<br />
named_guids no_implementation \<br />
raw_interfaces_only raw_native_types<br />
using namespace MADLL1;<br />
<br />
#import " MADLL2.dll" no_implementation \<br />
no_auto_exclude \<br />
raw_native_types raw_interfaces_only \<br />
named_guids <br />
using namespace MADLL2;<br />
<br />
#import " MADLL3.dll" no_implementation \<br />
no_auto_exclude \<br />
raw_native_types raw_interfaces_only \<br />
named_guids rename("SOMETHING"," SOMETHINGX") \<br />
rename(" SOMETHINGELSE", " SOMETHINGELSE X") \<br />
<br />
using namespace MADLL3;
My problem is with the third dll. I put rename because I had compilation errors.I taught It was name collision.
I did help with these variable but I have still alot of erros of the same kind:
Ex :
c:\inwork\opc_da_clientmerge\debug\OLEGEUSE.tlh(729) : error C2059: syntax error : 'constant'
enum TT_SOMETHING
{
TTDT_ONE = 0,///Here I should rename these variables
TTDT_TWO= 1,
TTDT_THREE= 2,
TTDT_FOUR= 3
};
Is it normal to rename everything? I don't think so.
Here is how I want to use the dll:
HRESULT hresult;<br />
CLSID clsid;<br />
<br />
CoInitialize(NULL);
hresult=CLSIDFromProgID(OLESTR("madll.clsConnexion"), &clsid);
if(FAILED(hresult))<br />
{<br />
<br />
TRACE_MSG(_T("CDataBD:: GetTypeAttr"),hresult);<br />
return hresult;<br />
} <br />
_clsConnexion *ConDll;
_clsError *Error;
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_clsConnexion),(LPVOID *) &t);<br />
if(FAILED(hresult))<br />
{<br />
TRACE_MSG(_T("CDataBD:: GetTypeAttr"),hresult);<br />
return hresult;<br />
}
//to this point everything works
but for the rest I have to load the third dll to test it
ConDll ->LoadData("01", "L4", 0, 0, m_Line, "OLE.MachineS", ADO_OLEDB, Error);<br />
ConDll->Release();
CoUninitialize();
I also tried with IDispatch
OLECHAR* name = OLESTR("LoadData"); <br />
HRESULT hr2 = pDispatch->GetIDsOfNames(IID_NULL,<br />
&name,<br />
1,<br />
GetUserDefaultLCID(),<br />
&dispid);
Thinking I could use Invoke....
But I received :
DISP_E_UNKNOWNNAME
I'm able to use these Interfaces :
ITypeLib
ITypeInfo
I have access to info from the lib but not Invoke...
You see that I tried different approches without success.
Is it me that don't understand or could it be how the dll was created?
I have access to source code from dll but can't change anything.
Hope somebody could help me
Regards
Lily
|
|
|
|
|
Hi there,
My guess is that MADLL3 typelibrary implicitly imports typelibs of MADLL2 or MADLL1, this causes all kinds of typedefs to be duplicated in the generated .tlh and .tli files.
Gertjan
|
|
|
|
|
when make a ComAddin:
in VB
Private Sub AddinInstance_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode,
ByVal AddInInst As Object,
custom() As Variant)
AddInInst.object = Me
End Sub
in MFC
STDMETHODIMP CMyAddin::OnConnection(IDispatch* Application,
ext_ConnectMode ConnectMode,
IDispatch* AddInInst,
LPSAFEARRAY* custom)
{
return S_OK;
}
Question is :
How to do (AddInInst.object = Me) in the MFC?
|
|
|
|
|
Please help me.
How to Call ComAddin's function from VBA MACRO?
|
|
|
|
|
I have to convert a TCHAR string to BSTR in an ATL based service without using MFC.
I tried T2OLE, but I could not compile the project because some errors:
'_lpa' : undeclared identifier, ...
Could anyone help me out?
Alma
|
|
|
|
|
You can use CComBSTR class to make this conversion.
CComBSTR bstrString( tcharString );
or
bstrString = tcharOtherString;
With best wishes,
Vita
|
|
|
|
|
|
The string conversion macros require that you put the USES_CONVERSION; macro at the beginning of the function/block.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Your getting this error because your not using the USES_CONVERSION macro in your functions that use the T2OLE macro. For example:
void myfunc(LPTSTR szIN, BSTR* bszOut){
USES_CONVERSION;
bszOut = T2OLE(szIN);
}
Hope that helps.
|
|
|
|
|
Yep, it workes this way. Thanks.
|
|
|
|
|
Hi!
I am new to COM / ATL and just trying to learn that...
I want to have a ATL COM Component with a dialog box with all its message handeling in it and want to show up that dialog in some other Client app using some interface etc.
Pls tell me how to do that. I will be thankful if you can give me detailed tutorial kind ....specifying all steps ..as I am new to it.
One more another question....
Actually my need is that my client ( a win32 SDK project without MFC) has a method which adds property Sheets and all it needs is a Dialog Resource ID and Callback function of that dialog to add propertysheet to existing propertysheet. Now I want a com dll having that property sheet. I would like to know how to do that ...Pls help . What I should do to make COM Dll and how to get Dialog ID and callback function in Client...
I would love to have some code/ project examples
thanks
Naveen
|
|
|
|
|
I need to implement IDispatch::GetIDSOfNames without creating type library, i.e. I need to return certain ID for certain name. How??
|
|
|
|
|
You must implement your version of GetIDsOfNames and correlate it with Invoke. Also you must implement the GetTypeInfoCount and GetTypeInfo to return E_NOTIMPL. And last, you should describe your interface as empty interface, derived from IDispatch.
With best wishes,
Vita
|
|
|
|
|
Yes, thanks, but can I ask some more about memory management. How to allocate memory in IDispatch::GetIDSOfNames implementation? (hich function is needed?)
|
|
|
|
|
I do not see any problem with memory. GetIDSOfNames does not return any memory pointer. If you want to allocate the internal buffers's memory then you can use any strategy you want.
With best wishes,
Vita
|
|
|
|
|
Sorry, I thought I must allocate memory for rgDispId. Now all correct!
P.S. Russian programmers answered me for the my last 4 questions. Hm...
|
|
|
|
|
Welcome on www.RSDN.ru, if you can read the Russian text.
With best wishes,
Vita
|
|
|
|
|
Yeah... My nick is ADK there...
|
|
|
|
|
Hello.
Sorry my poor english.
My question is how to Call ComAddin Function from VBA Macro if ComAddin is maked by using MFC C++;
I know how to call ComAddin function from VBA if ComAddin is maked by using VB.
|
|
|
|
|
is it good practice, or even possible, to have one class factory produce instances of many different COM classes?
i'm trying to make a scripting engine using IActiveScript and such, but i have multiple COM classes implementing IActiveScript, IActiveScriptSite, etc... but I don't want to have a class factory for each one
any thoughts?
- Roman -
|
|
|
|