This is a multi-part message in MIME format.
------=_NextPart_000_00EE_01C56763.DC1E8CA0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
(I post this message again, but with a more appropriate title)
I have some problem to control finely the signature of some a PInvoke =
Method I want to dynamically generate.
Let say, if it was staticaly declared it would look like that:
---------------------------
struct MyStruct
{
int a;
int b;
}
[DllImport("dllname", EntryPoint=3D"name", CharSet=3DAnsi)]
string MyFunction(
[MarshalAs(LPWStr)] string s1,=20
[MarshalAs(LPWStr)] StringBuffer buf,
string s2,=20
ref MyStruct m,=20
out int u);
---------------------------
I thought of something like that (but the marshall & ref/out information =
is missing, hence my question)
---------------------------
AssemblyBuilder ab =3D .......;
TypeBuilder ab.DefineType("aType", TypeAttribute.Public);
MethodBuilder mb =3D tb.DefinePInvokeMethod(
"MyFunction",
"dllname",
"name",
MthdAttr.PinvokeImpl | MthdAttr.Static | MthdAttr.Public,
CallingConventions.Standart | CallingConvention.Varargs,
typeof(string),=20
// how to setup the out/ref/marshallasattribute for the type below?
new Type[]{ typeof(string), typeof(StringBuffer), typeof(string), =
typeof(MyStruct), typeof(int) },
CallingConvention.Cdecl,
CharSet.Ansi
);
// for some reason this flag (below) required
// of course I want to preserve the Signature, what kind of flag it is =
?!?!?!
mb.SetImplementationFlags(MethodImplAttributes.PreserveSig);=20
I think (but not tested yet) that I might solve part of the problem (the =
ref/out) with call to
mb.DefineParameter(4, ParameterAttributes.Retval, null)=20
mb.DefineParameter(5, ParameterAttributes.Out, null)
but=20
1. I'm not sure it will work (a bit difficult to test)
2. what about the ANSI/Unicode marshalling?
Any tip?
thanks!
------=_NextPart_000_00EE_01C56763.DC1E8CA0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2627" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD><FONT face=3DArial><FONT size=3D2>
<BODY>
<DIV>
<DIV><FONT face=3DArial size=3D2>(<EM><FONT color=3D#0000ff>I post this =
message again,=20
but with a more appropriate title</FONT></EM>)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I have some problem to control finely =
the signature=20
of some a PInvoke Method I want to dynamically generate.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Let say, if it was staticaly declared =
it would look=20
like that:</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>---------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>struct MyStruct</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> int a;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> int b;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>[DllImport("dllname", =
EntryPoint=3D"name",=20
CharSet=3DAnsi)]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>string MyFunction(</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> [MarshalAs(LPWStr)] =
string s1,=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> [MarshalAs(LPWStr)] =
StringBuffer=20
buf,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> string s2, =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> ref MyStruct m, =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> out int =
u);</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>---------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I thought of something like that (<FONT =
color=3D#ff0000>but the marshall & ref/out information is missing, =
hence my=20
question</FONT>)</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>---------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>AssemblyBuilder ab =3D =
.......;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>TypeBuilder ab.DefineType("aType",=20
TypeAttribute.Public);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>MethodBuilder mb =3D=20
tb.DefinePInvokeMethod(</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
"MyFunction",</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
"dllname",</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> "name",</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> MthdAttr.PinvokeImpl =
|=20
MthdAttr.Static | MthdAttr.Public,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
CallingConventions.Standart |=20
CallingConvention.Varargs,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> typeof(string), =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <FONT =
color=3D#008080>// how to=20
setup the out/ref/marshallasattribute for the type =
below?</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> new Type[]{ =
typeof(string),=20
typeof(StringBuffer), typeof(string), typeof(MyStruct), typeof(int)=20
},</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =20
CallingConvention.Cdecl,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
CharSet.Ansi</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>);</FONT></DIV>
<DIV><FONT face=3DArial color=3D#008080 size=3D2>// for some reason =
this flag=20
(below) required</FONT></DIV>
<DIV><FONT face=3DArial color=3D#008080 size=3D2>// of course I want to =
preserve the=20
Signature, what kind of flag it is ?!?!?!</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>mb.SetImplementationFlags(MethodImplAttributes.PreserveSig);=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I think (but not tested yet) that I =
might solve=20
part of the problem (the ref/out) with call to</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>mb.DefineParameter(4, =
ParameterAttributes.Retval,=20
null)=20
<DIV><FONT face=3DArial size=3D2>mb.DefineParameter(5, =
ParameterAttributes.Out,=20
null)</FONT></DIV>
<DIV> </DIV>
<DIV>but </DIV>
<DIV>1. I'm not sure it will work (a bit difficult to test)</DIV>
<DIV>2. what about the ANSI/Unicode marshalling?</DIV>
<DIV> </DIV>
<DIV>Any tip?</DIV>
<DIV>thanks!</DIV></FONT></DIV></FONT></DIV></DIV></BODY></HTML></FONT></=
FONT>
------=_NextPart_000_00EE_01C56763.DC1E8CA0--