Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / January 2006

Tip: Looking for answers? Try searching our database.

Pass C# string to eVC DLL (Part 2)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
devgrt - 31 Jan 2006 18:52 GMT
I have an eVC DLL that I call from C#. I want to pass a C# string to the dll
and then copy that string's data into a char buffer as shown below.

I tried a different method (from my last post) but something is still
wrong -- I only get two random characters instead of the whole string...

eVC DLL:
int fn1(char *s)
{
   char *data = new char[40];
   strcpy(data, s);
   //data is not correct at this point
}

C# calling the DLL:
[DllImport("MyCProcess.dll")]
public static extern int fn1(byte [] s);
byte [] s = System.Text.Encoding.Unicode.GetBytes("this is a test string");
int r = fnl(s);

Thank for any help!
devgrt - 31 Jan 2006 18:58 GMT
OK -- I see the error:
I had:
 byte [] s = System.Text.Encoding.Unicode.GetBytes("this is a test
string");
should be:
 byte [] s = System.Text.Encoding.ASCII.GetBytes("this is a test string");

>I have an eVC DLL that I call from C#. I want to pass a C# string to the
>dll
[quoted text clipped - 19 lines]
>
> Thank for any help!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.