TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sunil bansal
NA
2
0
Problem in Getting the exact char[] data from C++ to C# String
Dec 22 2006 10:51 AM
Hi,
I am facing a problem while accessing a C++ dll from C# code.
Following is my C++ structure I am using...
typedef struct
{
LONG lPaBitNr;
UCHAR szPaAbr[8];
} AudioUnit_T_DataType;
and corresponding structure I am using in Dot Net is:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct AudioUnit_T_DataType
{
public int paBitNr;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=8)]
public String paAbr;
}
and following is my declaration of the function of C++ dll.
[DllImport("MyLib.dll", EntryPoint = "MyFunc")]
public static extern int MyFunc(
[MarshalAs(UnmanagedType.AsAny)]
object key,
[MarshalAs(UnmanagedType.AsAny),In, Out]
object data,
int size
);
size is the respective size of the structure (no of bytes to copy in data object)
When I call the MyFunc function with object data as AudioUnit_T_DataType structure,, i got all the data but I always loose the last character (8th) in the String paAbr.
i.e. suppose, the value of szPaAbr[8] was "abcdefgh"
then, after the call of MyFunc function, i got "abcdefg" value.. 'h' is lost (might be it is replaced by null character...)
What should I do to overcome this issue.
I dont want to change the lenght of array from 8 to 9.
Any help is appreciable.
Reply
Answers (
1
)
Retrieve data from SQL stored procedure in Excel spreadsheet
How can I insert Controls (eg. listbox, combobox) in Excel automation with events using C#