Convert C++ (return type int, long, user-define, etc) function into COM/ATL
Author |
Message |
Jo #1 / 4
|
 Convert C++ (return type int, long, user-define, etc) function into COM/ATL
Hi, I am a very newbie in COM/ATL. I have a project to convert all function for PDF from C++ to COM/ATL. All the basic structure already there, I just need to convert all the existing functions to COM/ATL. And I believe they use ATL for creating COM object. For the void function, is no problem. I do like the snippet below: STDMETHODIMP CMsiPdfObj::_cpdf_freeAllOutlineEntries(CPDFoutlineEntry *firstOL, CPDFoutlineEntry *lastOL) { CPDFoutlineEntry *olent, *olent2; olent = firstOL; do { /* free kids first */ if(olent->first != NULL) _cpdf_freeAllOutlineEntries(olent->first, olent->last); /* recurse */ if(olent->title) free(olent->title); if(olent->dest_attr_act_dict) free(olent->dest_attr_act_dict); olent2 = olent->next; /* save the next one at the same level */ free(olent); olent = olent2; /* freecnt++; fprintf(stderr,"freecount=%d\n", freecnt); */ } while(olent != NULL); return S_OK; Quote: }
But I don't know how to convert the function with return value as int, long, char and user define type???? Somebody can help me out asap, please??? The orig coding like snippets below: In the middle of function (1), it calls function (2) -- ( in the section say "write this one") (1) void _cpdf_WriteOutlineEntries(CPDFdoc *pdf, CPDFoutlineEntry *first, CPDFoutlineEntry *last) { CPDFoutlineEntry *olent; olent = first; do { _cpdf_WriteOneOutlineEntry(pdf, olent); /* write this one */ /* write kids */ if(olent->first != NULL) _cpdf_WriteOutlineEntries(pdf, olent->first, olent->last); /* recurse */ olent = olent->next; /* do the next one on the same level */ } while(olent != NULL); Quote: }
(2) long _cpdf_WriteOneOutlineEntry(CPDFdoc *pdf, CPDFoutlineEntry *olent) { sprintf(pdf->spbuf, "%d 0 obj\n", olent->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); sprintf(pdf->spbuf, "<<\n"); _cpdf_pdfWrite(pdf, pdf->spbuf); /* NULL parent means the parent is the global Outlines object */ if(olent->parent) sprintf(pdf->spbuf, "/Parent %d 0 R\n", olent->parent->objIndex); else sprintf(pdf->spbuf, "/Parent %d 0 R\n", pdf->objIndex[CPDF_Outlines]); _cpdf_pdfWrite(pdf, pdf->spbuf); if(olent->dest_page >= 0) { /* goto a specified page in the current document */ sprintf(pdf->spbuf, "/Dest [%d 0 R %s]\n", pdf->pageInfos[olent->dest_page].objIndex, olent->dest_attr_act_dict); _cpdf_pdfWrite(pdf, pdf->spbuf); } else { /* Action Outline, we just copy content of dictionary as this is quite complex. No checking is performed on the correctness of syntax. */ sprintf(pdf->spbuf, "/A <<\n%s\n>>\n", olent->dest_attr_act_dict); _cpdf_pdfWrite(pdf, pdf->spbuf); } _cpdf_pdfWrite(pdf, "/Title ("); _cpdf_pdfBinaryWrite(pdf, olent->title, olent->title_len); /* Unicode ready */ _cpdf_pdfWrite(pdf, ")\n"); /* Now, write out, first, last, next, prev if they are not NULL */ if(olent->next) { sprintf(pdf->spbuf, "/Next %d 0 R\n", olent->next->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); } if(olent->prev) { sprintf(pdf->spbuf, "/Prev %d 0 R\n", olent->prev->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); } if(olent->first) { sprintf(pdf->spbuf, "/First %d 0 R\n", olent->first->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); } if(olent->last) { sprintf(pdf->spbuf, "/Last %d 0 R\n", olent->last->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); } if(olent->count != 0) { if(olent->open) sprintf(pdf->spbuf, "/Count %d\n", olent->count); else sprintf(pdf->spbuf, "/Count -%d\n", olent->count); _cpdf_pdfWrite(pdf, pdf->spbuf); } _cpdf_pdfWrite(pdf, ">>\n"); _cpdf_pdfWrite(pdf, "endobj\n"); pdf->objByteOffset[olent->objIndex + 1] = pdf->currentByteCount; return(pdf->currentByteCount); Quote: }
|
Sun, 17 Apr 2005 01:40:28 GMT |
|
 |
