Hi Magnus,
I think you should not use the c# keyword out here, out keyword
indicates an parameter is being transferred by reference, which is not
applicable here.
This is the definition of your type,
//from Mattias
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct TtsrPlayerInfo
{
public int PlayerID;
public int ChannelID;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=30)]
public char[] NickName;
// or
//[MarshalAs(UnmanagedType.ByValTStr, SizeConst=30)]
//public string NickName;
public int PlayerChannelPrivileges;
public int PlayerPrivileges;
public int PlayerFlags;
}
class PInvoke
{
[DllImport("test.dll")]
public extern static int tsrGetPlayers([In,Out] TtsrPlayerInfo[]
tsrPlayers, ref int PlayerRecords);
}
your unmanaged function definition
int tsrGetPlayers(TtsrPlayerInfo *tsrPlayers,int *PlayerRecords);
You need create your array in managed code before passing it into your
function.
Here is a snippet from my test code.
<code>
int recs = 12;
TtsrPlayerInfo[] info = new TtsrPlayerInfo[recs];
Console.WriteLine(PInvoke.tsrGetPlayers(info,ref recs));
Console.WriteLine(info.Length);
foreach(TtsrPlayerInfo i in info)
{
Console.WriteLine(i.ChannelID);
Console.WriteLine(i.NickName);
Console.WriteLine(i.PlayerChannelPrivileges);
Console.WriteLine(i.PlayerFlags);
Console.WriteLine(i.PlayerID);
Console.WriteLine(i.PlayerPrivileges);
}
Console.Read();
</code>
Thanks, if you still have problems on it ,please let me know!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!
--------------------
| Reply-To: "Magnus Ullberg" <magnus@areaconsulting.us>
| From: "Magnus Ullberg" <magnus@areaconsulting.us>
| References: <#urrtoleDHA.2264@TK2MSFTNGP12.phx.gbl>
<uBGpHiteDHA.556@TK2MSFTNGP11.phx.gbl>
| Subject: Re: ExecutionEngineException when using a DLLImport call
| Date: Mon, 15 Sep 2003 08:33:05 -0500
[quoted text clipped - 8 lines]
| NNTP-Posting-Host: ky-owensboro1b-121.owboky.adelphia.net 24.52.178.121
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.interop:18727
| X-Tomcat-NG: microsoft.public.dotnet.framework.interop
[quoted text clipped - 27 lines]
| CurrentPlayers = new TtsrPlayerInfo[MAX_PLAYERS];
| int retval = tsrGetPlayers(CurrentPlayers, &CurrentPlayerCount);
Magnus Ullberg - 16 Sep 2003 14:08 GMT
Great, thanks a lot.
That works prefectly.
Do you have any suggestions on where to find more info about the [in,out]
declaration? I've never seen that before, it that basically a pointer?
Thanks,
Magnus Ullberg
Area Consulting Group, Inc.
> Hi Magnus,
> I think you should not use the c# keyword out here, out keyword
[quoted text clipped - 75 lines]
> | NNTP-Posting-Host: ky-owensboro1b-121.owboky.adelphia.net 24.52.178.121
> | Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
> phx.gbl!tk2msftngp13.phx.gbl
> | Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.interop:18727
[quoted text clipped - 29 lines]
> | CurrentPlayers = new TtsrPlayerInfo[MAX_PLAYERS];
> | int retval = tsrGetPlayers(CurrentPlayers, &CurrentPlayerCount);
Ying-Shen Yu[MSFT] - 16 Sep 2003 17:25 GMT
Hi Magnus,
It's my pleasure to help you solve your problem,
Thanks for using MSDN Newsgroup!
In, Out is Directional Attribute in CLR.
If you want to find more info about the these two attributes
you may search InAttribute and OutAttribute in your MSDN Index,
Or here is link
<InAttribute>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeInterop
ServicesInAttributeClassTopic.asp?frame=true
<OutAttribute>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeInterop
ServicesOutAttributeClassTopic.asp?frame=true
And there are also some examples on Interop comes with .NET Framework SDK
by default, they should be at,
\Program
Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Interop\PlatformInvoke\Cus
tom
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!
--------------------
| Reply-To: "Magnus Ullberg" <magnus@areaconsulting.us>
| From: "Magnus Ullberg" <magnus@areaconsulting.us>
| References: <#urrtoleDHA.2264@TK2MSFTNGP12.phx.gbl>
<uBGpHiteDHA.556@TK2MSFTNGP11.phx.gbl>
<e5laF54eDHA.576@tk2msftngp13.phx.gbl>
<8CD5syBfDHA.536@cpmsftngxa07.phx.gbl>
| Subject: Re: ExecutionEngineException when using a DLLImport call
| Date: Tue, 16 Sep 2003 08:08:53 -0500
[quoted text clipped - 8 lines]
| NNTP-Posting-Host: ky-owensboro1b-121.owboky.adelphia.net 24.52.178.121
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.interop:18753
| X-Tomcat-NG: microsoft.public.dotnet.framework.interop
[quoted text clipped - 88 lines]
| > | NNTP-Posting-Host: ky-owensboro1b-121.owboky.adelphia.net 24.52.178.121
| > | Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!tk2msftngp13.phx.gbl
| > | Xref: cpmsftngxa07.phx.gbl
[quoted text clipped - 30 lines]
| > | CurrentPlayers = new TtsrPlayerInfo[MAX_PLAYERS];
| > | int retval = tsrGetPlayers(CurrentPlayers, &CurrentPlayerCount);
Magnus Ullberg - 16 Sep 2003 20:19 GMT
> Hi Magnus,
> It's my pleasure to help you solve your problem,
> Thanks for using MSDN Newsgroup!
thanks for all the help
> If you want to find more info about the these two attributes
> you may search InAttribute and OutAttribute in your MSDN Index,
great, exactly what i was looking for