gbzhhu,
That article isn't very helpful.
This article is much more helpful, it shows actual sample code:
http://www.codeguru.com/Cp
So I set up my code like this, and it works great. If you see any issues please let me know.
[object, dual, uuid("12345678-1234-1234-1
__interface IMyFoo {
[id(1), helpstring("method foo1")] HRESULT foo1([in] BSTR str, [out,retval] BSTR* result);
[id(2), helpstring("method foo2")] HRESULT foo2([in] VARIANT buf, [in] LONG numBytes, [out,retval] BSTR* result);
};
[ coclass, uuid("87654321-4321-4321-4
class CMyFoo : public IMyFoo
{
public:
CMyFoo(void);
~CMyFoo void);
STDMETHOD(foo1)(BSTR str, LONG* result);
STDMETHOD(foo2)(VARIANT buf, LONG numBytes, BSTR* result);
};
STDMETHODIMP CMyFoo::foo2(VARIANT buf, LONG numBytes, BSTR* result)
{
void *pData;
if (buf.vt == (VT_ARRAY | VT_UI1)) {
SafeArrayAccessData(buf.pa
SafeArrayUnaccessData(buf.
}
else
return S_FALSE;
unsigned char pUChar = (unsigned char *)pData;
int sum = 0;
for (int i=0; i<numBytes; i++) {
// process buf here
sum += pUChar [i];
}
char outstr[50];
sprintf(outstr, "answer is %ld", sum);
*result = ::SysAllocString((OLECHAR *) outstr);
return S_OK;
}
From the C# side:
byte[] buf = new byte[1234];
// buf gets data in it, not important how
mycom.CMyFooClass myfoo = new mycomCMyFooClass();
string sum= myfoo.foo2(buf, buf.Length);
Main Topics
Browse All Topics





by: gbzhhuPosted on 2006-05-24 at 11:19:58ID: 16754270
This may help
47referenc e/msgs/20/ 100781.asp x
http://www.dotnet247.com/2