[openamq-dev] MS C# using Windows dll with exports.

Martin Sustrik sustrik at imatix.com
Fri Mar 28 10:23:49 CET 2008


Bo,
> As requested I have joined the fun to benefit others in my quest as
> this being my first post.  This code is provided AS IS with NO guarantee, use as you see fit.
>   
Thanks for that!
> Would you happen to have released the build scripts/code for the dlls
> with exports as posted on the wiki
> (http://wiki.openamq.org/package:win32-builds).  I would hope to
> obtain this info and then build on windows producing debug files if
> possible.
See the MSVC project attached.

> Below you will find what I have started in c# using
> openamq's dlls with exports functions from within VS 2005 c# (managed
> code calling unmanaged code through pinvoke).  I used the single
> threaded debug version within this code.
>   
I would suggest using multi-threaded version. With single-threaded one 
client application can effectively block the OpenAMQ client (by not 
calling 'wait' often enough) causing problem with heartbeats, delayed 
reading of messages from the socket etc.
> A question relates to my options to view tracing while running if I am
> not able to obtain the dll builds for modifying.  I am compiling an
> exe and simply running it from command line, not from within the IDE.
> I would like to use something such as sysinternals debugview
> (capturing kernel debugoutput) but what tools do you use (freeware i
> hope) to view the trace output?
>   
We are developing primarily on Linux, therefore our experience with 
tracing on Windows is quite limited.
> For those trying to run the code below I DO NOT have the connection
> create or destroy working.  As some may know the secret is in
> translating the variables, both headers and function calls.  The only
> working functions are "icl_system_initialise", "icl_system_terminate",
> "amq_client_connection_auth_plain", "icl_longstr_destroy_".  You will
> see the that "amq_client_connection_auth_plain" is confirmed working
> by using the PtrToStructure call and then the PtrToString call and
> console.writeline-ing the string.  I commented out the connection
> create and destroy as they are not yet working, might be the
> strc_amq_client_connection_t translation....  More time with this
> tomorrow..

I am not aware of peculiarities of porting C code to C#, however, note 
that the "connection" and "session", although they are pointers to C 
structs are in fact handles. Thus, the C# doesn't have to know anything 
about the struct members and handle the pointer as an opaque void* 
(handle). This may make the porting easier IMO.

Martin


More information about the openamq-dev mailing list