By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,464 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

convert string to char*

P: 8
i need to send a string from a text box to a certain
function that receives char* type
how can i do the convertion?
Mar 11 '09 #1
Share this Question
Share on Google+
6 Replies

Expert 2.5K+
P: 3,525
What have you tried so far?
What did MSDN have to say on this?
What about a search right here on Bytes?

Thread 250052
Mar 11 '09 #2

P: 8
well , im not sure i understood what was the solution in that thread, but
this is what i did :

the C function header (in the C dll called genclient.dll):

int genLogin(char * name);

and this is the C# code:
Expand|Select|Wrap|Line Numbers
  1. [DllImport("genClient.dll", EntryPoint = "genLogin",SetLastError = false, CharSet = CharSet.Auto)]
  2. public static extern int genLogin(string name);
  4. //and this is the call to the function:
  6. int reply;
  7. string s;
  8. reply = genLogin(s);
but now, c# cant find the enrty point genLogin...
what did i do wrong?
Mar 12 '09 #3

Expert 2.5K+
P: 3,525
It can't find the entry point... Or it doesn't like you trying to call it with an argument of 's' which has not been initialized yet? (s has no value when you try to use it in line 8)
Mar 12 '09 #4

Expert 100+
P: 229
Check this link for some examples on P/Invoke: There is also a download link for a "PInvoke Interop Assistant" tool, which helps you create the correct DllImport signature (if you did a mistake).

You can get detailed info on string marshalling on this link:
Mar 12 '09 #5

P: 8
now ive tried something else...

the C function header is this:

__declspec(dllexport) int genLogin(char * name);

and my decleration is this:

[DllImport("genClient.dll", EntryPoint = "genLogin", ExactSpelling = false, SetLastError = true)]
public static extern int genLogin([MarshalAs(UnmanagedType.LPArray)] byte[] name);

the call to the function is done in this way:

byte[] str = new byte[100];
textBox1.Text = Convert.ToString((genLogin(str)));

but still i get the following error:

Unable to find an entry point named 'genLogin' in DLL 'genClient.dll'.

any more suggestions?

Mar 12 '09 #6

Expert 100+
P: 229
Use the dumpbin.exe tool to make sure that you have the correct entry point name in C++.
Mar 13 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.