Topic
  • 8 replies
  • Latest Post - ‏2006-12-26T13:59:35Z by neekrish
SystemAdmin
SystemAdmin
684 Posts

Pinned topic MQe & C#

‏2006-12-11T11:37:54Z |
How to build C# wrapper for access MQ everyplace.

Does anyone have sample code/ help to do this?
Updated on 2006-12-26T13:59:35Z at 2006-12-26T13:59:35Z by neekrish
  • neekrish
    neekrish
    13 Posts

    Re: MQe & C#

    ‏2006-12-11T13:04:16Z  
    Hi Sonali,

    As MQe doesn't provide example code for C#, one has to use Platform Invocation Services provided by dotNET to develop wrappers on this to use in C# application.
    For the *.h(header) files present in the "include" directory, you can develop the C# wrapper for all the MQe functions that are used in the C# application.

    For example, to use the MQe function "mqeSession_initialize(...)" in C#, write the wrapper like
    public static extern MQERETURN mqeSession_initialize(http://MarshalAs(UnmanagedType.Struct)MQeExceptBlock m);
    You should be careful in Marshalling the arguments passed to MQe. You will have to use the appropriate data type in C# for all the MQe data types.(Ex for a 64 bit integer, pass a 64bit C# datatype only)

    You can also use tools that can generate wrappers for c code base in C#. For example "SWIG"( http://www.swig.org/) .

    I hope this helps you move forward in developing the C# wrapper for MQe

    Regards,
    Neeraj Krishna
  • SystemAdmin
    SystemAdmin
    684 Posts

    Re: MQe & C#

    ‏2006-12-12T08:40:08Z  
    • neekrish
    • ‏2006-12-11T13:04:16Z
    Hi Sonali,

    As MQe doesn't provide example code for C#, one has to use Platform Invocation Services provided by dotNET to develop wrappers on this to use in C# application.
    For the *.h(header) files present in the "include" directory, you can develop the C# wrapper for all the MQe functions that are used in the C# application.

    For example, to use the MQe function "mqeSession_initialize(...)" in C#, write the wrapper like
    public static extern MQERETURN mqeSession_initialize(http://MarshalAs(UnmanagedType.Struct)MQeExceptBlock m);
    You should be careful in Marshalling the arguments passed to MQe. You will have to use the appropriate data type in C# for all the MQe data types.(Ex for a 64 bit integer, pass a 64bit C# datatype only)

    You can also use tools that can generate wrappers for c code base in C#. For example "SWIG"( http://www.swig.org/) .

    I hope this helps you move forward in developing the C# wrapper for MQe

    Regards,
    Neeraj Krishna
    Hi Neeraj,

    Thanks for the reply. It surely gave me some insight.
    project is starting next monday. will try developing the MQe wrapper as per your gidelines.Before that need to find basic information.

    After reading your reply few basic Qs came to my mind. Can you please answer?

    I have installed MQe 2.0.2.1 trial version on my desktop.

    The "HMQ_nativeAPI.dll" is used as sample in your reply.
    I could find it under ~\MQe\C\PocketPc2003\arm\bin.

    1. Do we need to install/register these dlls on device separately?

    2. There are 14 such dlls named HMQ_*.dll. Are 'these HMQ dlls' to be used in p/invoke?

    3. How to check which *.h files corrospond to which dll.

    4. How to check the interface (method details etc) exposed by these dlls. Is there any documentation available? Couldn't find anything in install folder.

    thanks for info about swig. Will try that.
    Can you please tell me whether one can rely on wrapper genrated by tool.
    Is this swig tool, tried and tested?
  • neekrish
    neekrish
    13 Posts

    Re: MQe & C#

    ‏2006-12-12T13:34:15Z  
    Hi Neeraj,

    Thanks for the reply. It surely gave me some insight.
    project is starting next monday. will try developing the MQe wrapper as per your gidelines.Before that need to find basic information.

    After reading your reply few basic Qs came to my mind. Can you please answer?

    I have installed MQe 2.0.2.1 trial version on my desktop.

    The "HMQ_nativeAPI.dll" is used as sample in your reply.
    I could find it under ~\MQe\C\PocketPc2003\arm\bin.

    1. Do we need to install/register these dlls on device separately?

    2. There are 14 such dlls named HMQ_*.dll. Are 'these HMQ dlls' to be used in p/invoke?

    3. How to check which *.h files corrospond to which dll.

    4. How to check the interface (method details etc) exposed by these dlls. Is there any documentation available? Couldn't find anything in install folder.

    thanks for info about swig. Will try that.
    Can you please tell me whether one can rely on wrapper genrated by tool.
    Is this swig tool, tried and tested?
    Hi Sonali,
    Please find below the replies for your queries.

    1. Do we need to install/register these dlls on device separately?
    MQe DLLs need deployment (not registration) on devices. Follow the instruction given in the MQe Documentation(infocenter) for deployment of MQe C DLLs
    (Welcome to MQe -> Developing a basic application -> Deploying the C Application).

    2. There are 14 such dlls named HMQ_*.dll. Are 'these HMQ dlls' to be used in p/invoke?
    Yes, you are right :)

    3. How to check which *.h files corresponds to which dll.
    There is no direct way of finding this, but the reply to the fourth query may help you.

    4. How to check the interface (method details etc) exposed by these dlls. Is there any documentation available? Couldn't find anything in install folder.
    The basic information about the MQe DLLs are provided in the infocenter "Welcome to MQe -> Deploying your application -> Packaging and Deployment -> C Deployment -> Supplied DLLs".

    You will find most of these functions in HMQ_nativeAPI.dll. Also you can find out the exported functions in any MQe DLL using the third party tools available in the net. You can google for it :) One of them is "Depends" tool provided with VC++ 6.
    You can walk through the Header files to find the function prototypes.

    Examples are available with MQe product in C-codebase. I would suggest you to try some C examples on Pocket PC and get a hands on it.
    SWIG is a third party tool, you need to try(R&D) to make use of it.

    Regards,
    Neeraj Krishna
  • SystemAdmin
    SystemAdmin
    684 Posts

    Re: MQe & C#

    ‏2006-12-26T11:10:27Z  
    • neekrish
    • ‏2006-12-12T13:34:15Z
    Hi Sonali,
    Please find below the replies for your queries.

    1. Do we need to install/register these dlls on device separately?
    MQe DLLs need deployment (not registration) on devices. Follow the instruction given in the MQe Documentation(infocenter) for deployment of MQe C DLLs
    (Welcome to MQe -> Developing a basic application -> Deploying the C Application).

    2. There are 14 such dlls named HMQ_*.dll. Are 'these HMQ dlls' to be used in p/invoke?
    Yes, you are right :)

    3. How to check which *.h files corresponds to which dll.
    There is no direct way of finding this, but the reply to the fourth query may help you.

    4. How to check the interface (method details etc) exposed by these dlls. Is there any documentation available? Couldn't find anything in install folder.
    The basic information about the MQe DLLs are provided in the infocenter "Welcome to MQe -> Deploying your application -> Packaging and Deployment -> C Deployment -> Supplied DLLs".

    You will find most of these functions in HMQ_nativeAPI.dll. Also you can find out the exported functions in any MQe DLL using the third party tools available in the net. You can google for it :) One of them is "Depends" tool provided with VC++ 6.
    You can walk through the Header files to find the function prototypes.

    Examples are available with MQe product in C-codebase. I would suggest you to try some C examples on Pocket PC and get a hands on it.
    SWIG is a third party tool, you need to try(R&D) to make use of it.

    Regards,
    Neeraj Krishna
    Hi,

    Thanks for previous replies.
    I am trying to run C examples given in install folder of MQe.
    The process to do this is not clear to me.

    I was trying Helloworld sample. It didn't work.

    Copied all dlls from ~\MQe\C\PocketPc2003\arm\bin to device root
    and exe provided in folder ~\MQe\C\examples\PocketPc2003\arm\HelloWorld\Admin on the device root. Double-clicking it, gives error.

    1. Are lib files also need to be copied on device? where?

    2. Is there any configuration to be done on the device? eg. Creating & setting up queue. If yes then How to do it?

    3. How to compile this example. I couldn't find makefile at -
    ~\MQe\C\examples\src\HelloWorld\Admin
    (I have eVC 3.0 installed on my pc)

    I have not worked with C or VC++ before.
    Can you please explain the steps to run c examples or give a reference?
    also setup for MQe on the device.
  • neekrish
    neekrish
    13 Posts

    Re: MQe & C#

    ‏2006-12-26T12:45:13Z  
    Hi,

    Thanks for previous replies.
    I am trying to run C examples given in install folder of MQe.
    The process to do this is not clear to me.

    I was trying Helloworld sample. It didn't work.

    Copied all dlls from ~\MQe\C\PocketPc2003\arm\bin to device root
    and exe provided in folder ~\MQe\C\examples\PocketPc2003\arm\HelloWorld\Admin on the device root. Double-clicking it, gives error.

    1. Are lib files also need to be copied on device? where?

    2. Is there any configuration to be done on the device? eg. Creating & setting up queue. If yes then How to do it?

    3. How to compile this example. I couldn't find makefile at -
    ~\MQe\C\examples\src\HelloWorld\Admin
    (I have eVC 3.0 installed on my pc)

    I have not worked with C or VC++ before.
    Can you please explain the steps to run c examples or give a reference?
    also setup for MQe on the device.

    Neeraj Krishna
  • neekrish
    neekrish
    13 Posts

    Re: MQe & C#

    ‏2006-12-26T12:46:07Z  
    Hi,

    Thanks for previous replies.
    I am trying to run C examples given in install folder of MQe.
    The process to do this is not clear to me.

    I was trying Helloworld sample. It didn't work.

    Copied all dlls from ~\MQe\C\PocketPc2003\arm\bin to device root
    and exe provided in folder ~\MQe\C\examples\PocketPc2003\arm\HelloWorld\Admin on the device root. Double-clicking it, gives error.

    1. Are lib files also need to be copied on device? where?

    2. Is there any configuration to be done on the device? eg. Creating & setting up queue. If yes then How to do it?

    3. How to compile this example. I couldn't find makefile at -
    ~\MQe\C\examples\src\HelloWorld\Admin
    (I have eVC 3.0 installed on my pc)

    I have not worked with C or VC++ before.
    Can you please explain the steps to run c examples or give a reference?
    also setup for MQe on the device.
    Hi Sonali,
    There is a helpful article that I recommend you to read: http://www-128.ibm.com/developerworks/websphere/library/techarticles/0607_krishna/0607_krishna.html

    Here are answers for your queries:
    Q:
    Copied all dlls from ~\MQe\C\PocketPc2003\arm\bin to device root
    and exe provided in folder ~\MQe\C\examples\PocketPc2003\arm\HelloWorld\Admin on the device root. Double-clicking it, gives error.
    Ans:
    I think you would have got a similar error like this: "The file 'HelloWorld_Admin' cannot be opened. The executable tried to find the MQe DLLs at runtime. Place the DLLs in the '\Windows' directory. More information regarding this can be found in information center at 'Welcome to MQe -> deploying your application->C deployment -> Supplied DLLs'

    Q:
    1. Are lib files also need to be copied on device? where?
    A: No.... You do not need to copy the lib files. When you compile any C or C++ program you will have to link it with the appropriate library files. Only DLLs are used while running the application.

    Q:
    2. Is there any configuration to be done on the device? e.g. Creating & setting up queue. If yes then How to do it?
    A: There is no configuration required on the device. The Queues and other MQe objects are created programmatically. You can refer to information center at 'Welcome to MQe -> Designing your real Application -> Configuring MQe Objects -> Create a local Queue -> C

    Q:
    3. How to compile this example. I couldn't find makefile at -
    ~\MQe\C\examples\src\HelloWorld\Admin
    (I have eVC 3.0 installed on my pc)
    A:
    There is no makefile provided as compilation in eVC++/VC++ doesnt require a make file. I observe that you are using Pocket PC 2003 for deployment. eVC++ 3.0 is not compatible with PPC 2003. You need to use eVC++ 4.0 with latest service Pack. You can refer to the information center at 'Welcome to MQe -> Developing a basic application -> Setting up your development environment -> C development.

    Information center is available at http://www-306.ibm.com/software/integration/wmqe/library/

    I am afraid that you need to learn the basics of programming using eVC++ and VC++ before proceeding with developing MQe applications in C.
    Regards,
    Neeraj Krishna
  • SystemAdmin
    SystemAdmin
    684 Posts

    Re: MQe & C#

    ‏2006-12-26T12:54:21Z  
    • neekrish
    • ‏2006-12-26T12:46:07Z
    Hi Sonali,
    There is a helpful article that I recommend you to read: http://www-128.ibm.com/developerworks/websphere/library/techarticles/0607_krishna/0607_krishna.html

    Here are answers for your queries:
    Q:
    Copied all dlls from ~\MQe\C\PocketPc2003\arm\bin to device root
    and exe provided in folder ~\MQe\C\examples\PocketPc2003\arm\HelloWorld\Admin on the device root. Double-clicking it, gives error.
    Ans:
    I think you would have got a similar error like this: "The file 'HelloWorld_Admin' cannot be opened. The executable tried to find the MQe DLLs at runtime. Place the DLLs in the '\Windows' directory. More information regarding this can be found in information center at 'Welcome to MQe -> deploying your application->C deployment -> Supplied DLLs'

    Q:
    1. Are lib files also need to be copied on device? where?
    A: No.... You do not need to copy the lib files. When you compile any C or C++ program you will have to link it with the appropriate library files. Only DLLs are used while running the application.

    Q:
    2. Is there any configuration to be done on the device? e.g. Creating & setting up queue. If yes then How to do it?
    A: There is no configuration required on the device. The Queues and other MQe objects are created programmatically. You can refer to information center at 'Welcome to MQe -> Designing your real Application -> Configuring MQe Objects -> Create a local Queue -> C

    Q:
    3. How to compile this example. I couldn't find makefile at -
    ~\MQe\C\examples\src\HelloWorld\Admin
    (I have eVC 3.0 installed on my pc)
    A:
    There is no makefile provided as compilation in eVC++/VC++ doesnt require a make file. I observe that you are using Pocket PC 2003 for deployment. eVC++ 3.0 is not compatible with PPC 2003. You need to use eVC++ 4.0 with latest service Pack. You can refer to the information center at 'Welcome to MQe -> Developing a basic application -> Setting up your development environment -> C development.

    Information center is available at http://www-306.ibm.com/software/integration/wmqe/library/

    I am afraid that you need to learn the basics of programming using eVC++ and VC++ before proceeding with developing MQe applications in C.
    Regards,
    Neeraj Krishna
    Thanks Neeraj.

    I will go through the article and try doing it as per your comments.
    Actually I don't want to develop MQe applications in C.

    What I need is accessing MQe from .Net (C#).
    So I was trying to run the samples given.
    Can you please suggest any other approach instead of running C examples?
  • neekrish
    neekrish
    13 Posts

    Re: MQe & C#

    ‏2006-12-26T13:59:35Z  
    Thanks Neeraj.

    I will go through the article and try doing it as per your comments.
    Actually I don't want to develop MQe applications in C.

    What I need is accessing MQe from .Net (C#).
    So I was trying to run the samples given.
    Can you please suggest any other approach instead of running C examples?
    Hi Sonali,
    You need to have a good understanding of the MQe C code base API before writing the wrappers in C#. The C# application uses platform invocation services provided by .Net to call the C functions present in the MQe C DLLs. You will have to look at the C functions provided by MQe and find out appropriate function parameter data types to use in C#(.net) to call those C functions.

    I think you would be using Visual Studio 2005 for developing C# applications. You can use the same Visual studio for developing C/C++ applications also. So a good start would be to develop C/C++ applications using MQe C DLLs for the Win32 target and then for the pocket PC 2003 target. Then you can start writing C# wrappers on MQe C DLLs that use Platform invocation services.

    Regards,
    Neeraj Krishna