Solved

How to access a char* in DLL using c#

Posted on 2009-04-07
4
216 Views
Last Modified: 2012-05-06
I'm using c#2008 exporess.

I have a dll contain a function
int test(char* str); written by other C languge.

I try to read the string in the function but always get error and it seems to be unsafe.
Hence, how to get the string in the function above?
Thank you.
0
Comment
Question by:xuanspider
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
Chris-in-Clapham earned 500 total points
ID: 24085421
Assuming you are using DLLImport or similar construction to access the DLL then you will need to pass a StringBuilder object into the method.
0
 

Author Comment

by:xuanspider
ID: 24093195
I think I did not explain clearly. The Dll is not compiled by visio studio, is compiled by other C language "labwindow". It only supports char*, but when I using char[] to read the function. C# does not allowed me to do so no matter I use ref or out keyword.  Is there any solution?
0
 

Author Closing Comment

by:xuanspider
ID: 31567397
Solve already. I never notice that char in vs2008 is 2 byte. Thank you.
0
 
LVL 1

Expert Comment

by:Chris-in-Clapham
ID: 24094732
Do you have a code example to show what you have tried? A short piece of code and the associated error message will make it a lot clearer as to exactly what you are trying to achieve.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET Web API or ASP.NET Core MVC? 3 51
XAML: Layout 8 25
Server Error 11 47
Eagerly loading related objects in entity framework 5 23
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now