Jump to content

  • Log In with Google      Sign In   
  • Create Account


Need help with SWIG and void pointers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 StakFallT   Members   -  Reputation: 303

Like
0Likes
Like

Posted 31 December 2013 - 10:44 PM

Hopefully someone's got an answer. In a nutshell, I need SWIG to generate the ability for IntPtr <-> void *, and IntPtr<-> HWND.

 

I'm finding either SWIG's directive handling is abysmal or something is very wrong in my interface file. Don't get me wrong I'm extremely grateful for SWIG in general, it's saved my *** by generating a very thorough API for my engine, but it dropped the ball on me when it doesn't handle void pointers or HWND types properly; and if it drops the ball on me there, then it doesn't matter how good it is -- results are what matter, and I need void pointers and HWNDs, if I don't have that then it's no good to me since so much of game programming is around dealing with handles of various sorts. I'm trying to bridge between my engine's DLL and C#. Much of DX and even OpenGL (hRCs, etc) utilize void pointers and HWNDs (which are macroized as void pointers in windef.h I think). Now I'm starting to think it's SWIGs directive handling that is the problem because I've tried 4 different solutions I've found and not one of them provides me the automatic marshaling needed for C# to pass an IntPtr or a void ptr to a SWIGTYPE_p_void or SWIGTYPE_p_HWND without an error in C#.

 

Here's 4 links that I've tried:

http://swig.10945.n7.nabble.com/SWIG-C-void-issue-td5685.html

http://permalink.gmane.org/gmane.comp.programming.swig/13253

http://swig.10945.n7.nabble.com/Mapping-C-void-to-C-td218.html

http://swig.10945.n7.nabble.com/Getting-rid-of-SWIGTYPE-p-void-and-stuff-td4114.html

http://www.nickdarnell.com/2011/05/swig-and-a-miss/  -- point #9

 

with any of them, I get the error: "Error: Cannot implicitly convert type 'System.IntPtr' to 'SWIGTYPE_p_HWND'"

 

I know why it's saying that. It's because there's no SWIG generated (Or any generated for that matter) code to handle going from an IntPtr to an HWND datatype so it's trying to convert it without code (probably through some compiler generated automatic code) and it's unable to do that -- so it fails.

 

An honest look as to why I'm trying to avoid extensive learning on typemaps and C# marshaling

I suppose the answer would be for me to learn how to make my own typemaps. The way I see it, for what I'm trying to do, typemaps are a feature of SWIG that will probably not be revisited again once I have the few datatypes, I need for bridging across, set up. I am very familiar with what the argument probably will be... "You don't know what you're going to need in the future". Maybe not, but I know 90% (at the very least) of what I'm doing is being done in the C++ dll, 5% is making calls to the APIs that are exported out from that DLL and the remaining 5% is probably manipulations of the UI of the editor and just basic declarations so that I can pass objects over to the C++ dll. SWIG handles most of the other datatypes perfectly ok. And not for nothing, I have tried to look at it and understand it but got nowhere since there seems to be many different ways of achieving it (as evidenced by the 4 urls I posted), some through %cs_structs, some through %typemaps and some with indepth-marshaling (Involving %typemaps and %defines, and all sorts of nasty looking stuff).

 

To be brutally honest, I have no interest in learning marshaling. I only need this now because SWIG, with as good as it is, can't really handle void *, and HWND properly out of the box it seems. C++ is my choice of language, not C# and I can't afford to get bogged down in the minutiae of the "wonderful exciting world of marshaling" (or %typemaps for that matter).

 

Quick reason as to why I'm making the editor in C#

For those of you that followed my other post: http://www.gamedev.net/topic/650937-mfc-splitter-windows-and-cviews-oh-my -- You may find my detailing this ordeal/experience helpful if you're dealing with the same questions

I hate much of the things C# takes away (And yes I'm familiar with the "unsafe {};" constructs tongue.png -- but scoping issues occur rather easily imho). From what I've read, CLI is fine if you want to rewrite your code to be CLI compliant and are ok with it being Windows platform only. Only reason I'm writing my editor in C# is because I can throw together a UI pretty quickly and get it looking the way I want fairly quickly. And I've spent enough time with MFC to realize it works pretty good so long as you stick to it's automatic back-end macro-voodoo it does for window/view creation which is, again, pretty limiting. I guess C#'s purpose is not for language-simplification (As I always believed and managed objects was really more of a bonus), it's completely about managed objects and everything else is either an effect (Simpler language syntax imho), or a bonus (visual design of UI). The visual designing of forms was/is really a tacked on super-nice bonus. If they only did the visual-design feature but for C++.. Oh wait, Borland I think did that with VCL and their .NET implementation... hmm...

 

I guess an attachment of my .i file is needed? There's nothing in it really except the inclusion of the headers for my engine, and anyone of your choices for the solutions found at the URLs above, but I can certainly post it if it's really needed. Thanks in advance!

 

-- StakFallT


Edited by StakFallT, 31 December 2013 - 10:49 PM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS