View Single Post
  #2  
Old September 8th 09, 04:21 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VSTO calling unmanged function

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"scot_paro" scot_paro.3y5jco@invalid wrote in message
news:scot_paro.3y5jco@invalid...

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, some
custom authentication of the product, and some comms. I'd rather not
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 there


I've written an add-in and I've got the pinvoke stuff in place. I can
call Win32 functions - for testing, I pop up a message box and get the
system directory. All is well, works exactly as I'd expect.
However, when I call the functions in my unmanaged dll, the functions
get entered, but their arguments are garbage. I'm passing in a
StringBuilder to get a string of text back, but writing to the
StringBuilder parameter in the unmanged function (wchar_t*) causes an
access violation.
I've written a test project to make sure there's nothing funny with my
machine setup. I've got my unmanaged dll and a VB.NET console app. The
unmanaged functions return an int, accept a string, modify the string as
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 just
not like unmanaged code?

Thanks.
-R.


--
scot_paro
http://forums.slipstick.com


Ads