Click here to Skip to main content
15,902,894 members
Home / Discussions / C#
   

C#

 
AnswerRe: anyone help with this ??? Pin
DavidNohejl16-Apr-05 1:13
DavidNohejl16-Apr-05 1:13 
AnswerRe: anyone help with this ??? Pin
Heath Stewart16-Apr-05 8:30
protectorHeath Stewart16-Apr-05 8:30 
QuestionHow to use CStringArray in C# using p/invoke Pin
shusong15-Apr-05 23:57
shusong15-Apr-05 23:57 
AnswerRe: How to use CStringArray in C# using p/invoke Pin
Heath Stewart16-Apr-05 8:23
protectorHeath Stewart16-Apr-05 8:23 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
shusong16-Apr-05 15:00
shusong16-Apr-05 15:00 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
Heath Stewart16-Apr-05 22:53
protectorHeath Stewart16-Apr-05 22:53 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
shusong16-Apr-05 23:19
shusong16-Apr-05 23:19 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
Heath Stewart16-Apr-05 23:47
protectorHeath Stewart16-Apr-05 23:47 
If you look at the documentation for the CStringArray class, you'd see that it's declared in atlcoll.h, which you can find in the Vc7\atlmfc\include directory under your VS.NET installation path. Looking at it's definition, you can find that it has fields defined like so:
CString* m_pData;
INT_PTR m_nSize;
INT_PTR m_nMaxSize;
INT_PTR m_nGrowBy;
The CString class is defined in cstringt.h, and extends the CSimpleStringT, which contains on member, PXSTR and is defined in atlsimpstr.h. PXSTR is a typedef of a templated class. CString is a platform-specific character set, being ANSI on Windows 9x/Me and Unicode on Windows NT-based platforms like XP.

This means you should be able to define a class like so:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
class CStringArray
{
  public string[] m_pData;
  IntPtr m_nSize;
  IntPtr m_nMaxSize;
  IntPtr m_nGrowBy;
}
You should declare your P/Invoke method like so:
[DllImport("mydll.dll", CharSet=CharSet.Auto)]
static extern void GetString(out CStringArray strarr);
Try this and it should work for you.

You should not expose your P/Invoke method publicly, but instead encapsulate it in a method that is exposed publicly and removes the burden of having to work with natively-defined data, which isn't always so nice to work with in managed code.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft

[My Articles] [My Blog]
GeneralRe: How to use CStringArray in C# using p/invoke Pin
shusong17-Apr-05 1:04
shusong17-Apr-05 1:04 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
shusong17-Apr-05 15:15
shusong17-Apr-05 15:15 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
Heath Stewart17-Apr-05 16:28
protectorHeath Stewart17-Apr-05 16:28 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
shusong17-Apr-05 16:49
shusong17-Apr-05 16:49 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
Heath Stewart18-Apr-05 6:59
protectorHeath Stewart18-Apr-05 6:59 
GeneralRe: How to use CStringArray in C# using p/invoke Pin
ttcchh200812-Jun-10 3:14
ttcchh200812-Jun-10 3:14 
Questionhow to implement WHITEBOARD for many users Pin
xinxin_52515-Apr-05 23:33
xinxin_52515-Apr-05 23:33 
AnswerRe: how to implement WHITEBOARD for many users Pin
Colin Angus Mackay15-Apr-05 23:48
Colin Angus Mackay15-Apr-05 23:48 
GeneralURI format not supported Pin
Adnan Siddiqi15-Apr-05 22:29
Adnan Siddiqi15-Apr-05 22:29 
GeneralRe: URI format not supported Pin
Heath Stewart16-Apr-05 8:18
protectorHeath Stewart16-Apr-05 8:18 
GeneralRe: URI format not supported Pin
Adnan Siddiqi17-Apr-05 6:00
Adnan Siddiqi17-Apr-05 6:00 
GeneralRe: URI format not supported Pin
Heath Stewart17-Apr-05 16:24
protectorHeath Stewart17-Apr-05 16:24 
GeneralFun with collections... Pin
tantiboh15-Apr-05 22:13
tantiboh15-Apr-05 22:13 
GeneralRe: Fun with collections... Pin
Colin Angus Mackay15-Apr-05 23:37
Colin Angus Mackay15-Apr-05 23:37 
GeneralRe: Fun with collections... Pin
tantiboh16-Apr-05 6:29
tantiboh16-Apr-05 6:29 
GeneralVS.NET 2003 IDE Pin
pmasknguyen15-Apr-05 18:43
pmasknguyen15-Apr-05 18:43 
GeneralRe: VS.NET 2003 IDE Pin
leppie15-Apr-05 21:05
leppie15-Apr-05 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.