Click to See Complete Forum and Search --> : strut in com+


balaji_thaai
September 11th, 2000, 05:54 PM
Hi,
I need a detail v.v.urgently to make a design decision. It's purely about MTS. I need a practical suggesion more than
a book reading. If you know give me the idea ,oterwise let me know our friends (atl) list who is working in MTS consistently.
Question is:
I'm developing a component for mts, that to work with both c++&vb client. Can i use my own data types(c++ struct)
as a parameter type to exchage information.... instead of having tomany parameters for 1 funtion.
(e.g)
GetEmpDetails([in]int id,[out]BSTR* empName,[out]int* empAge,[out]BSTR* empDept); // normal notation.
But i want to write a funtion like this:
typedef Struct public Employee
{
BSTR* name;
int age;
BSTR* empDept;
} myEmployee;
//
GetEmpDetails([in] int id, [out]Employee* emp);
//
Will this funtion work correctly if i deploy under MTS package? THAT'S MY QUESTION?

mohanpc
November 2nd, 2000, 05:02 PM
You cannot use user defined datatypes in the parameters for the methods which are exposed to the outside world. Instead you can use the Safearrays supported by VARIANT. If you need any help like how to use SAFEARRAYS get back to me.

Thanks

bkkr
July 19th, 2001, 04:49 PM
I want to send & receive (in, out] array of user defined structure to a c++ com server from VB client.

How do i create array and send & receive from c++ server ?

Green_Beret
September 19th, 2001, 06:10 AM
Hi,
You can try the following :

Employee.h :

typedef struct Employee
{
BSTR *name;
int age;
BSTR *empDept;
}MyEmp;

In the IDL file of your COM project you have to add the following line :

import "Employee.h";

Your IDL function signature should look like this:

GetEmpDetails([in]long Id, [out]SAFEARRAY(MyEmp) *psaEmp);

The fn. signature in your COM header and CPP file should look like this :

GetEmpDetails([in]long Id, [out]SAFEARRAY **psaEmp);

In your function body :

MyEmp *l_MyEmp;

SafeArrayAccessData(*psaEmp,(void **)&l_MyEmp);

.........
........
//Your Code
.......
........

SafeArrayUnaccessData(*psaEmp);


That's it.
Regards,
The Beret.

P.S : Don't include Employee.h in your cpp file.