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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
devgrt - 31 Jan 2006 16:27 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. It
fails. Could anyone help me fix this code to what it should be. Thank you!

eVC DLL:
int mydll(LPSTR s)
{
   char data[40];
   strcpy(data, s);
}

C# calling the DLL:
[DllImport("MyCProcess.dll")]
public static extern int mydll(string s);
int r = mydll("teststring");
Paul G. Tobey [eMVP] - 31 Jan 2006 16:38 GMT
Fails how?  C# strings, it should be clear, are always Unicode, not ASCII.
If you're counting on the string to consist of 8-bit characters, you're
wrong and it's probably showing you just the first character.

Paul T.

>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. It
[quoted text clipped - 11 lines]
> public static extern int mydll(string s);
> int r = mydll("teststring");
Chris Tacke, MVP - 31 Jan 2006 17:18 GMT
CE is unicode, so you shouldn't be using char, but instead either wchar_t or
the TCHAR macro, along with the right copy function.

-Chris

>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. It
[quoted text clipped - 11 lines]
> public static extern int mydll(string s);
> int r = mydll("teststring");

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.