I just noticed, the strings are BSTRs. In this case, they are unicode and must be handled as such. The following should work:
[DllImport("endecode.dll", CharSet=CharSet.Unicode /* Optional in this case */,
CallingConvention=CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.BStr)]
static extern string decode([MarshalAs(UnmanagedType.BStr)]string data);
BSTR is #defined as wchar_t, which is a wide character. This will never by ANSI on any platform. Before you posted something that implied the string was ANSI. Also, make sure your C function declaration uses the C style declaration, otherwise it will be decorated. Since VB can all it, it's probably already correct. You can make sure by using the Dependency Walker (depends.exe), which is part of the Platform SDK and - if you choose the default options when installing VS.NET - should be in the <VS.NET Install Dir>\Vc7\PlatformSDK\bin directory. Open your unmanaged library and you should see the exported function. There should be no decoration (i.e., ordinals, etc.) on the function. If there is, you can forward-declare it like so:
#ifdef __cplusplus
extern "C" {
#endif
BSTR __stdcall decode(BSTR data);
#ifdef __cplusplus
}
#endif
You can use a .DEP file, too, but that's "out-dated".
Microsoft MVP, Visual C# My Articles