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(&pS tream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggini ng,STREAM_SEEK_ SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg) );
hr = pStream -Stat(&statstg, STATFLAG_NONAME );
pStream->Read(str1,3072 0,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)" c:\\atlcomdll\\ chk1.txt",_O_CR EAT|_O_BINARY|_ O_RDWR|_O_TRUNC ,_S_IREAD | _S_IWRITE);
_write(nFileHan dle,str1,30720) ;
_close(nFileHan dle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream( ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.Qua dPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteS eek(liBeggining , 0, out newpos);
uint x = 0;
pStream.Stat(ou t statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteR ead(out mybytearray[i], i, out yz);
}
System.IO.FileS tream objGetInfo =
System.IO.File. Create("C:\\ATL COMDLL\\hi.txt" );
objGetInfo.Writ e(mybytearray, 0, 30720);
objGetInfo.Clos e();
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. 4 4473
"John" <Jo**@discussio ns.microsoft.co mwrote in message
news:2E******** *************** ***********@mic rosoft.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(&pS tream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggini ng,STREAM_SEEK_ SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg) );
hr = pStream -Stat(&statstg, STATFLAG_NONAME );
pStream->Read(str1,3072 0,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)" c:\\atlcomdll\\ chk1.txt",_O_CR EAT|_O_BINARY|_ O_RDWR|_O_TRUNC ,_S_IREAD
| _S_IWRITE);
_write(nFileHan dle,str1,30720) ;
_close(nFileHan dle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream( ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.Qua dPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteS eek(liBeggining , 0, out newpos);
uint x = 0;
pStream.Stat(ou t statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteR ead(out mybytearray[i], i, out yz);
}
System.IO.FileS tream objGetInfo =
System.IO.File. Create("C:\\ATL COMDLL\\hi.txt" );
objGetInfo.Writ e(mybytearray, 0, 30720);
objGetInfo.Clos e();
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.RemoteR ead(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.RemoteR ead(out mybytearray, sizeof(mybytear ray), 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.
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.RemoteR ead(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\wwwr oot\server1_tes t\Default.aspx. cs(67,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.ISt ream.RemoteRead (out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwr oot\server1_tes t\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**@discussio ns.microsoft.co mwrote in message
news:2E******** *************** ***********@mic rosoft.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(&pS tream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggini ng,STREAM_SEEK_ SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg) );
hr = pStream -Stat(&statstg, STATFLAG_NONAME );
pStream->Read(str1,3072 0,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)" c:\\atlcomdll\\ chk1.txt",_O_CR EAT|_O_BINARY|_ O_RDWR|_O_TRUNC ,_S_IREAD
| _S_IWRITE);
_write(nFileHan dle,str1,30720) ;
_close(nFileHan dle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream( ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.Qua dPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteS eek(liBeggining , 0, out newpos);
uint x = 0;
pStream.Stat(ou t statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteR ead(out mybytearray[i], i, out yz);
}
System.IO.FileS tream objGetInfo =
System.IO.File. Create("C:\\ATL COMDLL\\hi.txt" );
objGetInfo.Writ e(mybytearray, 0, 30720);
objGetInfo.Clos e();
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.RemoteR ead(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.RemoteR ead(out mybytearray, sizeof(mybytear ray), 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.
"John" <Jo**@discussio ns.microsoft.co mwrote in message
news:C4******** *************** ***********@mic rosoft.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.RemoteR ead(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\wwwr oot\server1_tes t\Default.aspx. cs(67,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.ISt ream.RemoteRead (out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwr oot\server1_tes t\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.RemoteR ead(mybytearray , 30720, out xy);
Also, don't use hard coded values, pass the size of the byte[] like this:
pStream.RemoteR ead(mybytearray , mybytearray.Len gth, out xy);
and use meaningfull and "correctly" cased names in your code....
pStream.RemoteR ead(myByteArray , myByteArray.Len gth, out bytesReturned);
Willy.
"John" <Jo**@discussio ns.microsoft.co mwrote in message
news:C4******** *************** ***********@mic rosoft.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.RemoteR ead(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\wwwr oot\server1_tes t\Default.aspx. cs(67,9): error CS1502: The
best overloaded method match for 'SERVER1Lib.ISt ream.RemoteRead (out byte,
uint, out uint)' has some invalid arguments
f:\inetpub\wwwr oot\server1_tes t\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**@discussio ns.microsoft.co mwrote in message news:2E******* *************** ************@mi crosoft.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(&pS tream);
char* str1 = new char[30720];
ULONG rval = 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggini ng,STREAM_SEEK_ SET, NULL);
STATSTG statstg;
memset (&statstg, 0, sizeof(statstg) );
hr = pStream -Stat(&statstg, STATFLAG_NONAME );
pStream->Read(str1,3072 0,&rval);
pStream->Release();
int nFileHandle =
_open((LPCSTR)" c:\\atlcomdll\\ chk1.txt",_O_CR EAT|_O_BINARY|_ O_RDWR|_O_TRUNC ,_S_IREAD
| _S_IWRITE);
_write(nFileHan dle,str1,30720) ;
_close(nFileHan dle);
delete[] str1;
Visual c# code snippet:
IStream pStream = null;
obj.TestStream( ref pStream);
tagSTATSTG statstg = new tagSTATSTG();
_LARGE_INTEGER liBeggining ;
liBeggining.Qua dPart = 0;
_ULARGE_INTEGER newpos ;
newpos.QuadPart = 0;
pStream.RemoteS eek(liBeggining , 0, out newpos);
uint x = 0;
pStream.Stat(ou t statstg,x);
byte[] mybytearray = new byte[30720];
uint xy;
for (uint i = 0; i < 30720; i ++)
{
uint yz = 0;
pStream.RemoteR ead(out mybytearray[i], i, out yz);
}
System.IO.FileS tream objGetInfo =
System.IO.File. Create("C:\\ATL COMDLL\\hi.txt" );
objGetInfo.Writ e(mybytearray, 0, 30720);
objGetInfo.Clos e();
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.RemoteR ead(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.RemoteR ead(out mybytearray, sizeof(mybytear ray), 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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
class Stream:
_public_methods_ =
|
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 bytes actually read?
What the code fragment should do is read up to 1000 bytes into a buffer, or
finish early if reading failed. Just your average read loop.
I have: (this is a simplified version; I know there's no detailed error
|
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...
I mange to create the object and call methods that returns strings (BSTR)
|
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" but in a
std::istream.
It appeared at first that "readsome" would do exactly what I wanted but
it appears not to work very well at all (at least with gcc!). When
reading from a named pipe on gcc, it returns immediately - no errors,
just...
|
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 a parser for the chunk of bytes returned by
the first. It expects a reference to a
std::istream as its argument.
| |
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;
IStreamObject.Read(buffer, size, readBytes);
|
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 how to create an instance of it to pass as the parameter. Anyone
can tell me what to do? i dont know what to pass in as the parameter,
because I'm not sure how to create an instance of the "IStream" object
in C#
|
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:
(C++)
STDMETHODIMP CIntf::SendFiles(int noOfStreams, IUnknown** dataStreams)
{
|
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 extract the raw html from Internet Explorer using a BHO. When accessing the HTML via the mshtml.HTMLDocument (DOM) object you get a version of the HTML that is different from what you see when you "right click --> view source". IE changes the code for...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |