Pointer to String in VB2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?bW9iaWxlbW9iaWxl?=

    #1

    Pointer to String in VB2005

    I'm trying to load this structure for a call to DeviceIoControl :

    typedef struct _NDISUIO_QUERY_ OID {
    NDIS_OID Oid;
    PTCHAR ptcDeviceName;
    UCHAR Data[sizeof(ULONG)];
    } NDISUIO_QUERY_O ID, *PNDISUIO_QUERY _OID;

    I created the equivalent in VB:

    <StructLayout(L ayoutKind.Seque ntial)_
    Public Class NDISUIO_QUERY_O ID ' nuiouser.h
    Public Oid As Int32
    Public ptcDeviceName As IntPtr
    <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=4)_
    Public Data As String
    End Class

    What I need to proceed is: How do I get the pointer to my DeviceName string
    to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
    &DeviceName -- I don't know how to do this in VB.

    Thanks for any help,
    Steve
  • Guest's Avatar

    #2
    Re: Pointer to String in VB2005

    Strings are already reference types so send it as a string.

    Also, don't crosspost to so many groups.

    And lastly, a Google search would probably have led you to a working
    implementation - you're far from teh first to be using NDIS from amanaged
    code. The OpenNETCF SDF has all of this stuff fully done and tested for
    example.


    --
    Chris Tacke - Embedded MVP
    OpenNETCF Consulting
    Managed Code in the Embedded World

    --



    "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comwrote in message
    news:AFD4E53D-C99D-49D4-84BC-F277C9537059@mi crosoft.com...
    I'm trying to load this structure for a call to DeviceIoControl :
    >
    typedef struct _NDISUIO_QUERY_ OID {
    NDIS_OID Oid;
    PTCHAR ptcDeviceName;
    UCHAR Data[sizeof(ULONG)];
    } NDISUIO_QUERY_O ID, *PNDISUIO_QUERY _OID;
    >
    I created the equivalent in VB:
    >
    <StructLayout(L ayoutKind.Seque ntial)_
    Public Class NDISUIO_QUERY_O ID ' nuiouser.h
    Public Oid As Int32
    Public ptcDeviceName As IntPtr
    <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=4)_
    Public Data As String
    End Class
    >
    What I need to proceed is: How do I get the pointer to my DeviceName
    string
    to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
    &DeviceName -- I don't know how to do this in VB.
    >
    Thanks for any help,
    Steve

    Comment

    • =?Utf-8?B?bW9iaWxlbW9iaWxl?=

      #3
      Re: Pointer to String in VB2005


      "<ctacke/>" wrote:
      Strings are already reference types so send it as a string.
      I don't understand this -- are you saying my VB structure/class shouldn't
      define ptcDeviceName as an IntPtr? If the structure's correct, how do I load
      ptcDeviceName; i.e., get a String into a IntPtr?
      >
      Also, don't crosspost to so many groups.
      Not sure what the issue is here. I posted to the NETCF/PPC groups because
      I'm working on that platform, and posted to 3 other general VB groups because
      they're specific to VB, and it seems a lot of the NETCF/PPC people use C# or
      C++.
      >
      And lastly, a Google search would probably have led you to a working
      implementation - you're far from teh first to be using NDIS from amanaged
      code. The OpenNETCF SDF has all of this stuff fully done and tested for
      example.
      I could find NOTHING in VB -- I did a TON of Google searches before I posted
      this message. Everything I've found is in C# or C++.

      The specific question is: How do I get a pointer to a string in VB. Or am I
      setting up the structure incorrectly?

      I've used the OpenNETCF 1.4 source to get some ideas -- even though wading
      through such a large code base (and it's C# not VB, so it doesn't answer my
      specific question) takes a huge chunk of time, as it would with any large
      system like it.
      >
      >
      --
      Chris Tacke - Embedded MVP
      OpenNETCF Consulting
      Managed Code in the Embedded World

      --
      >
      >
      >
      "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comwrote in message
      news:AFD4E53D-C99D-49D4-84BC-F277C9537059@mi crosoft.com...
      I'm trying to load this structure for a call to DeviceIoControl :

      typedef struct _NDISUIO_QUERY_ OID {
      NDIS_OID Oid;
      PTCHAR ptcDeviceName;
      UCHAR Data[sizeof(ULONG)];
      } NDISUIO_QUERY_O ID, *PNDISUIO_QUERY _OID;

      I created the equivalent in VB:

      <StructLayout(L ayoutKind.Seque ntial)_
      Public Class NDISUIO_QUERY_O ID ' nuiouser.h
      Public Oid As Int32
      Public ptcDeviceName As IntPtr
      <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=4)_
      Public Data As String
      End Class

      What I need to proceed is: How do I get the pointer to my DeviceName
      string
      to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
      &DeviceName -- I don't know how to do this in VB.

      Thanks for any help,
      Steve
      >
      >
      >

      Comment

      • Ken Halter

        #4
        Re: Pointer to String in VB2005

        "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comwrote in message
        news:049BBF3E-5104-45C9-B1F0-56014A3522B5@mi crosoft.com...
        >
        "<ctacke/>" wrote:
        >
        >Strings are already reference types so send it as a string.
        All groups on the MS server that start with 'microsoft.publ ic.vb' are there
        to support VB Classic (v1 thru 6), so, this question is basically white
        noise in non-dotnet groups.

        --
        Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
        In Loving Memory - http://www.vbsight.com/Remembrance.htm


        Comment

        • Armin Zingler

          #5
          Re: Pointer to String in VB2005

          "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comschrie b
          The specific question is: How do I get a pointer to a string in VB.
          Or am I setting up the structure incorrectly?
          Strings are reference type, thus a String within a structure is a pointer:

          Public ptcDeviceName As String

          Maybe you need an additional MarshalAs attribute.


          Armin

          Comment

          • Karl E. Peterson

            #6
            Re: Pointer to String in VB2005

            mobilemobile <mobilemobile@d iscussions.micr osoft.comwrote:
            I created the equivalent in VB:
            No, you created it in VB.NET, according to your Subject and source.

            Keep this *crap* out of the ClassicVB groups!

            It has no place here.

            Please.
            --
            ..NET: It's About Trust!



            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Pointer to String in VB2005

              "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comschrie b:
              I'm trying to load this structure for a call to DeviceIoControl :
              >
              typedef struct _NDISUIO_QUERY_ OID {
              NDIS_OID Oid;
              PTCHAR ptcDeviceName;
              UCHAR Data[sizeof(ULONG)];
              } NDISUIO_QUERY_O ID, *PNDISUIO_QUERY _OID;
              >
              I created the equivalent in VB:
              >
              <StructLayout(L ayoutKind.Seque ntial)_
              Public Class NDISUIO_QUERY_O ID ' nuiouser.h
              Public Oid As Int32
              Public ptcDeviceName As IntPtr
              <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=4)_
              Public Data As String
              End Class
              >
              What I need to proceed is: How do I get the pointer to my DeviceName
              string
              to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
              &DeviceName -- I don't know how to do this in VB.
              Declare the member simply 'As String'. In addition, set the structure's
              character set ('CharSet' in 'StructLayout') to 'Auto').

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              • =?Utf-8?B?bW9iaWxlbW9iaWxl?=

                #8
                Re: Pointer to String in VB2005

                Thanks for the heads up, Ken, didn't realize that. My apologies.

                "Ken Halter" wrote:
                "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comwrote in message
                news:049BBF3E-5104-45C9-B1F0-56014A3522B5@mi crosoft.com...

                "<ctacke/>" wrote:
                Strings are already reference types so send it as a string.
                >
                All groups on the MS server that start with 'microsoft.publ ic.vb' are there
                to support VB Classic (v1 thru 6), so, this question is basically white
                noise in non-dotnet groups.
                >
                --
                Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
                In Loving Memory - http://www.vbsight.com/Remembrance.htm
                >
                >
                >

                Comment

                • =?Utf-8?B?bW9iaWxlbW9iaWxl?=

                  #9
                  Re: Pointer to String in VB2005

                  Another poster in the classic VB groups gave me the info that all groups
                  starting with 'microsoft.publ ic.vb' were classic VB only groups, which I
                  didn't know. I apologized to him. I will not, however, extend that courtesy
                  to you, given your overly emotional response.

                  I've programmed since the early 70s, Fortran IV, Dartmouth Basic, Algol,
                  Pascal, COBOL, C, right through creating large systems in VB5/6 (some of
                  which are still used) and now .NET.

                  If you choose to continue to use VB6, an environment which I loved working
                  in, and still have a large code base of, then that's a choice that works for
                  you. But calling the work of others "crap" is not a professional or reasoned
                  position. Every language has it's good sides and bad sides.

                  "Karl E. Peterson" wrote:
                  mobilemobile <mobilemobile@d iscussions.micr osoft.comwrote:
                  I created the equivalent in VB:
                  >
                  No, you created it in VB.NET, according to your Subject and source.
                  >
                  Keep this *crap* out of the ClassicVB groups!
                  >
                  It has no place here.
                  >
                  Please.
                  --
                  ..NET: It's About Trust!

                  >
                  >
                  >

                  Comment

                  • RobinS

                    #10
                    Re: Pointer to String in VB2005

                    I removed all of the groups from this posting except this one.

                    mobilemobile, many of the VB6 programmers seem to be bitter. Every time
                    ..Net comes up in one of those newsgroups, there are a handful of people who
                    diss it, even though they have never tried it.

                    I'm impressed that you're choosing to learn something new.

                    Have a great day.
                    Robin S.
                    ---------------------------------------------------------
                    "mobilemobi le" <mobilemobile@d iscussions.micr osoft.comwrote in message
                    news:DF5CE264-5AA1-4136-AB04-75DACE9289AF@mi crosoft.com...
                    Another poster in the classic VB groups gave me the info that all groups
                    starting with 'microsoft.publ ic.vb' were classic VB only groups, which I
                    didn't know. I apologized to him. I will not, however, extend that
                    courtesy
                    to you, given your overly emotional response.
                    >
                    I've programmed since the early 70s, Fortran IV, Dartmouth Basic, Algol,
                    Pascal, COBOL, C, right through creating large systems in VB5/6 (some of
                    which are still used) and now .NET.
                    >
                    If you choose to continue to use VB6, an environment which I loved
                    working
                    in, and still have a large code base of, then that's a choice that works
                    for
                    you. But calling the work of others "crap" is not a professional or
                    reasoned
                    position. Every language has it's good sides and bad sides.
                    >
                    "Karl E. Peterson" wrote:
                    >
                    >mobilemobile <mobilemobile@d iscussions.micr osoft.comwrote:
                    I created the equivalent in VB:
                    >>
                    >No, you created it in VB.NET, according to your Subject and source.
                    >>
                    >Keep this *crap* out of the ClassicVB groups!
                    >>
                    >It has no place here.
                    >>
                    >Please.
                    >--
                    >..NET: It's About Trust!
                    > http://vfred.mvps.org
                    >>
                    >>
                    >>

                    Comment

                    • J French

                      #11
                      Re: Pointer to String in VB2005

                      On Fri, 9 Feb 2007 19:04:00 -0800, =?Utf-8?B?bW9iaWxlbW9 iaWxl?=
                      <mobilemobile@d iscussions.micr osoft.comwrote:
                      But calling the work of others "crap" is not a professional or reasoned
                      >position. Every language has it's good sides and bad sides.
                      The problem is that if we get dotnet questions here then people get
                      confused
                      - it is like posting a C++ question here


                      Comment

                      • =?Utf-8?B?bW9iaWxlbW9iaWxl?=

                        #12
                        Re: Pointer to String in VB2005

                        You're absolutely right, J, my mistake, sorry about that.

                        I'm not sure if these discussions groups are moderated in any way, but I
                        imagine that people mistakenly posting to incorrect groups is not an uncommon
                        occurrence. After all, posting my question to a Classic VB forum doesn't
                        help me to solve my current problem.

                        Steve

                        "J French" wrote:
                        On Fri, 9 Feb 2007 19:04:00 -0800, =?Utf-8?B?bW9iaWxlbW9 iaWxl?=
                        <mobilemobile@d iscussions.micr osoft.comwrote:
                        >
                        But calling the work of others "crap" is not a professional or reasoned
                        position. Every language has it's good sides and bad sides.
                        >
                        The problem is that if we get dotnet questions here then people get
                        confused
                        - it is like posting a C++ question here
                        >
                        >
                        >

                        Comment

                        • J French

                          #13
                          Re: Pointer to String in VB2005

                          On Sat, 10 Feb 2007 08:11:01 -0800, =?Utf-8?B?bW9iaWxlbW9 iaWxl?=
                          <mobilemobile@d iscussions.micr osoft.comwrote:
                          >You're absolutely right, J, my mistake, sorry about that.
                          >
                          >I'm not sure if these discussions groups are moderated in any way, but I
                          >imagine that people mistakenly posting to incorrect groups is not an uncommon
                          >occurrence. After all, posting my question to a Classic VB forum doesn't
                          >help me to solve my current problem.
                          It looks as if there is a bit of automatic moderation for foul
                          language, but we can get round that.

                          Mostly we are a bunch of old timers who try to pass our acquired
                          mistakes onto others
                          - not easy when 'others' are using another language

                          It gets quite funny when a VB'er produces a comprehensive reply for a
                          ..net'er and neither understands why it does not work.

                          We are a bit cliquey - that happens over time - over time you get to
                          like or loathe people.
                          - and we do need to keep the old ( and un-renameable ) NGs clear of
                          obfuscation.


                          Comment

                          • Mike Coon

                            #14
                            Re: Pointer to String in VB2005

                            J French wrote:
                            The problem is that if we get dotnet questions here then people get
                            confused
                            - it is like posting a C++ question here
                            Where, in that major list of cross-posted groups is "here"? (Rhetorical
                            question only!)

                            Mike.
                            --



                            Comment

                            • Neila

                              #15
                              Re: Pointer to String in VB2005

                              We are a bit cliquey - that happens over time - over time you get to
                              like or loathe people.
                              LOL, I like to loathe all you wonderful people!!!
                              OTOH, I Loathe to like you all.....
                              Anybody wanting to do the P2S in VB Classic just ask!
                              Hell, I'll even take it to the next level!!!!!
                              Leave it to you Clicky old farts to dig up the API Declarations ;-)
                              HTH, Neila

                              -------
                              Public Sub GetStringArrayF romPointer(pStr ingArray As Long, _
                              strArray() As Variant, _
                              lngLabelCount As Long)
                              'Returns an Array of strings from a Pointer
                              Dim lngValue As Long
                              Dim lngLabPtrs() As Long
                              Dim strValue As String

                              ReDim lngLabPtrs(lngL abelCount - 1)
                              ReDim strArray(lngLab elCount - 1)
                              If lngLabelCount 0 Then
                              'We have a pointer to an array of Pointers
                              'Blast them into the right slots
                              Call CopyMemory(lngL abPtrs(0), ByVal pStringArray, 4 *
                              lngLabelCount)

                              'Now dereference each of the pointers to get the strings
                              For lngValue = 0 To lngLabelCount - 1
                              strValue = ANSIStringFromP ointer(lngLabPt rs(lngValue))
                              strArray(lngVal ue) = StripNull(strVa lue)
                              Next
                              End If
                              End Sub

                              Public Function ANSIStringFromP ointer(ByVal lngStringPointe r As Long)
                              As String
                              'Returns an ANSI string from a pointer to an ANSI string.
                              Dim strReturn As String
                              strReturn = VBA.String$(lst rlenA(ByVal lngStringPointe r), 0)
                              Call lstrcpyA(ByVal strReturn, ByVal lngStringPointe r)
                              ANSIStringFromP ointer = strReturn
                              End Function



                              On Feb 10, 8:46 am, erew...@nowhere .uk (J French) wrote:
                              On Sat, 10 Feb 2007 08:11:01 -0800, =?Utf-8?B?bW9iaWxlbW9 iaWxl?=
                              >
                              <mobilemob...@d iscussions.micr osoft.comwrote:
                              You're absolutely right, J, my mistake, sorry about that.
                              >
                              I'm not sure if these discussions groups are moderated in any way, but I
                              imagine that people mistakenly posting to incorrect groups is not an uncommon
                              occurrence. After all, posting my question to a Classic VB forum doesn't
                              help me to solve my current problem.
                              >
                              It looks as if there is a bit of automatic moderation for foul
                              language, but we can get round that.
                              >
                              Mostly we are a bunch of old timers who try to pass our acquired
                              mistakes onto others
                              - not easy when 'others' are using another language
                              >
                              It gets quite funny when a VB'er produces a comprehensive reply for a
                              .net'er and neither understands why it does not work.
                              >
                              We are a bit cliquey - that happens over time - over time you get to
                              like or loathe people.
                              - and we do need to keep the old ( and un-renameable ) NGs clear of
                              obfuscation.

                              Comment

                              Working...