PInvoke and QueryPathOfRegTypeLib

While writing a Nant task that resolves a type library guid and version to a path using QueryPathOfRegTypeLib via pinvoke I ran into a bit of trouble. When I used my task the tlbimp task complained that it wasn’t given a valid path. Apparently an extra ‘\0’-char is added to the end of the string returned by QueryPathOfRegTypeLib. I couldn’t figure out why it was added, don’t think there is anything wrong with the pinvoke declaration I got from from pinvoke.net, so for now I just strip the last character of the path in the task.

So now I can build my projects from scratch even if they require an interop assembly without hardcoding the path to the type library used.

Update: Just saw that the guy who wrote the signature on pinvoke.net wrote a small note about this after I asked him about it. Link.

Leave a Reply

Your email address will not be published.