PC Review


Reply
Thread Tools Rate Thread

Calling a DLL with LPSTR parameters

 
 
Arnau Font
Guest
Posts: n/a
 
      4th May 2005
Hi,

I'm trying to invoke a function in a DLL, using DllImport. One of the
parameters is a ANSI string, but the CharSet enumeration has only the Auto
and Unicode members. How can I send a string in ANSI to the DLL?


[DllImport("Protocol.dll", CharSet = CharSet.Auto)]
static extern int Configure(string password, uint pwdSize); //The password
should be passed as ANSI

Thanks!


 
Reply With Quote
 
 
 
 
José Miguel Torres
Guest
Posts: n/a
 
      4th May 2005
Try using StringBuilder.

regards


--
José Miguel Torres
jtorres_diaz~~ARROBA~~terra.es
http://jmtorres.blogspot.com

"Arnau Font" <(E-Mail Removed)> escribió en el mensaje
news:%(E-Mail Removed)...
> Hi,
>
> I'm trying to invoke a function in a DLL, using DllImport. One of the
> parameters is a ANSI string, but the CharSet enumeration has only the Auto
> and Unicode members. How can I send a string in ANSI to the DLL?
>
>
> [DllImport("Protocol.dll", CharSet = CharSet.Auto)]
> static extern int Configure(string password, uint pwdSize); //The password
> should be passed as ANSI
>
> Thanks!
>
>



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      4th May 2005
use:-
[DllImport("Protocol.dll")]
static extern int Configure(byte[] password, uint pwdSize); //The password
should be passed as ANSI

And use System.Text.Encoding.ASCII.GetBytes() to get the byte array for your
string, and pass this into the function.

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

"Arnau Font" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I'm trying to invoke a function in a DLL, using DllImport. One of the
> parameters is a ANSI string, but the CharSet enumeration has only the Auto
> and Unicode members. How can I send a string in ANSI to the DLL?
>
>
> [DllImport("Protocol.dll", CharSet = CharSet.Auto)]
> static extern int Configure(string password, uint pwdSize); //The password
> should be passed as ANSI
>
> Thanks!
>
>



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      4th May 2005
Why you do not want to modify native part that it would receive UNICODE
string?

If this is impossible, you can try to pass your string as byte array:

byte [] b = System.Text.Encoding.ASCII.GetBytes("Password");
Configure(b, b.Length);

....

[DllImport("Protocol.dll")]
static extern int Configure(byte [] password, int pwdSize);

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com


Arnau Font wrote:
> Hi,
>
> I'm trying to invoke a function in a DLL, using DllImport. One of the
> parameters is a ANSI string, but the CharSet enumeration has only the Auto
> and Unicode members. How can I send a string in ANSI to the DLL?
>
>
> [DllImport("Protocol.dll", CharSet = CharSet.Auto)]
> static extern int Configure(string password, uint pwdSize); //The password
> should be passed as ANSI
>
> Thanks!
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling access with parameters rwboyden via AccessMonster.com Microsoft Access VBA Modules 3 6th Jul 2007 12:44 AM
PInvoke with LPSTR parameters problem Asfar Microsoft VC .NET 7 12th Mar 2006 09:09 PM
Calling DLL - Parameters not being sent over? =?Utf-8?B?QVJUTUlD?= Microsoft C# .NET 1 20th Feb 2005 11:58 PM
Calling procedure from another WKB with parameters =?Utf-8?B?QWppdA==?= Microsoft Excel Programming 5 18th Nov 2004 10:43 PM
Calling Url with form parameters in c# ? WJ Microsoft C# .NET 4 19th Feb 2004 09:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.