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
Harish Iyer
NA
58
0
Passing string from C# to C++
Oct 27 2009 5:16 AM
Hello,
I have a C# client in which I make a call to a C++ DLL. The C++ code looks as follows ;
BYTE mmc_write(unsigned long addr, BYTE* Buffer)
{
}
On the C# side, I have declared the function as
[DllImport("somecpp.dll")
internal static extern byte mmc_write(ulong addr, [MarshalAs(UnManagedType.LPStr)]string sendBuffer);
and I use it in a function as below :
int Send(string sData)
{
byte yRet = mmc_write(0, sData);
if(yRet > 0)
retutn sData.Length;
return 0;
}
Now when I debug, I see that the string received on the C++ side is a bad pointer. I tried wrapping the string in C# to a StringBuilder also, but to no avail.
Am I doing something wrong here ? It would be great if someone can help me in this
Reply
Answers (
2
)
Connecting VB.NET with Excel 2007 & Access 2007
Call a native C++ dll from My C# windows app