Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

How to access a char* in DLL using c#

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
xuanspider
Asked:
xuanspider
  • 2
  • 2
1 Solution
 
Chris-in-ClaphamCommented:
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
 
xuanspiderAuthor Commented:
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
 
xuanspiderAuthor Commented:
Solve already. I never notice that char in vs2008 is 2 byte. Thank you.
0
 
Chris-in-ClaphamCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now