Translating char variable type from C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dann

    #1

    Translating char variable type from C++

    I'm trying (in VB2005) to interact with a third-party DLL written (I
    think) in C++.

    One of the functions requires me to pass a structure consisting
    solely of char types according to the DLL documentation, but AIUI in
    C++ this will be single byte values not unicode as in .Net. Each
    variable element of the srtucture will assume a simple integer value
    of 0, 1, 2 or 3 - in other words digits only and no other characters.

    I'm thinking that in VB2005 I should make the structure of byte type
    elements. Anyone care to confirm/correct me please?
  • diAb0Lo

    #2
    Re: Translating char variable type from C++

    On 21 mayo, 13:19, John Dann <n...@prodata.c o.ukwrote:
    I'm trying (in VB2005) to interact with a third-party DLL written (I
    think) in C++.
    >
    One of the functions requires me to pass a structure consisting
    solely of char types according to the DLL documentation, but AIUI in
    C++ this will be single byte values not unicode as in .Net. Each
    variable element of the srtucture will assume a simple integer value
    of 0, 1, 2 or 3 - in other words digits only and no other characters.
    >
    I'm thinking that in VB2005 I should make the structure of byte type
    elements. Anyone care to confirm/correct me please?
    Hi there,

    Arrays and structures in c++ are always By Reference Parameters (I
    Think). However, I dont understand very well what you are trying to do.

    Comment

    • John Dann

      #3
      Re: Translating char variable type from C++

      On 21 May 2007 15:22:15 -0700, diAb0Lo <garis.sosa@gma il.comwrote:
      >Arrays and structures in c++ are always By Reference Parameters (I
      >Think). However, I dont understand very well what you are trying to do.
      OK, let me try and explain in a little more detail:

      I'm trying (in VB2005) to interact with a third-party DLL written (I
      think) in C++, but almost certainly not in a .Net version of the
      language. Therefore I'm having to use COM Interop Services. I can call
      several of the functions in the DLL successfully so I know that my
      approach is working OK in general.

      However there's one particular DLL function that is refusing to work
      correctly. This is a function that requires a structure passed to it.
      The structure definition (from the C/C++ documentation) is:

      struct MyStructure
      {
      char parA;
      char parB;
      char parC;
      }

      where parA, B, C etc seem to take simple integer values like 0, 1, 2,
      3 (even though they're typed as char).

      I'm trying to simulate this structure in VB2005 as in:

      Public Structure MyDotNetStructu re
      Dim parA as Byte
      Dim parB as Byte
      Dim parC as Byte
      End Structure

      and then setting the values for the structure elements like:

      MyDotNetStructu re.parA=Asc("0" )

      (Using the Asc() function to simulate the value that the C++ char
      might have, was my thinking.)

      then calling the DLL function by

      Dim Response as short = DLLName.MyFunct ion(ByRef MyDotNetStructu re)

      (MyFunction is declared as a shared function in a class in my project
      called DLLName that imports the InterOpServices .)

      But I keep getting an 'invalid data' response from the function. I
      presume that I haven't got the values or type of the structure right
      but I'm not sure what to try next - there are quite a few permutations
      of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
      bit more familiar with how to code this sort of communication.

      Anyone please?

      Comment

      • Andrew Morton

        #4
        Re: Translating char variable type from C++

        John Dann wrote:
        where parA, B, C etc seem to take simple integer values like 0, 1, 2,
        3 (even though they're typed as char).
        MyDotNetStructu re.parA=Asc("0" )
        But I keep getting an 'invalid data' response from the function.
        Asc("0") is 48 - is that a valid number to send it?

        If you want to set it to a number, set it to a number:
        MyDotNetStructu re.parA = 0

        HTH

        Andrew


        Comment

        • John Dann

          #5
          Re: Translating char variable type from C++

          On Tue, 22 May 2007 09:05:40 +0100, "Andrew Morton"
          <akm@in-press.co.uk.inv alidwrote:
          >Asc("0") is 48 - is that a valid number to send it?
          Yes I think that's the problem - thanks. This was actually how I had
          it originally, but it wasn't working so I started to wonder whether
          char wasn't more like a string type and hence added the Asc()
          conversion. Possibly what stopped it working originally was that the
          structure was being passed ByVal and not ByRef (as per diAb0Lo's
          suggestion). But when I changed to ByRef I didn't then remove the
          Asc() conversion again.

          Comment

          • diAb0Lo

            #6
            Re: Translating char variable type from C++

            On 22 mayo, 03:42, John Dann <n...@prodata.c o.ukwrote:
            On 21 May 2007 15:22:15 -0700, diAb0Lo <garis.s...@gma il.comwrote:
            >
            Arrays and structures in c++ are always By Reference Parameters (I
            Think). However, I dont understand very well what you are trying to do.
            >
            OK, let me try and explain in a little more detail:
            >
            I'm trying (in VB2005) to interact with a third-party DLL written (I
            think) in C++, but almost certainly not in a .Net version of the
            language. Therefore I'm having to use COM Interop Services. I can call
            several of the functions in the DLL successfully so I know that my
            approach is working OK in general.
            >
            However there's one particular DLL function that is refusing to work
            correctly. This is a function that requires a structure passed to it.
            The structure definition (from the C/C++ documentation) is:
            >
            struct MyStructure
            {
            char parA;
            char parB;
            char parC;
            >
            }
            >
            where parA, B, C etc seem to take simple integer values like 0, 1, 2,
            3 (even though they're typed as char).
            >
            I'm trying to simulate this structure in VB2005 as in:
            >
            Public Structure MyDotNetStructu re
            Dim parA as Byte
            Dim parB as Byte
            Dim parC as Byte
            End Structure
            >
            and then setting the values for the structure elements like:
            >
            MyDotNetStructu re.parA=Asc("0" )
            >
            (Using the Asc() function to simulate the value that the C++ char
            might have, was my thinking.)
            >
            then calling the DLL function by
            >
            Dim Response as short = DLLName.MyFunct ion(ByRef MyDotNetStructu re)
            >
            (MyFunction is declared as a shared function in a class in my project
            called DLLName that imports the InterOpServices .)
            >
            But I keep getting an 'invalid data' response from the function. I
            presume that I haven't got the values or type of the structure right
            but I'm not sure what to try next - there are quite a few permutations
            of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
            bit more familiar with how to code this sort of communication.
            >
            Anyone please?
            Yet, I dont understand what your problem is. See, I did this and
            worked ok:

            Public Structure MyDotNetStructu re
            Dim parA As Byte
            Dim parB As Byte
            Dim parC As Byte
            End Structure

            Dim mySt as new MyDotNetStructu re
            mySt.parA = Asc("0")

            At least parA is set to 48.

            Comment

            • diAb0Lo

              #7
              Re: Translating char variable type from C++

              On 22 mayo, 03:42, John Dann <n...@prodata.c o.ukwrote:
              On 21 May 2007 15:22:15 -0700, diAb0Lo <garis.s...@gma il.comwrote:
              >
              Arrays and structures in c++ are always By Reference Parameters (I
              Think). However, I dont understand very well what you are trying to do.
              >
              OK, let me try and explain in a little more detail:
              >
              I'm trying (in VB2005) to interact with a third-party DLL written (I
              think) in C++, but almost certainly not in a .Net version of the
              language. Therefore I'm having to use COM Interop Services. I can call
              several of the functions in the DLL successfully so I know that my
              approach is working OK in general.
              >
              However there's one particular DLL function that is refusing to work
              correctly. This is a function that requires a structure passed to it.
              The structure definition (from the C/C++ documentation) is:
              >
              struct MyStructure
              {
              char parA;
              char parB;
              char parC;
              >
              }
              >
              where parA, B, C etc seem to take simple integer values like 0, 1, 2,
              3 (even though they're typed as char).
              >
              I'm trying to simulate this structure in VB2005 as in:
              >
              Public Structure MyDotNetStructu re
              Dim parA as Byte
              Dim parB as Byte
              Dim parC as Byte
              End Structure
              >
              and then setting the values for the structure elements like:
              >
              MyDotNetStructu re.parA=Asc("0" )
              >
              (Using the Asc() function to simulate the value that the C++ char
              might have, was my thinking.)
              >
              then calling the DLL function by
              >
              Dim Response as short = DLLName.MyFunct ion(ByRef MyDotNetStructu re)
              >
              (MyFunction is declared as a shared function in a class in my project
              called DLLName that imports the InterOpServices .)
              >
              But I keep getting an 'invalid data' response from the function. I
              presume that I haven't got the values or type of the structure right
              but I'm not sure what to try next - there are quite a few permutations
              of ByRef/ByVal, byte values etc etc. I was hoping someone might be a
              bit more familiar with how to code this sort of communication.
              >
              Anyone please?
              Yet, I dont understand what your problem is. See, I did this and
              worked ok:

              Public Structure MyDotNetStructu re
              Dim parA As Byte
              Dim parB As Byte
              Dim parC As Byte
              End Structure

              Dim mySt as new MyDotNetStructu re
              mySt.parA = Asc("0")

              At least parA is set to 48.

              Comment

              Working...