|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Directors with C# attributes?When C++ code calls back into C# to make a virtual method
call (using the directors feature), I’m having a difficult time figuring
out how to enforce a MarshalAs attribute on the director functions. I
know how to use imtype’s and cstype’s inattribute/outattribute to
put C# attributes on the intermediate (PINVOKE) and wrapper classes, but I don’t
see anywhere in the documentation that it discusses putting C# attributes on
director functions. This seems critical in order to have full
functionality, so I must be missing something. Any help would be most appreciated! Thanks, Philip ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Directors with C# attributes?Philip Flesher wrote:
> When C++ code calls back into C# to make a virtual method call (using > the directors feature), I’m having a difficult time figuring out how to > enforce a MarshalAs attribute on the director functions. I know how to > use imtype’s and cstype’s inattribute/outattribute to put C# attributes > on the intermediate (PINVOKE) and wrapper classes, but I don’t see > anywhere in the documentation that it discusses putting C# attributes on > director functions. This seems critical in order to have full > functionality, so I must be missing something. The director methods use the types in the cstype and imtype typemaps. They also use the inattributes and outattributes specified in the cstype and imtype typemaps. The documentation mentions the cstype and imtype inattribute and outattribute typemap attributes. I just checked that the inattribute and outattribute code gets generated in the correct places for directors. It all looks okay, but didn't go as far as running any code. If you have any problems can you elaborate? William ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
|
|
|
Re: Directors with C# attributes?Your code is a bit hard to follow, I need to see the source, not just
the generated code. However, I think I've got it now and can see that there is no way to set a C# attribute on the delegate methods. I reckon we need a new type of attribute for this as the imtype inattributes and outattributes will need to be different. I have checked in some code which allows you to use new attributes, 'directorinattributes' and 'directoroutattributes' in the imtype typemap. Here is the test I used (for int): %typemap(imtype, inattributes="/*[imtypeinattributeint]*/", outattributes="/*[imtypeoutattributeint]*/", directorinattributes="/*[imtypedirectorinattributeint]*/", directoroutattributes="/*[imtypedirectoroutattributeint]*/", out="/*custom imtype-out*/ int") int "/*custom imtype*/ int" Can you try it out and let me know if it works and even better, provide me your typemaps with a testcase for future regression testing? William Philip Flesher wrote: > Thanks for writing, William. > > The problem is that the director delegates aren't tagged with the > attributes. For example: > > public virtual void BarClass([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1) { > //... > } > > private void SwigDirectorFooCallback(string arg1) { > FooCallback(arg1); > } > > public delegate void SwigDelegateModuleName_0(string arg1); > > > That code is generated by SWIG for a sample function, even though in my > interface file, I've done this: > > %typemap(cstype, > inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", > outattributes="[return: > MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const > std::string & "string" > > %typemap(imtype, > inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", > outattributes="[return: > MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const > std::string & "string" > > %feature("director") BarClass; > > > > As you can see, the delegate signature does not have the attributes on > it that I need. Only the virtual function (which is not the function > that is directly called by the C++ code) has the attributes. What this > means is that the C++ code calls the delegate without any explicit > marshalling, which causes default marshalling to be used. This wreaks > havoc on my UTF-8 encoded strings. > > I believe I need the delegate signature to look like this: > > private void > SwigDirectorFooCallback([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1) { > FooCallback(arg1); > } > > public delegate void > SwigDelegateModuleName_0([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1); > > > > Thanks for your help! > > - Philip > > -----Original Message----- > From: William Fulton [mailto:william@...] On Behalf Of > William S Fulton > Sent: Tuesday, January 15, 2008 5:07 PM > To: Philip Flesher > Cc: swig-user@... > Subject: Re: [Swig-user] Directors with C# attributes? > > Philip Flesher wrote: >> When C++ code calls back into C# to make a virtual method call (using >> the directors feature), I'm having a difficult time figuring out how > to >> enforce a MarshalAs attribute on the director functions. I know how > to >> use imtype's and cstype's inattribute/outattribute to put C# > attributes >> on the intermediate (PINVOKE) and wrapper classes, but I don't see >> anywhere in the documentation that it discusses putting C# attributes > on >> director functions. This seems critical in order to have full >> functionality, so I must be missing something. > The director methods use the types in the cstype and imtype typemaps. > They also use the inattributes and outattributes specified in the cstype > > and imtype typemaps. The documentation mentions the cstype and imtype > inattribute and outattribute typemap attributes. I just checked that the > > inattribute and outattribute code gets generated in the correct places > for directors. It all looks okay, but didn't go as far as running any > code. If you have any problems can you elaborate? > > William > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Swig-user mailing list > Swig-user@... > https://lists.sourceforge.net/lists/listinfo/swig-user > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Directors with C# attributes?Hi William,
Unfortunately, we're not in the position to be able to use the "bleeding edge" development version. We don't have compilation/build tools set up, and it's not something we have time to try to dig into. It sounds like I'm pretty much S.O.L. with the current version of SWIG, which is at least an answer I can deal with! I think we'll just have to do search-and-replace ourselves on the generated files. That will at least get me in a working state. Thanks for your assistance! - Philip -----Original Message----- From: William Fulton [mailto:william@...] On Behalf Of William S Fulton Sent: Friday, January 18, 2008 5:42 PM To: Philip Flesher Cc: swig-user@... Subject: Re: [Swig-user] Directors with C# attributes? Your code is a bit hard to follow, I need to see the source, not just the generated code. However, I think I've got it now and can see that there is no way to set a C# attribute on the delegate methods. I reckon we need a new type of attribute for this as the imtype inattributes and outattributes will need to be different. I have checked in some code which allows you to use new attributes, 'directorinattributes' and 'directoroutattributes' in the imtype typemap. Here is the test I used (for int): %typemap(imtype, inattributes="/*[imtypeinattributeint]*/", outattributes="/*[imtypeoutattributeint]*/", directorinattributes="/*[imtypedirectorinattributeint]*/", directoroutattributes="/*[imtypedirectoroutattributeint]*/", out="/*custom imtype-out*/ int") int "/*custom imtype*/ int" Can you try it out and let me know if it works and even better, provide me your typemaps with a testcase for future regression testing? William Philip Flesher wrote: > Thanks for writing, William. > > The problem is that the director delegates aren't tagged with the > attributes. For example: > > public virtual void BarClass([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1) { > //... > } > > private void SwigDirectorFooCallback(string arg1) { > FooCallback(arg1); > } > > public delegate void SwigDelegateModuleName_0(string arg1); > > > That code is generated by SWIG for a sample function, even though in > interface file, I've done this: > > %typemap(cstype, > inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", > outattributes="[return: > MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const > std::string & "string" > > %typemap(imtype, > inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", > outattributes="[return: > MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const > std::string & "string" > > %feature("director") BarClass; > > > > As you can see, the delegate signature does not have the attributes on > it that I need. Only the virtual function (which is not the function > that is directly called by the C++ code) has the attributes. What this > means is that the C++ code calls the delegate without any explicit > marshalling, which causes default marshalling to be used. This wreaks > havoc on my UTF-8 encoded strings. > > I believe I need the delegate signature to look like this: > > private void > SwigDirectorFooCallback([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1) { > FooCallback(arg1); > } > > public delegate void > SwigDelegateModuleName_0([MarshalAs(UnmanagedType.CustomMarshaler, > MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string > arg1); > > > > Thanks for your help! > > - Philip > > -----Original Message----- > From: William Fulton [mailto:william@...] On Behalf Of > William S Fulton > Sent: Tuesday, January 15, 2008 5:07 PM > To: Philip Flesher > Cc: swig-user@... > Subject: Re: [Swig-user] Directors with C# attributes? > > Philip Flesher wrote: >> When C++ code calls back into C# to make a virtual method call (using >> the directors feature), I'm having a difficult time figuring out how > to >> enforce a MarshalAs attribute on the director functions. I know how > to >> use imtype's and cstype's inattribute/outattribute to put C# > attributes >> on the intermediate (PINVOKE) and wrapper classes, but I don't see >> anywhere in the documentation that it discusses putting C# attributes > on >> director functions. This seems critical in order to have full >> functionality, so I must be missing something. > The director methods use the types in the cstype and imtype typemaps. > They also use the inattributes and outattributes specified in the > > and imtype typemaps. The documentation mentions the cstype and imtype > inattribute and outattribute typemap attributes. I just checked that the > > inattribute and outattribute code gets generated in the correct places > for directors. It all looks okay, but didn't go as far as running any > code. If you have any problems can you elaborate? > > William > > ------------------------------------------------------------------------ - > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Swig-user mailing list > Swig-user@... > https://lists.sourceforge.net/lists/listinfo/swig-user > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Directors with C# attributes?Hi William,
The 'directorinattributes' attribute seems to be present (and working) in SWIG 1.3.36 but I notice it's not mentioned in the 1.3 docs http://www.swig.org/Doc1.3/CSharp.html#CSharp. Has this been adopted as an officially supported feature (I hope it has) or is it not documented for a reason? Thanks, Evan
|
|
|
Re: Directors with C# attributes?I've mentioned these in the documentation for the next release. So I
guess that makes it official! William eodabash wrote: > Hi William, > > The 'directorinattributes' attribute seems to be present (and working) in > SWIG 1.3.36 but I notice it's not mentioned in the 1.3 docs > http://www.swig.org/Doc1.3/CSharp.html#CSharp. Has this been adopted as an > officially supported feature (I hope it has) or is it not documented for a > reason? > > Thanks, > Evan > > > wsfulton wrote: >> Your code is a bit hard to follow, I need to see the source, not just >> the generated code. However, I think I've got it now and can see that >> there is no way to set a C# attribute on the delegate methods. I reckon >> we need a new type of attribute for this as the imtype inattributes and >> outattributes will need to be different. I have checked in some code >> which allows you to use new attributes, 'directorinattributes' and >> 'directoroutattributes' in the imtype typemap. Here is the test I used >> (for int): >> >> %typemap(imtype, >> inattributes="/*[imtypeinattributeint]*/", >> outattributes="/*[imtypeoutattributeint]*/", >> directorinattributes="/*[imtypedirectorinattributeint]*/", >> directoroutattributes="/*[imtypedirectoroutattributeint]*/", >> out="/*custom imtype-out*/ int") int "/*custom imtype*/ int" >> >> Can you try it out and let me know if it works and even better, provide >> me your typemaps with a testcase for future regression testing? >> >> William >> >> >> Philip Flesher wrote: >>> Thanks for writing, William. >>> >>> The problem is that the director delegates aren't tagged with the >>> attributes. For example: >>> >>> public virtual void BarClass([MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string >>> arg1) { >>> //... >>> } >>> >>> private void SwigDirectorFooCallback(string arg1) { >>> FooCallback(arg1); >>> } >>> >>> public delegate void SwigDelegateModuleName_0(string arg1); >>> >>> >>> That code is generated by SWIG for a sample function, even though in my >>> interface file, I've done this: >>> >>> %typemap(cstype, >>> inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", >>> outattributes="[return: >>> MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const >>> std::string & "string" >>> >>> %typemap(imtype, >>> inattributes="[MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]", >>> outattributes="[return: >>> MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]") const >>> std::string & "string" >>> >>> %feature("director") BarClass; >>> >>> >>> >>> As you can see, the delegate signature does not have the attributes on >>> it that I need. Only the virtual function (which is not the function >>> that is directly called by the C++ code) has the attributes. What this >>> means is that the C++ code calls the delegate without any explicit >>> marshalling, which causes default marshalling to be used. This wreaks >>> havoc on my UTF-8 encoded strings. >>> >>> I believe I need the delegate signature to look like this: >>> >>> private void >>> SwigDirectorFooCallback([MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string >>> arg1) { >>> FooCallback(arg1); >>> } >>> >>> public delegate void >>> SwigDelegateModuleName_0([MarshalAs(UnmanagedType.CustomMarshaler, >>> MarshalTypeRef=typeof(ManagedChatApiWrapper.MarshalPtrToUtf8))]string >>> arg1); >>> >>> >>> >>> Thanks for your help! >>> >>> - Philip >>> >>> -----Original Message----- >>> From: William Fulton [mailto:william@...] On Behalf Of >>> William S Fulton >>> Sent: Tuesday, January 15, 2008 5:07 PM >>> To: Philip Flesher >>> Cc: swig-user@... >>> Subject: Re: [Swig-user] Directors with C# attributes? >>> >>> Philip Flesher wrote: >>>> When C++ code calls back into C# to make a virtual method call (using >>>> the directors feature), I'm having a difficult time figuring out how >>> to >>>> enforce a MarshalAs attribute on the director functions. I know how >>> to >>>> use imtype's and cstype's inattribute/outattribute to put C# >>> attributes >>>> on the intermediate (PINVOKE) and wrapper classes, but I don't see >>>> anywhere in the documentation that it discusses putting C# attributes >>> on >>>> director functions. This seems critical in order to have full >>>> functionality, so I must be missing something. >>> The director methods use the types in the cstype and imtype typemaps. >>> They also use the inattributes and outattributes specified in the cstype >>> >>> and imtype typemaps. The documentation mentions the cstype and imtype >>> inattribute and outattribute typemap attributes. I just checked that the >>> >>> inattribute and outattribute code gets generated in the correct places >>> for directors. It all looks okay, but didn't go as far as running any >>> code. If you have any problems can you elaborate? >>> >>> William >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Microsoft >>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> _______________________________________________ >>> Swig-user mailing list >>> Swig-user@... >>> https://lists.sourceforge.net/lists/listinfo/swig-user >>> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Swig-user mailing list >> Swig-user@... >> https://lists.sourceforge.net/lists/listinfo/swig-user >> >> > ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
| Free embeddable forum powered by Nabble | Forum Help |