Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   VSTO calling unmanged function (http://www.outlookbanter.com/add-ins-outlook/94609-vsto-calling-unmanged-function.html)

scot_paro September 7th 09 05:38 PM

VSTO calling unmanged function
 

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? :confused:

Thanks.
-R.


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


Ken Slovak - [MVP - Outlook] September 8th 09 04:21 PM

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? :confused:

Thanks.
-R.


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




All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com