473,466 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IStream interface

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], 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.
--
Thanks & Regards,
John.
May 11 '07 #1
4 4452
"John" <Jo**@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
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], 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.
--
Thanks & Regards,
John.

Do you actually understand what you are doing here?

for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteRead(out mybytearray[i], i, out yz);
}
you are overwriting the buffer for each iteration, with a decreasing number
of bytes from the stream ...
You should read the whole stream at once just like you did in C++:

uint yz = 0;
pStream.RemoteRead(out mybytearray, sizeof(mybytearray), out
yz);

and check the number of bytes returned (yz) in the buffer against the size
of the buffer, if yz is smaller, then you are done reading, if equal you may
have more data to read...

Note that I can't comment on the remaining part of the code, as it's
incomplete, but there may be other issues.
Willy.

May 11 '07 #2
Hi Willy,

Thank you for your prompt response.

Is there any article to read the data from stream in visual c sharp
application for website.

I have replace with this below code according to your suggestion.
- uint xy;
pStream.RemoteRead(out mybytearray, 30720, out xy);

the output is :
----- Build started: Project: http://localhost/server1_test/, Configuration:
Debug .NET ------
Validating Web Site
Building directory '/server1_test/'.

f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.IStream.RemoteRead(out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,32): error CS1503:
Argument '1': cannot convert from 'out byte[]' to 'out byte'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
It is not allowing to take byte[]. It accepts only byte.

How do I resolve this?
-
Thanks & Regards,
John.
"Willy Denoyette [MVP]" wrote:
"John" <Jo**@discussions.microsoft.comwrote in message
news:2E**********************************@microsof t.com...
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], 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.
--
Thanks & Regards,
John.


Do you actually understand what you are doing here?

for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteRead(out mybytearray[i], i, out yz);
}
you are overwriting the buffer for each iteration, with a decreasing number
of bytes from the stream ...
You should read the whole stream at once just like you did in C++:

uint yz = 0;
pStream.RemoteRead(out mybytearray, sizeof(mybytearray), out
yz);

and check the number of bytes returned (yz) in the buffer against the size
of the buffer, if yz is smaller, then you are done reading, if equal you may
have more data to read...

Note that I can't comment on the remaining part of the code, as it's
incomplete, but there may be other issues.
Willy.


May 12 '07 #3
"John" <Jo**@discussions.microsoft.comwrote in message
news:C4**********************************@microsof t.com...
Hi Willy,

Thank you for your prompt response.

Is there any article to read the data from stream in visual c sharp
application for website.

I have replace with this below code according to your suggestion.
- uint xy;
pStream.RemoteRead(out mybytearray, 30720, out xy);

the output is :
----- Build started: Project: http://localhost/server1_test/,
Configuration:
Debug .NET ------
Validating Web Site
Building directory '/server1_test/'.

f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.IStream.RemoteRead(out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,32): error CS1503:
Argument '1': cannot convert from 'out byte[]' to 'out byte'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped
==========
It is not allowing to take byte[]. It accepts only byte.

How do I resolve this?
-
Thanks & Regards,
John.


As I told you it's hard to answer such questions if you only post a part of
the code, what I'm missing here is your RemoteRead declaration.
Anyway, try this:

pStream.RemoteRead(mybytearray, 30720, out xy);

Also, don't use hard coded values, pass the size of the byte[] like this:

pStream.RemoteRead(mybytearray, mybytearray.Length, out xy);

and use meaningfull and "correctly" cased names in your code....

pStream.RemoteRead(myByteArray, myByteArray.Length, out bytesReturned);

Willy.
May 12 '07 #4
"John" <Jo**@discussions.microsoft.comwrote in message
news:C4**********************************@microsof t.com...
Hi Willy,

Thank you for your prompt response.

Is there any article to read the data from stream in visual c sharp
application for website.

I have replace with this below code according to your suggestion.
- uint xy;
pStream.RemoteRead(out mybytearray, 30720, out xy);

the output is :
----- Build started: Project: http://localhost/server1_test/,
Configuration:
Debug .NET ------
Validating Web Site
Building directory '/server1_test/'.

f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.IStream.RemoteRead(out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwroot\server1_test\Default.aspx.cs(67 ,32): error CS1503:
Argument '1': cannot convert from 'out byte[]' to 'out byte'
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped
==========
It is not allowing to take byte[]. It accepts only byte.

How do I resolve this?
-
Thanks & Regards,
John.
"Willy Denoyette [MVP]" wrote:
>"John" <Jo**@discussions.microsoft.comwrote in message
news:2E**********************************@microso ft.com...
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], 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.
--
Thanks & Regards,
John.


Do you actually understand what you are doing here?

for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteRead(out mybytearray[i], i, out yz);
}
you are overwriting the buffer for each iteration, with a decreasing
number
of bytes from the stream ...
You should read the whole stream at once just like you did in C++:

uint yz = 0;
pStream.RemoteRead(out mybytearray, sizeof(mybytearray), out
yz);

and check the number of bytes returned (yz) in the buffer against the
size
of the buffer, if yz is smaller, then you are done reading, if equal you
may
have more data to read...

Note that I can't comment on the remaining part of the code, as it's
incomplete, but there may be other issues.
Willy.



May 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Juan Carlos CORUÑA | last post by:
Hello all, I have developed an automation server using Mark's win32 extensions and I must return a IStream COM object from one method of the automation server. Here is an extract of my code:...
6
by: Steve | last post by:
Hi, I'm trying to convert a file reading loop into one using streams. The BSD OS read API returns the number of bytes read, but istream::read returns itself. How can I find out the number of...
5
by: Gunnar Liknes | last post by:
Hi, I am trying to access COM component - method that takes a IStream (ByRef) parameter from ASP (Not ASP.NET). So far I have had no luck and google drowns my search with ASP.NET examples......
13
by: Gianni Mariani | last post by:
What I would like to do is read bytes from a stream, any number and any time. I would like it to wait until there are any bytes to read. I want the exact same functionality as cstdio's "fread"...
7
by: John Salmon | last post by:
I'm working with two libraries, one written in old school C, that returns a very large chunk of data in the form of a C-style, NUL-terminated string. The other written in a more modern C++ is...
21
by: Peter Larsen [] | last post by:
Hi, I have a problem using System.Runtime.InteropServices.ComTypes.IStream. Sample using the Read() method: if (IStreamObject != null) { IntPtr readBytes = IntPtr.Zero;...
3
by: Kourosh | last post by:
Hi all, I'm trying to call a COM function from C# The function gets a paramter of type IStream in C++. I've found the type System.Runtime.InteropServices.ComTypes.IStream, however I'm not sure...
4
by: Ralf | last post by:
Hallo, I'm trying to call a COM function from C#. The function has a parameter from the type array of IStream* (IStream**). The COM component (out-proc-server (.exe)) has the following code: ...
0
by: admb600 | last post by:
I wouldn't normally beg but my dissertation is due in, in a couple of weeks and I am in way over my head here.. Fixing this issue will make or break the project and my degree.. The goal is to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.