I have a piece of C# code that needs to convert a string array to a LPCWSTR to pass to a Win32 API function. I can’t find nothing in the Marshal class that makes it straightforward. Does anybody knows how to do that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should declare the API function as taking a string array. Since it’s declared as constant, you should add an
Inattribute so that it’s not marshalled back after the call. If the function truly only has a unicode version as you’ve specified (i.e., it takesLPCWSTRand notLPCTSTR), then you should declare it withCharSet=Unicode. Similar to:What API function are you trying to call? If you post it, I can give you a good P/Invoke signature for it. Or you can check pinvoke.net, which has a pretty good pre-compiled list (community-generated) of P/Invoke signatures.