|
* The xmlparser XmlLite from microsoft uses IStream to read and write xml.
It is described how to copy text into a stream, but not how to read the text back from the stream. Do you know how to do this?
Code to write text to IStream.
IStream * pStream = NULL;
HGLOBAL hXmlContent;
HRESULT hr;
int iResult = 0;
// allocate global memory to copy the HTML content to
hXmlContent = ::GlobalAlloc( GPTR, ( ::_tcslen( kpszXML_in ) + 1 ) * sizeof(TCHAR) );
if (!hXmlContent)
return false;
::_tcscpy( (TCHAR *) hXmlContent, kpszXML_in );
// create a stream object based on the HTML content
hr = ::CreateStreamOnHGlobal( hXmlContent, TRUE, &pStream );
|
|
|
|
|
|
Thank you for the link.
I also found another way to do this.
LARGE_INTEGER pos;<br />
pos.QuadPart = 0;<br />
pOutStream->Seek((LARGE_INTEGER)pos, STREAM_SEEK_SET, NULL);<br />
<br />
char pszXml[4095];
ULONG cb=4095;<br />
ULONG cbRead=0;<br />
CString strXmlFromIStream;<br />
do <br />
{<br />
memset(pszXml,0,4095);<br />
hr = pOutStream->Read(pszXml, cb, &cbRead);<br />
strXmlFromIStream += pszXml;<br />
} while(cbRead!=0);
|
|
|
|
|
Hello everyone,
I am looking for some tutorials about how to use OLE Viewer. But I can not find any detailed tutorials. Any reference?
thanks in advance,
George
|
|
|
|
|
In which forum should I submit C questions???????
|
|
|
|
|
Just ask here!
Maxwell Chen
|
|
|
|
|
This is the forum...
- NS -
|
|
|
|
|
If you like to ask on the codeproject this forum is good choice.;)
|
|
|
|
|
Thanks and sorry for the late reply,
my ques is like that:
i have a struct built for ADT in a source file, and it compiles successfully.
the problem is that when i try to use it in the designated program, It doesn't recognize all of the members of the struct.
here is the relevant code:
this is the struct source file:
typedef struct data
{
char** colName;
const struct element_interface** ifc;
Element* temp_row;
}data;
typedef struct table_rec
{
char TabInitFlag;
int iterator;
data* localData;
char** last_found_array;
Matrix tableArray;
int tableWidth;
int last_found;
}table_rec;
header file:
typedef struct table_rec *Table;
application try to use:
Result rdb_del_customer(RestaurantDB rdb,const char* name)
{
Element passName[1];
int *count;
passName[0] = string_to_element(name);
count = (int*)malloc(sizeof(int));
tab_delete_rows(rdb->customers , rdb->customers->localData->colName , passName , 1 , count);
if(*count == 0)
return RES_NO_MATCH;
else
return RES_NO_ERROR;
}
it doesn't recognize the rdb->customer as a Table, pointer to table_rec Struct
Error message:
error C2037: left of 'localData' specifies undefined struct/union 'table_rec' c:\documents and settings\dan\my documents\visual studio 2005\projects\mtm_rst\mtm_rst\restaurantdb.c 61
and of course I want to use code project to ask my questions, it's my guide in
every step on my way to become a programmer excellent.
|
|
|
|
|
Put your structure in the header file instead of the source file.
|
|
|
|
|
I am not allowed to do this, this is what ADT programming is all about.
I must hide my implementation from the user(in this case me ),
so I only pass to the user the header interface to my ADT, and the object file,
he uses that to create he's own program using my module.
it's a school assignment :->
|
|
|
|
|
gizmokaka wrote: I must hide my implementation from the user(in this case me ),
Which implementation ? I just see a structure with data in it, no functions at all. How can somebody manipulate an 'object' without knowing what's inside.
How could you know that the structure contains a localData member if it is hidden ?
Hide implementation means that you put your function definitions in a cpp file and only 'show' (through a header file) the function prototypes.
|
|
|
|
|
true, and that's what I do,
only I am not allowed to reveal the members of the struct because
then the user of the ADT can change their type or value directly
which can hurt the functionality and integrity of the ADT.
|
|
|
|
|
The error message tells clearly what is the error:
gizmokaka wrote: rdb->customers->localData->colName
at this line the structs are unknown.
You have to include the struct declarations before, so, as is telling Cedric, you canto put they in the header file.
Or, if you want to hide that structs to the user, you have to put ALL the code that use they in the SAME file, above the declaration of that structs.
Elseway the compiler can't know that table_rec and data exists.
Russell
|
|
|
|
|
Maybe I am missing something here but
the ADT is a module of it's own, and is separated from the application using it.
I can't put the struct in the user application, only the header and link to the
ADT object file.
and yes I do want to hide the structs to the user.
Again, how do you suggest I do that???
I think I didn't understand the last time
|
|
|
|
|
gizmokaka wrote: and yes I do want to hide the structs to the user.
You can not hide to the user what is part of the public interface the user is programming against.
But maybe a forward declaration can solve your problem? Just as to tell the compiler "There is a data-type named 'local_data', and you will know it when you need to".
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
You can notice that it's what I did in the header with a pointer to the table_rec struct
is that not enough?
should I also announce a pointer to data?
can you send me a piece of code on how to do it in my files??
source file:
typedef struct data
{
char** colName;
const struct element_interface** ifc;
Element* temp_row;
}data;
typedef struct table_rec
{
char TabInitFlag;
int iterator;
data* localData;
char** last_found_array;
Matrix tableArray;
int tableWidth;
int last_found;
}table_rec;
header:
typedef struct table_rec *Table;
please if you can resend the renovated code I would be more then thankful
and I will learn another new thing
thanks in advanced.
|
|
|
|
|
The point remains: Your struct table_rec is part of a public interface (as you are reaching inside of it).
The public interface must be completely known to be used.
If you do not want this, you will have to add access-functions for the data you need:
char* customer_get_colname( table_rec* customer); The implementation of this function has to be able to see the complete table_rec. But users of it have not.
-- modified at 8:42 Friday 7th September, 2007
Typo
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I think I understand my problem now thank you a lot.
I will try changing things and see how it works,
you really helped, thanks.
|
|
|
|
|
You're welcome.
And please, change the title of your first mail to include "[solved]"
Thank you!
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
|
View your post and use the 'modify' link in the lower right of it.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
jhwurmbach wrote: The point remains: Your struct table_rec is part of a public interface (as you are reaching inside of it).
The public interface must be completely known to be used.
true, but not necessarily completely true. You can hide part of the implimentation, though it is more complicated and generally discouraged. Providing that the sizes are the same you can swap the contents, or remap them to a full structure. There are valid reasons to do this, and invalid ones. Hiding the interface isn't the best reason in the world. I will use it to handle state based multiple meanings.
struct {
// some public code
char reserved[64];
// some public code
} data;
This you can remap with another structure 64bytes in size without difficulty. The easiest way is with two structures, one in the header, your public one, and one in the source, a private one. The problem is this is difficult to maintain. I generally will keep it in the public interface using a union to hold multiple structures in the same space, but not all programmers will do that.
this is commonly done in communication programming
struct {
int key;
// some code
} packet1;
struct {
int key;
// some code
// some more code
} packet2;
If packet1 and 2 are different sizes you can tell them apart by size. But what if they were the same size, but had say short ints packed together vs. doubles. The key tells you which packet you have, you then recast the structure to the appropriate structure and you have access to the different packet information.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Simply let your code be something like this:
file.cpp
#include "file.h"
struct{
int tagA;
int tagB;
};
setTagA(..){..}
setTagB(..){..}
getTagA(..){..}
getTagB(..){..}
Operation1OnStruct(..){..}
Operation2OnStruct(..){..}
....
OperationNOnStruct(..){..}
PublicOperation1OnStruct(..){..}
PublicOperation2OnStruct(..){..}
PublicOperation3OnStruct(..){..}
file.h
setTagA(..);
setTagB(..);
getTagA(..);
getTagB(..);
PublicOperation1OnStruct(..);
PublicOperation2OnStruct(..);
PublicOperation3OnStruct(..);
In this way the user can only use the public operations on the struct, but not the private ones because on the .h file you will put only declarations of public functions.
In file.cpp you have to define first the struct, then every function (public or private).
Important: the order!
First declare the struct and include the file.h , then define public and private functions.
the private functions on the cpp file can use each other ONLY if they calls function jet defined/declared. So the private Operation2OnStruct(..) can use Operation1OnStruct(..) but not OperationNOnStruct(..) . Then if you want add some prototipes of the private function at the beginning of the file.
Russell
|
|
|
|
|
Hi,
i include some headers to use sockets. The project works great, till now no problems.
Now, the IntelliSense will not work anymore.
My own classes and variables the IntelliSense shows the members and type, but
for example "accept(...);" it doesn't even know the function "accept" if i hit the F12 Key
Is there a special work to do, that IntelliSense works again?
Big thanks
|
|
|
|