Alexander Nickolo #2 / 4
|
 Convert C++ (return type int, long, user-define, etc) function into COM/ATL
You cannot return values in COM interface methods, other than an HRESULT status code. To return values, add another parameter at the end and let the user supply the address of its variable to get the return value. In IDL terms you specify these arguments with [out, retval]. -- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq ===================================== Quote:
> Hi, > I am a very newbie in COM/ATL. > I have a project to convert all function for PDF from C++ to COM/ATL. > All the basic structure already there, I just need to convert all the > existing functions to COM/ATL. And I believe they use ATL for creating > COM object. > For the void function, is no problem. > I do like the snippet below: > STDMETHODIMP CMsiPdfObj::_cpdf_freeAllOutlineEntries(CPDFoutlineEntry > *firstOL, CPDFoutlineEntry *lastOL) > { > CPDFoutlineEntry *olent, *olent2; > olent = firstOL; > do { > /* free kids first */ > if(olent->first != NULL) > _cpdf_freeAllOutlineEntries(olent->first, olent->last); /* > recurse */ > if(olent->title) free(olent->title); > if(olent->dest_attr_act_dict) free(olent->dest_attr_act_dict); > olent2 = olent->next; /* save the next one at the same level */ > free(olent); > olent = olent2; > /* freecnt++; > fprintf(stderr,"freecount=%d\n", freecnt); > */ > } while(olent != NULL); > return S_OK; > } > But I don't know how to convert the function with return value as int, > long, char and user define type???? > Somebody can help me out asap, please??? > The orig coding like snippets below: > In the middle of function (1), it calls function (2) -- ( in the > section say "write this one") > (1) > void _cpdf_WriteOutlineEntries(CPDFdoc *pdf, CPDFoutlineEntry *first, > CPDFoutlineEntry *last) > { > CPDFoutlineEntry *olent; > olent = first; > do { > _cpdf_WriteOneOutlineEntry(pdf, olent); /* write this one */ > /* write kids */ > if(olent->first != NULL) > _cpdf_WriteOutlineEntries(pdf, olent->first, olent->last); /* > recurse */ > olent = olent->next; /* do the next one on the same level */ > } while(olent != NULL); > } > (2) > long _cpdf_WriteOneOutlineEntry(CPDFdoc *pdf, CPDFoutlineEntry *olent) > { > sprintf(pdf->spbuf, "%d 0 obj\n", > olent->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); > sprintf(pdf->spbuf, "<<\n"); _cpdf_pdfWrite(pdf, pdf->spbuf); > /* NULL parent means the parent is the global Outlines object */ > if(olent->parent) > sprintf(pdf->spbuf, "/Parent %d 0 R\n", olent->parent->objIndex); > else > sprintf(pdf->spbuf, "/Parent %d 0 R\n", > pdf->objIndex[CPDF_Outlines]); > _cpdf_pdfWrite(pdf, pdf->spbuf); > if(olent->dest_page >= 0) { > /* goto a specified page in the current document */ > sprintf(pdf->spbuf, "/Dest [%d 0 R %s]\n", > pdf->pageInfos[olent->dest_page].objIndex, > olent->dest_attr_act_dict); > _cpdf_pdfWrite(pdf, pdf->spbuf); > } > else { > /* Action Outline, we just copy content of dictionary as this is > quite complex. > No checking is performed on the correctness of syntax. > */ > sprintf(pdf->spbuf, "/A <<\n%s\n>>\n", > olent->dest_attr_act_dict); > _cpdf_pdfWrite(pdf, pdf->spbuf); > } > _cpdf_pdfWrite(pdf, "/Title ("); > _cpdf_pdfBinaryWrite(pdf, olent->title, olent->title_len); /* Unicode > ready */ > _cpdf_pdfWrite(pdf, ")\n"); > /* Now, write out, first, last, next, prev if they are not NULL */ > if(olent->next) { > sprintf(pdf->spbuf, "/Next %d 0 R\n", > olent->next->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); > } > if(olent->prev) { > sprintf(pdf->spbuf, "/Prev %d 0 R\n", > olent->prev->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); > } > if(olent->first) { > sprintf(pdf->spbuf, "/First %d 0 R\n", > olent->first->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); > } > if(olent->last) { > sprintf(pdf->spbuf, "/Last %d 0 R\n", > olent->last->objIndex); _cpdf_pdfWrite(pdf, pdf->spbuf); > } > if(olent->count != 0) { > if(olent->open) > sprintf(pdf->spbuf, "/Count %d\n", olent->count); > else > sprintf(pdf->spbuf, "/Count -%d\n", olent->count); > _cpdf_pdfWrite(pdf, pdf->spbuf); > } > _cpdf_pdfWrite(pdf, ">>\n"); > _cpdf_pdfWrite(pdf, "endobj\n"); > pdf->objByteOffset[olent->objIndex + 1] = pdf->currentByteCount; > return(pdf->currentByteCount); > }
|
Sun, 17 Apr 2005 11:11:49 GMT |
|
 |
