User Profile

Collapse

Profile Sidebar

Collapse
MrVS
MrVS
Last Activity: Jan 27 '09, 12:01 PM
Joined: Jan 21 '09
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • MrVS
    replied to Convert byte array to byte pointer
    If I can do it by passing C# class object to C++ CLI, I want to see how complicated it is. Because my programmers want to write as much as they can in C# including the MQCBDs class, then pass the MQCBDs object into C++ CLI for a lower level operation. There are just too many similar MQXXX classes/objects they have created in C#, they dont' want to convert all of them into C++ class.

    Is there any example I can follow to pass C# class...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    The MQCBDs object is defined as a class in CSharp:
    Code:
    [Serializable,StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
        public class MQCBDs
        {
            public const string MQCBD_STRUC_ID = "CBD ";
            public const int MQCBD_VERSION_1 = 1;
            public const int MQCBD_CURRENT_VERSION = 1;
            public const int MQCBDO_NONE = 0x00000000;
    ...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    Hi,

    I just found out the caller of the MQCBX function passed in a serialized object "cbd* from the CSharp program.
    eg. in C#
    Code:
    private byte[] MQCBD_ToByteArray(MQCBDs obj)
            {
                if (obj == null)
                    return null;
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                try
    ...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    Do you know how to copy the "array<System:: Byte>^ cbd" into a
    "System::By te *" ?
    eg.
    Either this:
    Code:
      System::Byte *buffer = (System::Byte *)(array<System::Byte>^)cbd->Clone();
    OR:
    Code:
       array<System::Byte>^ buffer = (array<System::Byte>^)cbd->Clone();
       p_mqcbd = new MQCBD[buffer->Length+1];
    	for (int i = 0; i<buffer->Length;
    ...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    OK, it works, it prints 123456.
    The *funny character* at the end of each index array is non-printable character.
    Not quite understand why they are there after passed into C++.

    Thank you very much for the help again.
    REALLY REALLY appreciate for your help....
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    Thanks for the help. Your fix works.
    When I step into the MQCBX function in C++, and pull the variable name cbd the Watch list, I found there is funny character on each of the array index.
    eg.
    In the C++ Watch list:
    cbd
    -- [0] 1 ' '
    -- [1] 2 'a'
    -- [2] 3 'c'
    etc

    In the C# Watch list,
    the cbd buffer is clearly printed as:
    cbd
    -- [0] 1
    -- [1] 2...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    Hi,

    Perhaps a simple project is more clear about this idea.
    But I still can't get it working.

    Here is my C# program:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Text;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.IO;
    ...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    the COPY method looks like for int type only....
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    Is there a big difference between Unmanaged dll and Unmanaged Interop?
    Since I am not using Unmanaged dll, but the example you shown me still *import* dll the marshal it. Is this example still applicable to my current situation?

    Thanks...
    See more | Go to post

    Leave a comment:


  • MrVS
    replied to Convert byte array to byte pointer
    I can't convert it to string, the "arr" in my code is a serializable object, setup as Class type in C#. I used the following codes to convert this Class type object into serializable byte array:

    Code:
            public byte[] MQGMO_ToByteArray(MQGMOs obj)
            {
                if (obj == null)
                    return null;
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream
    ...
    See more | Go to post

    Leave a comment:


  • MrVS
    started a topic Convert byte array to byte pointer

    Convert byte array to byte pointer

    Hi,

    I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function.
    But in the CSharp prorgram, I only managed to create a byte array (byte[]).

    Can anyone tell me how to convert byte array to byte pointer in CSharp?

    Please show me an simple example about how to do it.

    Thank you for your help
    Edit/Delete...
    See more | Go to post

  • MrVS
    started a topic Passing CSharp class type to CPP (CLR) function
    in C

    Passing CSharp class type to CPP (CLR) function

    Hi,

    I don't know how to pass a CSharp class type object to a CPP function that takes void pointer argument in the function.

    eg.
    in C#:
    MQMDs md = new MQMDs();
    MQGMOs gmo = new MQGMOs();
    MQCBDs cbd = new MQCBDs();

    using (Managed managed = new Managed())
    {
    managed.Execute ();
    int ret = managed.MQCBX(q Mgr.myHconn,
    operation,
    cbd,
    myQueue.hObj,...
    See more | Go to post
No activity results to display
Show More
Working...