Click here to Skip to main content
15,918,742 members
Home / Discussions / C#
   

C#

 
GeneralRe: String Array in C# Pin
Michael P Butler14-Feb-04 21:34
Michael P Butler14-Feb-04 21:34 
QuestionUnmanaged Dlls ? Pin
veselin_iordanov14-Feb-04 15:40
veselin_iordanov14-Feb-04 15:40 
AnswerRe: Unmanaged Dlls ? Pin
leppie14-Feb-04 19:51
leppie14-Feb-04 19:51 
GeneralRe: Unmanaged Dlls ? Pin
veselin_iordanov15-Feb-04 6:57
veselin_iordanov15-Feb-04 6:57 
AnswerRe: Unmanaged Dlls ? Pin
Heath Stewart16-Feb-04 5:13
protectorHeath Stewart16-Feb-04 5:13 
GeneralRe: Unmanaged Dlls ? Pin
veselin_iordanov16-Feb-04 9:21
veselin_iordanov16-Feb-04 9:21 
GeneralRe: Unmanaged Dlls ? Pin
Heath Stewart16-Feb-04 9:26
protectorHeath Stewart16-Feb-04 9:26 
GeneralRe: Unmanaged Dlls ? Pin
veselin_iordanov16-Feb-04 9:32
veselin_iordanov16-Feb-04 9:32 
GeneralRe: Unmanaged Dlls ? Pin
Heath Stewart16-Feb-04 9:51
protectorHeath Stewart16-Feb-04 9:51 
GeneralRe: Unmanaged Dlls ? Pin
veselin_iordanov16-Feb-04 9:56
veselin_iordanov16-Feb-04 9:56 
GeneralRe: Unmanaged Dlls ? Pin
Heath Stewart16-Feb-04 10:30
protectorHeath Stewart16-Feb-04 10:30 
GeneralRe: Unmanaged Dlls ? Pin
veselin_iordanov16-Feb-04 12:27
veselin_iordanov16-Feb-04 12:27 
GeneralRe: Unmanaged Dlls ? Pin
Heath Stewart17-Feb-04 2:41
protectorHeath Stewart17-Feb-04 2:41 
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
GeneralChanging Control Locations In C# Pin
Eric Houser14-Feb-04 12:16
Eric Houser14-Feb-04 12:16 
GeneralRe: Changing Control Locations In C# Pin
Colin Angus Mackay14-Feb-04 13:27
Colin Angus Mackay14-Feb-04 13:27 
GeneralRe: Changing Control Locations In C# Pin
Bo Hunter15-Feb-04 7:38
Bo Hunter15-Feb-04 7:38 
GeneralRichTextBox, Scroll Bars and VScroll Event Pin
je_gonzalez14-Feb-04 11:03
je_gonzalez14-Feb-04 11:03 
GeneralCommunication between webservice and win application Pin
Anonymous14-Feb-04 10:59
Anonymous14-Feb-04 10:59 
GeneralRe: Communication between webservice and win application Pin
Mazdak14-Feb-04 19:49
Mazdak14-Feb-04 19:49 
GeneralRe: Communication between webservice and win application Pin
Anonymous14-Feb-04 21:26
Anonymous14-Feb-04 21:26 
GeneralRe: Communication between webservice and win application Pin
Mazdak14-Feb-04 21:30
Mazdak14-Feb-04 21:30 
GeneralRe: Communication between webservice and win application Pin
naxos15-Feb-04 20:10
naxos15-Feb-04 20:10 
GeneralNeed Help In Socket Programming Pin
Amoola14-Feb-04 10:15
Amoola14-Feb-04 10:15 
GeneralRe: Need Help In Socket Programming Pin
Colin Angus Mackay14-Feb-04 10:53
Colin Angus Mackay14-Feb-04 10:53 
GeneralShellnotifications Pin
Lesuran14-Feb-04 9:56
Lesuran14-Feb-04 9:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.