Jump to content
Excelsior Forums
Sign in to follow this  
will592

reference to unknown Struct

Recommended Posts

I am very new to this and have what may be a stupid question.  I am trying to call a function from a c library (dll) and having a little trouble figuring something out.  One of the arguments that is passed into the function is a pointer to a internal struct that I know nothing about.  I am not a C programmer (or at least not a very good one...this much should be obvious).  I never need to dereference the pointer in my code, only pass the pointer back into several other functions in the DLL.  Basically it looks something like this ( Where newStruc is the struct that I don't know anything about and therefore don't know how to define in Java but exists in  the DLL)

   Structure newStruc = new GeoHandleStruct();

   

   Pointer pGeoEngHandle = Pointer.createPointerTo(newStruc);

   xFunction geoEngInit=new xFunction("Mm32v8","short GeoEngCheckDbAvailability(CSTRING, CSTRING, CSTRING, short*, newStruc *)");

   geoEngInit.invoke(searchPath, db_name, user_dict, dbInitRequestFlags, pGeoEngHandle);

 

 Next I would want to take the pointer that was returned from the previous method call and pass it into some other method such as:

   xFunction geoEngGetCfgParms=new xFunction("Mm32v8","short GeoEngGetCfgParms(newStruc *, someOtherStruc *)");

   geoEngGetCfgParms.invoke(pGeoEngHandle, someOtherStrucArgument);

and so on and so forth.  Can anyone help?  Sorry if this is a stupid question.

Thanks,

Chris

Share this post


Link to post
Share on other sites

As far as I can understand, what you need is not a structure, but just a buffer that is big enough to store the unknown structure instance.  If you know that the structure size is SIZE (or, at least, that the size of the structure is no more than SIZE), you could create the handle as, for example,

Argument pGeoEngHandle = new Argument("", Argument.CSTRING, SIZE);

Of course, "newStruc*" should be replaced with the "CSTRING" in function signatures.

Share this post


Link to post
Share on other sites

Perhaps I misunderstood your response...but I tried to do this and it still isn't working.  When I pass in the CSTRING argument the function returns successfully, but anytime I try to pass that argument back as the pointer to the structure I get an invalid parameter value message (from my dll).  After I invoke the function, should the Argument that I passed in contain the pointer or do I have to manipulate it somehow to create a pointer to the object?  Thanks in advance,

Chris

Share this post


Link to post
Share on other sites

No manipulating is needed. Have you provide the buffer of enough size? Try to increase it, for example, to 10000 bytes. If it won't help, pelase send your program and dll to our Support Dept.

Share this post


Link to post
Share on other sites

Still wasn't able to get it to work.  The function returns a value that indicates it does not like the arguments being passed in.  Should the CSTRING that I am passing be a container for the struct itself or just a pointer to it?  The function only needs to be passed a pointer... it would seem that I should be able to just create a generic Pointer object and pass it around regardless of what it is pointing too...I never need to deref it inside my code.  I have sent the DLL and some of my code to your Support Dept., I hope that it will be enough for someone to point out my (hopefully) silly mistake.

Thanks,

Chris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×