C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
PLS HELP: How give string from C# to C++ char *!!!!!!!!!! Posted by Falke on 27 Nov 2003 at 7:57 AM
Hi all,

also,my problem is:

I have a DLL in C++
and I want link a function of this DLL in the programm language C#:

my problem is passing this string "COM1" from C# to the
type char *port .


---------------------------------------------------------------------
---C++ DLL---
extern "C" _declspec(dllexport) double getT_AV (long baud, char *port)
{
//port should point at "COM1" :char *port = "COM1"
...
}
---
---My C# Code---this code doesn't working
[DllImport("ChamberDriver.dll")]
public static extern double getT_AV(long baud,string port);

private void get_Temp_Click(object sender, System.EventArgs e)
{

long baud = 19200;
string port ="COM1"

double temp = getT_AV (baud,port);

Output.Text = temp.ToString();

}
---
----------------------------------------------------------------------
I hope my description is understandable ;)

thank you for Help !!!
Report
Re: PLS HELP: How give string from C# to C++ char *!!!!!!!!!! Posted by pingpong on 28 Nov 2003 at 5:56 AM
Your problem is not with the string, but since you asked, here's the rule:
- If the DLL is going to change the content of the string (const char*), pass an System.Text.StringBuilder object
- If the DLL is not changing the content, (char*), pass a string.

Now, your real problem is with the "long", C/C++ long is 32-bit, .NET long is 64. So change C# decleration getT_AV(int baud, string ..etc) and you should be fine


: Hi all,
:
: also,my problem is:
:
: I have a DLL in C++
: and I want link a function of this DLL in the programm language C#:
:
: my problem is passing this string "COM1" from C# to the
: type char *port .
:
:
: ---------------------------------------------------------------------
: ---C++ DLL---
: extern "C" _declspec(dllexport) double getT_AV (long baud, char *port)
: {
: //port should point at "COM1" :char *port = "COM1"
: ...
: }
: ---
: ---My C# Code---this code doesn't working
: [DllImport("ChamberDriver.dll")]
: public static extern double getT_AV(long baud,string port);
:
: private void get_Temp_Click(object sender, System.EventArgs e)
: {
:
: long baud = 19200;
: string port ="COM1"
:
: double temp = getT_AV (baud,port);
:
: Output.Text = temp.ToString();
:
: }
: ---
: ----------------------------------------------------------------------
: I hope my description is understandable ;)
:
: thank you for Help !!!
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.