IT Community - Software Programming, Web Development and Technical Support

How to Pass a string value from vc++ .net dll to c#?

This is a discussion on How to Pass a string value from vc++ .net dll to c#? within the C and C++ Programming forums, part of the Software Development category; How to Pass a string value from vc++ .net dll to c#?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 05:07 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Question How to Pass a string value from vc++ .net dll to c#?

How to Pass a string value from vc++ .net dll to c#?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 05:37 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to Pass a string value from vc++ .net dll to c#?

Pass a string values from VC++ dll to C#.


Goals:

This project is a sample for sendind string value from VC++ dll to c#.

Steps:

1) copy the following code in vc++ dll project.

SAMPLE_API const char * OpenFile(const char *file)
{
std::string sample = "test";
char *Val = new char[sample.length() + 1];
strcpy(Val, sample.c_str());
return Val;
}

2) run the code and use this dll in C#

3) copy the following code in C#.

[DllImport("sample.dll", EntryPoint = "OpenFile")]
private static extern string OpenFile(string fileName);

private void Btn_Browse_Click(object sender, EventArgs e)
{
string Data = OpenFile(fileName);
MessageBox.Show(Data);
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is diffrenece between string.compare and string.compareordinal shaalini ASP and ASP.NET Programming 3 12-28-2007 10:46 PM
Is it possible to Pass Query String to Javascript? velhari HTML, CSS and Javascript Coding Techniques 1 11-20-2007 10:47 PM
how to pass and retrieve variable(query string) in same page using ajax? ursklakshmanan PHP Programming 0 09-17-2007 12:05 PM
How to pass array of string from vc++ dll to C# ? kingmaker C and C++ Programming 2 08-10-2007 05:35 AM
What is the main difference between pass-by-reference and pass-by-value? oxygen Java Programming 2 08-07-2007 01:15 AM


All times are GMT -7. The time now is 04:10 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0