Implementing an Existing COM Interface in Managed Code which RETURNS an Array of COM Structures
here simple com structure definition idl:
typedef [uuid(ee3337e6-14f7-469b-be9f-8d45fa43f4ed)]
struct eatemplate_act
{
long templateid;
bstr templatename;
} eatemplate_act;
here com interface definition:
library eadimensionlib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
importlib("..\eaact\eaact.tlb");
// forward declarations
// ====================
interface ieadimensionac;
// ieadimensionac -
// ==========================================
[
odl,
uuid(9fde51ba-c965-4beb-aea4-27c9f25c99c0),
version(1.0),
nonextensible,
oleautomation,
dual,
pointer_default(unique)
]
interface ieadimensionac : idispatch
{
// templates method
// ======================
[id(1), helpstring("gets templates")]
hresult gettemplates
(
// parameters
[in, out] safearray(struct eatemplate_act)* templates,
// return
[out, retval] long* size
}
}
i want implement gettemplate's in c# com interface existing programs can begin use new c#, wcf based logic. have no problem calling current com implementation .net code, replacing com implementation .net code isn't working.
the following code, compiles warning resulting interface not operational in com programs.
namespace eaclientws
{
[guidattribute("0223f301-e827-4fb7-b55b-ac3c658ceaea")]
[progidattribute("eaclientws.cdimensionlocators")]
public class cdimensionlocators : eadimensionlib.ieadimensionac
{
eadomainwsclient m_odomainproxy = new eadomainwsclient();
public int gettemplates(ref array templates)
{
int lcount = 0;
int = 0;
dimension[] dimtemplates = null;
eaactlib.eatemplate_act[] mytemplates = null;
lcount = m_odomainproxy.gettemplates(ref dimtemplates);
if (lcount == 0)
return 0;
mytemplates = new eaactlib.eatemplate_act[lcount];
foreach (dimension vtemplate in dimtemplates)
{
mytemplates[i].templateid = vtemplate.dimensionid;
mytemplates[i].templatename = vtemplate.dimensionname;
i++;
}
templates = mytemplates;
return lcount;
}
}
the interop books show 1 way com -> .net, leaves me big conversion.
thanks
peter boswell
msdos 1.0 developer
hans passant.
.NET Framework > Common Language Runtime Internals and Architecture
Comments
Post a Comment