Jo #3 / 4
|
 Convert C++ (return type int, long, user-define, etc) function into COM/ATL
Thanks for the reply, but I am not really understand in term of how to code it. Do you mind to give me a snippet of the example, please? Thanks, Joe Quote:
> You cannot return values in COM interface methods, other than > an HRESULT status code. To return values, add another parameter > at the end and let the user supply the address of its variable to > get the return value. In IDL terms you specify these arguments > with [out, retval]. > -- > ========================= > ============ > Alexander Nickolov > Microsoft MVP [VC], MCSD
> MVP VC FAQ: http://www.mvps.org/vcfaq > ========================= > ============
> > Hi, > > I am a very newbie in COM/ATL. > > I have a project to convert all function for PDF from C++ to COM/ATL. > > All the basic structure already there, I just need to convert all the > > existing functions to COM/ATL. And I believe they use ATL for creating > > COM object. > > For the void function, is no problem. > > I do like the snippet below: > > STDMETHODIMP CMsiPdfObj:: cpdf freeAllOutlineEntries(CPDFoutlineEntry > > *firstOL, CPDFoutlineEntry *lastOL) > > { > > CPDFoutlineEntry *olent, *olent2; > > olent = firstOL; > > do { > > /* free kids first */ > > if(olent->first != NULL) > > cpdf freeAllOutlineEntries(olent->first, olent->last); /* > > recurse */ > > if(olent->title) free(olent->title); > > if(olent->dest attr act dict) free(olent->dest attr act dict); > > olent2 = olent->next; /* save the next one at the same level */ > > free(olent); > > olent = olent2; > > /* freecnt++; > > fprintf(stderr,"freecount=%d\n", freecnt); > > */ > > } while(olent != NULL); > > return S OK; > > } > > But I don't know how to convert the function with return value as int, > > long, char and user define type???? > > Somebody can help me out asap, please??? > > The orig coding like snippets below: > > In the middle of function (1), it calls function (2) -- ( in the > > section say "write this one") > > (1) > > void cpdf WriteOutlineEntries(CPDFdoc *pdf, CPDFoutlineEntry *first, > > CPDFoutlineEntry *last) > > { > > CPDFoutlineEntry *olent; > > olent = first; > > do { > > cpdf WriteOneOutlineEntry(pdf, olent); /* write this one */ > > /* write kids */ > > if(olent->first != NULL) > > cpdf WriteOutlineEntries(pdf, olent->first, olent->last); /* > > recurse */ > > olent = olent->next; /* do the next one on the same level */ > > } while(olent != NULL); > > } > > (2) > > long cpdf WriteOneOutlineEntry(CPDFdoc *pdf, CPDFoutlineEntry *olent) > > { > > sprintf(pdf->spbuf, "%d 0 obj\n", > > olent->objIndex); cpdf pdfWrite(pdf, pdf->spbuf); > > sprintf(pdf->spbuf, "<<\n"); cpdf pdfWrite(pdf, pdf->spbuf); > > /* NULL parent means the parent is the global Outlines object */ > > if(olent->parent) > > sprintf(pdf->spbuf, "/Parent %d 0 R\n", olent->parent->objIndex); > > else > > sprintf(pdf->spbuf, "/Parent %d 0 R\n", > > pdf->objIndex[CPDF Outlines]); > > cpdf pdfWrite(pdf, pdf->spbuf); > > if(olent->dest page >= 0) { > > /* goto a specified page in the current document */ > > sprintf(pdf->spbuf, "/Dest [%d 0 R %s]\n", > > pdf->pageInfos[olent->dest page].objIndex, > > olent->dest attr act dict); > > cpdf pdfWrite(pdf, pdf->spbuf); > > } > > else { > > /* Action Outline, we just copy content of dictionary as this is > > quite complex. > > No checking is performed on the correctness of syntax. > > */ > > sprintf(pdf->spbuf, "/A <<\n%s\n>>\n", > > olent->dest attr act dict); > > cpdf pdfWrite(pdf, pdf->spbuf); > > } > > cpdf pdfWrite(pdf, "/Title ("); > > cpdf pdfBinaryWrite(pdf, olent->title, olent->title len); /* Unicode > > ready */ > > cpdf pdfWrite(pdf, ")\n"); > > /* Now, write out, first, last, next, prev if they are not NULL */ > > if(olent->next) { > > sprintf(pdf->spbuf, "/Next %d 0 R\n", > > olent->next->objIndex); cpdf pdfWrite(pdf, pdf->spbuf); > > } > > if(olent->prev) { > > sprintf(pdf->spbuf, "/Prev %d 0 R\n", > > olent->prev->objIndex); cpdf pdfWrite(pdf, pdf->spbuf); > > } > > if(olent->first) { > > sprintf(pdf->spbuf, "/First %d 0 R\n", > > olent->first->objIndex); cpdf pdfWrite(pdf, pdf->spbuf); > > } > > if(olent->last) { > > sprintf(pdf->spbuf, "/Last %d 0 R\n", > > olent->last->objIndex); cpdf pdfWrite(pdf, pdf->spbuf); > > } > > if(olent->count != 0) { > > if(olent->open) > > sprintf(pdf->spbuf, "/Count %d\n", olent->count); > > else > > sprintf(pdf->spbuf, "/Count -%d\n", olent->count); > > cpdf pdfWrite(pdf, pdf->spbuf); > > } > > cpdf pdfWrite(pdf, ">>\n"); > > cpdf pdfWrite(pdf, "endobj\n"); > > pdf->objByteOffset[olent->objIndex + 1] = pdf->currentByteCount; > > return(pdf->currentByteCount); > > }
|
Sun, 17 Apr 2005 22:20:57 GMT |
|
 |
Brian Mut #4 / 4
|
 Convert C++ (return type int, long, user-define, etc) function into COM/ATL
Your question really suggests you are at the beginning end of the ATL/DCOM learning curve. Your question and the many others that are sure to follow are best answered with a good book at your side. Try http://www.wrox.com/books/1861001401.htm
|
Mon, 18 Apr 2005 04:24:03 GMT |
|
|
|