Member Avatar for Thew

Hello everyone,
I have a problem in my Borland C++ project.
I need to use my own COM object written in C# (this COM allows me to directly print PDF files) in my another project in C++, but as soon as I call some COM functions which require a string parameter (output file path) my COM throws an exception: Illegal characters in path. So I used for (int i = 0; i < mDocumentFileName.Length; i++) and I found out that at the end of the string there is a \0 character. As far as I know a typical string ends with \0 so the Lenght param should return the number of character before the \0 is reached so if the mDocumentFileName = "out.pdf" it should ends with 'f' not with '\0'. In Borland C++, I use AnsiToOLESTR to convert ansi strings to wchar_t strings.

What's wrong? Or how to solve this?
Thanks.

Recommended Answers

All 2 Replies

Create a small program to test out that function and find out how it works. I don't use that compiler so I can't help you very much. Working with small two or three line programs is a lot easier than trying to work with large programs and DLLs.

Member Avatar for Thew

My testing program contains this:

pdf->InitializeDocument(AnsiToOLESTR("out.pdf"));
pdf->SaveDocument();

AnsiToOLESTR generates wide string from ansi string that I use.
My C# COM only copies the string and uses it when I call pdf->SaveDocument(), but at that line: mPdfDocument.Save(mDocumentFileName); an exception is thrown because another \0 character appears at the end of the string caused by the Length which returns "original length + 1". I have to use this:
String tmp = mDocumentFileName.Substring(0, mDocumentFileName.Length - 1);
mPdfDocument.Save(tmp);
instead to make it working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.