G
Guest
Hi all,
I am developing website application in asp.net , visual C# and atl com. I
am using atl com component in visual C# application. One of the function of
com component interface returns IStream interface.
I want to read data from that IStream interface. I am new to visual c#. I
have written some code. But, it is returning whole data. It is returning some
null characters.
I have checked same com dll with vc++ client. It is returning whole data
properly.
VC++ code snippet (client):
//pI is com interface in vc++ client
IStream* pStream = NULL;
pI->TestStream(&pStream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggining,STREAM_SEEK_SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg));
hr = pStream -> Stat(&statstg, STATFLAG_NONAME);
pStream->Read(str1,30720,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)"c:\\atlcomdll\\chk1.txt",_O_CREAT|_O_BINARY|_O_RDWR|_O_TRUNC,_S_IREAD | _S_IWRITE);
_write(nFileHandle,str1,30720);
_close(nFileHandle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream(ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.QuadPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteSeek(liBeggining, 0, out newpos);
uint x = 0;
pStream.Stat(out statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteRead(out mybytearray, i, out yz);
}
System.IO.FileStream objGetInfo =
System.IO.File.Create("C:\\ATLCOMDLL\\hi.txt");
objGetInfo.Write(mybytearray, 0, 30720);
objGetInfo.Close();
Now, I am comparing with chk1.txt and hi.txt. But, both are not same.
How to get the whole data in byte[] in visual c# using IStream interface?
suggest me.
I am developing website application in asp.net , visual C# and atl com. I
am using atl com component in visual C# application. One of the function of
com component interface returns IStream interface.
I want to read data from that IStream interface. I am new to visual c#. I
have written some code. But, it is returning whole data. It is returning some
null characters.
I have checked same com dll with vc++ client. It is returning whole data
properly.
VC++ code snippet (client):
//pI is com interface in vc++ client
IStream* pStream = NULL;
pI->TestStream(&pStream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggining,STREAM_SEEK_SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg));
hr = pStream -> Stat(&statstg, STATFLAG_NONAME);
pStream->Read(str1,30720,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)"c:\\atlcomdll\\chk1.txt",_O_CREAT|_O_BINARY|_O_RDWR|_O_TRUNC,_S_IREAD | _S_IWRITE);
_write(nFileHandle,str1,30720);
_close(nFileHandle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream(ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.QuadPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteSeek(liBeggining, 0, out newpos);
uint x = 0;
pStream.Stat(out statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteRead(out mybytearray, i, out yz);
}
System.IO.FileStream objGetInfo =
System.IO.File.Create("C:\\ATLCOMDLL\\hi.txt");
objGetInfo.Write(mybytearray, 0, 30720);
objGetInfo.Close();
Now, I am comparing with chk1.txt and hi.txt. But, both are not same.
How to get the whole data in byte[] in visual c# using IStream interface?
suggest me.