VSTO calling unmanged function

S

scot_paro

Hi, I'm really struggling with this so any help would be appreciated.
Outlook 2007, VS2008 Pro, VSTO 3, XP Pro x64 (dev) and x32 (test).

I've a C++ dll with a bunch of functions to handle the registry, som
custom authentication of the product, and some comms. I'd rather no
have to rewrite them in VB.NET/C# (I'm primarily a C++ developer).
There are extern "C" wrappers for the C++ calls.

The product was originally done in VBA, and everything works fine ther
:)

I've written an add-in and I've got the pinvoke stuff in place. I ca
call Win32 functions - for testing, I pop up a message box and get th
system directory. All is well, works exactly as I'd expect.
However, when I call the functions in my unmanaged dll, the function
get entered, but their arguments are garbage. I'm passing in
StringBuilder to get a string of text back, but writing to th
StringBuilder parameter in the unmanged function (wchar_t*) causes a
access violation.
I've written a test project to make sure there's nothing funny with m
machine setup. I've got my unmanaged dll and a VB.NET console app. Th
unmanaged functions return an int, accept a string, modify the string a
a side effect, and it all works fine.
But, when I do exactly the same thing in the add-in, it fails :(

Is there something I'm missing? Is this a CAS issue? Does VSTO jus
not like unmanaged code? :confused:

Thanks.
-R
 
K

Ken Slovak - [MVP - Outlook]

What if instead of passing a StringBuilder object you pass a string and
Marshal it as UnmanagedType.BStr, does that work?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top