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?

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.

My testing program contains this:


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);
instead to make it working.

This article has been dead for over six months. Start a new discussion instead.